Publish to NPM #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| command: | |
| required: true | |
| type: choice | |
| options: | |
| - test | |
| - publish | |
| default: test | |
| version: | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: create github token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.ACTIONS_RUNNER_APP_ID }} | |
| private-key: ${{ secrets.ACTIONS_RUNNER_PRIVATE_KEY }} | |
| - name: checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: configure git | |
| run: | | |
| git config --global user.name "FusionAuth Automation" | |
| git config --global user.email "donotreply@fusionauth.io" | |
| - name: set aws credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: arn:aws:iam::752443094709:role/gha-fusionauth-node-cli | |
| role-session-name: aws-auth-action | |
| aws-region: us-west-2 | |
| - name: get secret | |
| run: | | |
| while IFS=$'\t' read -r key value; do | |
| echo "::add-mask::${value}" | |
| echo "${key}=${value}" >> $GITHUB_ENV | |
| done < <(aws secretsmanager get-secret-value \ | |
| --region us-west-2 \ | |
| --secret-id platform/npmjs \ | |
| --query SecretString \ | |
| --output text | \ | |
| jq -r 'to_entries[] | [.key, .value] | @tsv') | |
| - name: create npmrc | |
| run: | | |
| echo "color=false" > ~/.npmrc | |
| echo "//registry.npmjs.org/:_authToken=${{ env.API_KEY }}" >> ~/.npmrc | |
| chmod 600 ~/.npmrc | |
| - name: set version | |
| run: npm version ${{ inputs.version }} | |
| - name: commit version changes (only on main branch) | |
| if: inputs.command == 'publish' && github.ref == 'refs/heads/main' | |
| run: | | |
| git push | |
| git push --tags | |
| - name: install dependencies | |
| run: npm install | |
| - name: build the package | |
| run: npm run build | |
| - name: test publish to npmjs | |
| if: inputs.command == 'test' | |
| run: npm publish --dry-run | |
| - name: publish to npmjs (only on main branch) | |
| if: inputs.command == 'publish' && github.ref == 'refs/heads/main' | |
| run: npm publish | |