From 41a3fbfd55119d04c79dbb714ee16d3de0db4abd Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Sun, 14 Jan 2024 16:28:29 +0100 Subject: [PATCH] ci: automate npm publish (#305) Add a workflow that performs the publishing when a new Git tag is pushed. --- .github/actions/build-setup/action.yml | 6 ++++++ .github/workflows/publish-npm-package.yml | 22 ++++++++++++++++++++ packages/website/docs/development/release.md | 3 +++ 3 files changed, 31 insertions(+) create mode 100644 .github/workflows/publish-npm-package.yml diff --git a/.github/actions/build-setup/action.yml b/.github/actions/build-setup/action.yml index 2770e4d4f..74f722afd 100644 --- a/.github/actions/build-setup/action.yml +++ b/.github/actions/build-setup/action.yml @@ -1,6 +1,11 @@ name: 'Build Setup' description: 'Setup node and install dependencies' +inputs: + registry-url: + description: 'Optional registry to set up for auth.' + required: false + runs: using: 'composite' steps: @@ -8,6 +13,7 @@ runs: uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' + registry-url: ${{ inputs.registry-url }} - name: Install dependencies uses: bahmutov/npm-install@v1 with: diff --git a/.github/workflows/publish-npm-package.yml b/.github/workflows/publish-npm-package.yml new file mode 100644 index 000000000..7adb29584 --- /dev/null +++ b/.github/workflows/publish-npm-package.yml @@ -0,0 +1,22 @@ +name: Publish NPM Package +on: + push: + tags: + - v* +jobs: + build: + runs-on: ubuntu-22.04 + permissions: + # required for "npm provenance" + id-token: write + contents: write + steps: + - uses: actions/checkout@v4 + - name: Build Setup + uses: ./.github/actions/build-setup + with: + registry-url: 'https://registry.npmjs.org' + # scoped package requires "access=public" + - run: npm publish -w packages/core --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/packages/website/docs/development/release.md b/packages/website/docs/development/release.md index 95627ecb7..e4bfb6d57 100644 --- a/packages/website/docs/development/release.md +++ b/packages/website/docs/development/release.md @@ -56,6 +56,9 @@ git tag v0.2.0 ## Publish the npm package +The package is published automatically once the Git tag is pushed thanks to a [GitHub workflow](https://github.com/maxGraph/maxgraph-integration-examples/actions/workflows/publish-npm-package.yml). + +If its execution fails, and you want to publish the package manually: - Checkout the tag that has just been created - From packages/core: - run `npm publish`