From 9b423ed43cd334b5bae75c8b76db1b949f2d3967 Mon Sep 17 00:00:00 2001 From: Jose Manuel Palomares Date: Mon, 6 May 2024 19:20:59 +0200 Subject: [PATCH] feat: changing npm publish pipeline (#60) * feat: changing npm publish pipeline * feat: changing npm publish pipeline --- .github/workflows/_npm_publish.yaml | 106 ++++++++++++++++++++++++++++ .github/workflows/npm.yaml | 43 ----------- .github/workflows/publish.yaml | 52 ++++++++++++++ 3 files changed, 158 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/_npm_publish.yaml delete mode 100644 .github/workflows/npm.yaml create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/_npm_publish.yaml b/.github/workflows/_npm_publish.yaml new file mode 100644 index 0000000..03cd067 --- /dev/null +++ b/.github/workflows/_npm_publish.yaml @@ -0,0 +1,106 @@ +################################################################################ +# DO NOT EDIT THIS FILE (Auto-Generated) # +# Contents of this file were generated by https://github.com/parcelLab/.github # +# Changes to this file may be overwritten. # +################################################################################ +name: ~Lib / NPM Publish +on: + workflow_call: + inputs: + access: + required: false + description: The package access ('restricted' or 'public') + default: restricted + type: string + botEmail: + required: false + description: The email of the bot that will appear in the GitOps commit + default: dev.bot@parcellab.com + type: string + botName: + required: false + description: The name of the bot that will appear in the GitOps commit + default: parcellab-dev-bot + type: string + buildBeforePublish: + required: false + description: Build the package before publishing + default: true + type: string + defaultBranch: + required: false + description: The default branch + default: main + type: string + nodeVersion: + required: false + description: The node version to provide (e.g. `lts/*`, `18`, `18.4`...) + default: latest + type: string + scope: + required: false + description: The npm organization (defaults to @parcellab) + default: "@parcellab" + type: string + version: + required: true + description: The version to publish (without 'v') + type: string + secrets: + githubAuthToken: + required: false + npmjsAuthToken: + required: false +jobs: + npm-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout current git repository + uses: actions/checkout@v3 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of REPO_ACCESS_TOKEN + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository + - name: Use Node.js with Github Packages as registry url + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.nodeVersion }} + registry-url: https://npm.pkg.github.com + scope: ${{ inputs.scope }} + - name: Install npm dependencies + run: npm i + env: + NPM_GITHUB_TOKEN: ${{ secrets.PACKAGES_READ_TOKEN }} + - if: inputs.buildBeforePublishing + name: Run build + run: npm run build + - name: Update package.json version to ${{ inputs.version }} + uses: mikefarah/yq@v4.27.2 + with: + cmd: | + yq e '.version = "${{ inputs.version }}"' -i package.json -j + - name: Commit new package.json version + run: | + git config --local user.email "${{ inputs.botEmail }}" + git config --local user.name "${{ inputs.botName }}" + git commit -m "chore: set version ${{ inputs.version }} [skip ci]" -a + - name: Push changes to current git repository + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.githubAuthToken }} + branch: ${{ inputs.defaultBranch }} + - name: Publish NPM package + run: npm publish --access ${{ inputs.access }} + env: + NODE_AUTH_TOKEN: ${{ secrets.githubAuthToken }} + - if: inputs.access == 'public' + name: Use Node.js with NPMjs as registry url + uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.nodeVersion }} + registry-url: https://registry.npmjs.org + scope: ${{ inputs.scope }} + - if: inputs.access == 'public' + name: Publish NPM package + run: npm publish --access ${{ inputs.access }} + env: + NODE_AUTH_TOKEN: ${{ secrets.npmjsAuthToken }} diff --git a/.github/workflows/npm.yaml b/.github/workflows/npm.yaml deleted file mode 100644 index 1f22a0f..0000000 --- a/.github/workflows/npm.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: NPM -on: - push: - tags: - - "v*" - workflow_dispatch: - inputs: - version: - description: The version to publish (without 'v', e.g. 1.0.0) - required: true -jobs: - version: - runs-on: ubuntu-latest - outputs: - version: ${{ steps.load_version.outputs.version }} - steps: - - name: Load version - id: load_version - run: | - if [ "$GITHUB_EVENT_NAME" = 'workflow_dispatch' ] - then - VERSION="${{ github.event.inputs.version }}" - else - if [ "$GITHUB_EVENT_NAME" = 'release' ] - then - TAG_NAME="${{ github.event.release.tag_name }}" - else - TAG_NAME="${{ github.ref }}" - fi - CLEAN_TAG=${TAG_NAME##*/} - VERSION=${CLEAN_TAG//v} - fi - echo "version=$VERSION" >> $GITHUB_OUTPUT - publish: - needs: version - uses: parcelLab/ci/.github/workflows/npm.yaml@v1 - with: - # access: public - buildBeforePublish: false - version: ${{ needs.version.outputs.version }} - secrets: - githubAuthToken: ${{ secrets.NPM_GITHUB_TOKEN }} - # npmjsAuthToken: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..2e9e25d --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,52 @@ +################################################################################ +# DO NOT EDIT THIS FILE (Auto-Generated) - COPY IT! # +# # +# Contents of this file were generated by https://github.com/parcelLab/.github # +# Changes to this file may be overwritten. # +# # +# Copy this file into the repo .github/workflows folder and edit it based on # +# your needs to create a new workflow. Rename it to `publish.yaml`. # +################################################################################ +name: Publish +on: + push: + tags: + - "v*" + workflow_dispatch: + inputs: + version: + description: The version to publish (without 'v', e.g. 1.0.0) + required: true +jobs: + version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.load_version.outputs.version }} + steps: + - name: Load version + id: load_version + run: | + if [ "$GITHUB_EVENT_NAME" = 'workflow_dispatch' ] + then + VERSION="${{ github.event.inputs.version }}" + else + if [ "$GITHUB_EVENT_NAME" = 'release' ] + then + TAG_NAME="${{ github.event.release.tag_name }}" + else + TAG_NAME="${{ github.ref }}" + fi + CLEAN_TAG=${TAG_NAME##*/} + VERSION=${CLEAN_TAG//v} + fi + echo "::set-output name=version::$VERSION" + publish: + needs: version + uses: ./.github/workflows/_npm-publish.yaml + with: + # access: public # For public packages + # buildBeforePublish: false # For packages that do not require a build step + version: ${{ needs.version.outputs.version }} + secrets: + githubAuthToken: ${{ secrets.REPO_ACCESS_TOKEN }} + # npmjsAuthToken: ${{ secrets.NPM_TOKEN }} # For public packages