Skip to content

Commit

Permalink
feat: changing npm publish pipeline (#60)
Browse files Browse the repository at this point in the history
* feat: changing npm publish pipeline

* feat: changing npm publish pipeline
  • Loading branch information
jmpalomares committed May 6, 2024
1 parent 095b8f7 commit 9b423ed
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 43 deletions.
106 changes: 106 additions & 0 deletions .github/workflows/_npm_publish.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
43 changes: 0 additions & 43 deletions .github/workflows/npm.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9b423ed

Please sign in to comment.