Skip to content

Test and Publish Workflow #306

Test and Publish Workflow

Test and Publish Workflow #306

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Test and Publish Workflow
on:
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
ref:
description: |
The branch, tag or SHA to checkout. When checking out the repository that
triggered a workflow, this defaults to the reference or SHA for that event.
Otherwise, uses the default branch.
required: false
default: master
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
version: [
{ node: "16.x", npm: "9" },
{ node: "18.x", npm: "10" },
{ node: "20.x", npm: "10" }
]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.version.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.version.node }}
cache: 'npm'
- name: Get GCloud CLI to install pubsub emulator
uses: google-github-actions/setup-gcloud@v1
with:
install_components: 'beta,pubsub-emulator'
- run: npm i -g npm@${{ matrix.version.npm }}
- run: npm i
name: Install root dependencies
- run: npm run lint
name: Lint all packages
- run: npm run test:cov:all
name: Launch tests for each packages
publish:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch' }}
needs: test
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
cache: 'npm'
- run: npm i -g npm@10 && npm i
- run: npm run build
- run: git config --global user.email "[email protected]" && git config --global user.name "Algoan Bot"
- run: npx lerna version --conventional-commits --changelog-preset conventionalcommits --create-release github --include-merged-tags --yes
name: Run Lerna version
env:
GH_TOKEN: ${{ secrets.PUBLIC_REPO_GHA_PAT }}
- name: Setting NPM configs to publish to NPM
run: |
echo "//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}" > .npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publishing to NPM
run: npx lerna publish from-git --yes --registry=https://registry.npmjs.org
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setting NPM configs to publish to GitHub Packages
run: |
echo "@algoan:registry=https://npm.pkg.github.com" > .npmrc
echo "//npm.pkg.github.com/:_authToken=\${NODE_AUTH_TOKEN}" >> .npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publishing to GitHub Packages
run: npx lerna publish from-git --yes --registry=https://npm.pkg.github.com
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}