|
| 1 | +name: NPM Release Automation |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + environment: |
| 6 | + description: 'The library release version' |
| 7 | + required: true |
| 8 | + default: '' |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout Repository |
| 15 | + uses: actions/checkout@v3 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + token: ${{ secrets.PAT }} |
| 19 | + - name: Set up Node.js |
| 20 | + uses: actions/setup-node@v3 |
| 21 | + with: |
| 22 | + node-version: 20 |
| 23 | + registry-url: "https://registry.npmjs.org/" |
| 24 | + - name: Install packages |
| 25 | + run: npm install |
| 26 | + - name: Build modules |
| 27 | + run: npm run build |
| 28 | + - name: Test |
| 29 | + run: npm run test |
| 30 | + - name: Update package.json version |
| 31 | + run: | |
| 32 | + VERSION="${{ github.event.inputs.environment }}" |
| 33 | + echo "Release v $VERSION" |
| 34 | + jq --arg ver "$VERSION" '.version = $ver' package.json > temp.json && mv temp.json package.json |
| 35 | + jq --arg ver "$VERSION" '.version = $ver' modules/cmpapi/package.json > temp.json && mv temp.json modules/cmpapi/package.json |
| 36 | + jq --arg ver "$VERSION" '.version = $ver' modules/stub/package.json > temp.json && mv temp.json modules/stub/package.json |
| 37 | + - name: Check input version TAG |
| 38 | + id: check |
| 39 | + run: | |
| 40 | + git status |
| 41 | + VERSION="${{ github.event.inputs.environment }}" |
| 42 | + echo "Release v $VERSION" |
| 43 | + if git show-ref --tags --verify --quiet "refs/tags/${VERSION}"; then |
| 44 | + echo "Tag ${VERSION} exists" |
| 45 | + echo "version_changed=false" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "Tag ${VERSION} does not exist" |
| 48 | + echo "version_changed=true" >> $GITHUB_OUTPUT |
| 49 | + fi |
| 50 | + - name: Publish to NPM |
| 51 | + if: ${{steps.check.outputs.version_changed == 'true'}} |
| 52 | + run: | |
| 53 | + npm --version |
| 54 | + cd modules/stub |
| 55 | + pwd |
| 56 | + npm publish --access public #actual release to NPM repository |
| 57 | + cd ../cmpapi |
| 58 | + pwd |
| 59 | + npm publish --access public #actual release to NPM repository |
| 60 | + |
| 61 | + env: |
| 62 | + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
| 63 | + - name: Commit and Push Changes |
| 64 | + if: ${{steps.check.outputs.version_changed == 'true'}} |
| 65 | + run: | |
| 66 | + git status |
| 67 | + VERSION="${{ github.event.inputs.environment }}" |
| 68 | + echo "Release v $VERSION" |
| 69 | + #Stage the files |
| 70 | + git add . |
| 71 | + git commit -m "Release v $VERSION" |
| 72 | + git tag "$VERSION" |
| 73 | + git push --tags #actual tag push to GitHub Repo |
| 74 | + git push origin master #actual push to GitHub Repo |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{secrets.PAT}} |
0 commit comments