From d32f2d97a15a0f2710060c6f46ed6e112ca25068 Mon Sep 17 00:00:00 2001 From: Damian Borowiecki Date: Tue, 30 Apr 2024 19:22:12 +0200 Subject: [PATCH] Added centralized workflow for npm publishing (#133) add generic publish --------- Co-authored-by: Patrick Delcroix --- .github/workflows/module-npmpublish.yml | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/module-npmpublish.yml diff --git a/.github/workflows/module-npmpublish.yml b/.github/workflows/module-npmpublish.yml new file mode 100644 index 0000000..fca661e --- /dev/null +++ b/.github/workflows/module-npmpublish.yml @@ -0,0 +1,66 @@ +name: Reusable Node.js Package Workflow + +on: + workflow_call: + inputs: + node_version: + type: string + required: true + registry_url: + type: string + required: true + scope: + type: string + default: 'openimis' + access: + type: string + default: 'public' + tag: + type: string + secrets: + NPM_TOKEN: + required: true + +jobs: + build_and_publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ inputs.node_version }} + registry-url: ${{ inputs.registry_url }} + scope: ${{ inputs.scope }} + - name: Update version with TAG + env: + TAG_NAME: ${{ github.event.inputs.tag }} + run: | + if [ -z "$TAG_NAME" ]; then + git fetch --tags + export TAG_NAME=$(git tag --sort=-version:refname | head -n 1) + fi + echo "tag to use $TAG_NAME" + echo $(jq --arg a "$TAG_NAME" '.version = ($a)' package.json) > package.json + - run: yarn install + - run: yarn build + - run: npm publish --access ${{ inputs.access }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + +# Use example +# name: Implement Node.js Package Workflow + +# on: +# release: +# types: [published] + +# jobs: +# call-central-workflow: +# uses: openimis/openimis-fe_js/.github/workflows/module-npmpublish.yml@develop +# with: +# node_version: '18' +# registry_url: 'https://registry.npmjs.org/' +# access: 'public' +# scope: 'openimis' +# secrets: +# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}