Publish packages to NPM #389
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish packages to NPM | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: | |
- closed | |
branches: | |
- master | |
workflow_run: | |
workflows: [Update API client] | |
types: | |
- completed | |
jobs: | |
publish: | |
if: | |
github.event.pull_request.merged == true || | |
github.event.workflow_run.conclusion == 'success' | |
runs-on: ubuntu-latest | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
PUBLISH_PAT: ${{ secrets.PUBLISH_PAT }} | |
GH_TOKEN: ${{ secrets.PUBLISH_PAT }} | |
steps: | |
- name: Checkout ⬇️ | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PUBLISH_PAT }} | |
- name: Setup Node 🎛️ | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: "yarn" | |
registry-url: "https://registry.npmjs.org" | |
- name: Git Identity 🪪 | |
run: | | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor }}@users.noreply.github.com" | |
- name: Yarn Install 📦️ | |
run: yarn install --immutable | |
- name: Setup NX 1/2 🎛️ | |
uses: nrwl/nx-set-shas@v4 | |
with: | |
main-branch-name: master | |
# This step is needed for nx affected to work when CI is running on a PR | |
# See also https://nx.dev/ci/recipes/set-up/monorepo-ci-github-actions#configuring-ci-using-github-actions-and-nx | |
- name: Setup NX 2/2 🎛 | |
if: | |
(github.ref != 'refs/heads/master' && | |
github.event.workflow_run.head_branch != 'master') | |
run: git branch --track master origin/master | |
- name: Build 🔨 | |
run: yarn nx affected -t build --parallel=3 | |
# TODO: Uses the previous version. Needs a fix! | |
- name: Create version file 🔢 | |
run: | | |
yarn nx run @mittwald/api-client:build:write-version-file | |
git add . | |
- name: Version and publish 🚀 | |
if: | |
github.event.workflow_run.head_branch == 'master' || github.ref == | |
'refs/heads/master' | |
run: | | |
yarn lerna publish \ | |
--conventional-commits \ | |
--create-release github \ | |
--message "chore(release): bump version to %v" \ | |
--yes --no-private \ | |
--tag-version-prefix "" |