148 lines
4.7 KiB
YAML
148 lines
4.7 KiB
YAML
name: test-and-publish
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
environment:
|
|
required: true
|
|
type: string
|
|
|
|
jobs:
|
|
version:
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: codacy/git-version
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Fix tar access
|
|
run: apk add --update --no-progress tar
|
|
- name: Fix git access
|
|
run: |
|
|
git config --global --add safe.directory /__w/diff2html/diff2html
|
|
- name: Get next version
|
|
run: |
|
|
export NEXT_VERSION="$(/bin/git-version --folder=$PWD --release-branch=master)"
|
|
echo "Next version is ${NEXT_VERSION}"
|
|
echo "${NEXT_VERSION}" > next-version.txt
|
|
echo "version=${NEXT_VERSION}" >> $GITHUB_ENV
|
|
- name: Get next npm tag name
|
|
run: |
|
|
if [ "${GITHUB_REF_NAME}" = "master" ]; then
|
|
export PUBLISH_TAG="latest"
|
|
elif [ "${GITHUB_REF_NAME}" = "next" ]; then
|
|
export PUBLISH_TAG="next"
|
|
else
|
|
export PUBLISH_TAG="pr"
|
|
fi
|
|
echo "Next tag is ${PUBLISH_TAG}"
|
|
echo "${PUBLISH_TAG}" > publish-tag.txt
|
|
- name: Upload versions
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: versions
|
|
if-no-files-found: error
|
|
path: |
|
|
next-version.txt
|
|
publish-tag.txt
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
needs: [version]
|
|
strategy:
|
|
matrix:
|
|
node-version: [16.x, 18.x, 20.x, 22.x]
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Use Node.js ${{ matrix.node-version }}
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: ${{ matrix.node-version }}
|
|
cache: 'npm'
|
|
- name: Log environment setup
|
|
run: |
|
|
node -v
|
|
npm -v
|
|
- name: Install dependencies
|
|
run: npm install
|
|
- name: Build templates
|
|
run: npm run build:templates
|
|
- name: Build library
|
|
run: npm run build
|
|
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
needs: [build]
|
|
environment: ${{ inputs.environment }}
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Download versions
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: versions
|
|
- name: Store version
|
|
run: echo "version=$(cat next-version.txt)" >> $GITHUB_ENV
|
|
- name: Configure Git
|
|
run: |
|
|
git config user.email "gh-actions@users.noreply.github.com"
|
|
git config user.name "GitHub Actions"
|
|
- name: Tag commit
|
|
uses: tvdias/github-tagger@v0.0.1
|
|
with:
|
|
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
|
tag: '${{ env.version }}'
|
|
- name: Install dependencies
|
|
run: npm install
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
registry-url: 'https://registry.npmjs.org'
|
|
node-version: '22.x'
|
|
- name: Configure NPM version
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
run: |
|
|
rm -f .npmrc
|
|
touch .npmrc
|
|
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc
|
|
echo "registry=https://registry.npmjs.org/" >> .npmrc
|
|
echo "access=public" >> .npmrc
|
|
echo "save-exact=true" >> .npmrc
|
|
- name: Version package
|
|
run: |
|
|
# Update version in packages to publish
|
|
npm version $(cat next-version.txt) -m "Release version %s"
|
|
- name: Publish to NPM
|
|
run: npm publish --tag $(cat publish-tag.txt)
|
|
- uses: actions/setup-node@v3
|
|
with:
|
|
node-version: '22.x'
|
|
registry-url: 'https://npm.pkg.github.com'
|
|
- name: Configure NPM version
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
rm -f .npmrc
|
|
touch .npmrc
|
|
echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc
|
|
echo "@rtfpessoa:registry=https://npm.pkg.github.com/" >> .npmrc
|
|
echo "access=public" >> .npmrc
|
|
echo "save-exact=true" >> .npmrc
|
|
- name: Publish to GPR
|
|
run: |
|
|
# HACK: Override npm package name to be able to publish in GitHub
|
|
sed -i 's/^ "name":.*/ "name": "@rtfpessoa\/diff2html",/g' package.json
|
|
echo "Going to publish version $(cat next-version.txt) to GitHub"
|
|
npm publish --tag $(cat publish-tag.txt)
|
|
# HACK: Restore npm package name
|
|
sed -i 's/^ "name":.*/ "name": "diff2html",/g' package.json
|
|
- name: Upload docs
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: docs
|
|
if-no-files-found: error
|
|
path: docs/
|