|
| 1 | +name: 🏷️ Publish NPM Latest |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + dryrun: |
| 7 | + type: boolean |
| 8 | + required: false |
| 9 | + description: Dry-Run |
| 10 | + version: |
| 11 | + description: 'Fixed Version' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + id-token: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + deploy-npm-latest: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 30 |
| 23 | + steps: |
| 24 | + - name: Retrieve current Date Time in EST |
| 25 | + shell: bash |
| 26 | + run: echo "START_TIME=$(TZ=":America/New_York" date -R|sed 's/.....$//')" >> $GITHUB_ENV |
| 27 | + |
| 28 | + - name: Current datetime - ${{ env.START_TIME }} |
| 29 | + run: echo ${{ env.START_TIME }} |
| 30 | + |
| 31 | + - name: Clone repository |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + fetch-depth: 0 |
| 35 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + |
| 37 | + - if: ${{ github.event.pull_request.merged != true && contains('["ghiscoding"]', github.actor) != true }} |
| 38 | + name: Exit early when current actor is not allowed to push new release |
| 39 | + run: | |
| 40 | + echo "Error: Your GitHub username (${{ github.actor }}) is not on the allowed list of admins for this workflow" |
| 41 | + exit 1 |
| 42 | +
|
| 43 | + - name: Set NodeJS |
| 44 | + uses: actions/setup-node@v4 |
| 45 | + with: |
| 46 | + registry-url: 'https://registry.npmjs.org/' |
| 47 | + node-version: 22 |
| 48 | + |
| 49 | + - name: Get npm cache directory path |
| 50 | + id: npm-cache-dir-path |
| 51 | + run: echo "dir=$(npm config get cache)" >> $GITHUB_OUTPUT |
| 52 | + |
| 53 | + - uses: actions/cache@v4 |
| 54 | + id: npm-cache |
| 55 | + with: |
| 56 | + path: ${{ steps.npm-cache-dir-path.outputs.dir }} |
| 57 | + key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-npm- |
| 60 | +
|
| 61 | + - name: Install dependencies |
| 62 | + run: npm ci |
| 63 | + |
| 64 | + - name: 🧪 Dry-Run - GitHub Release |
| 65 | + if: ${{ inputs.dryrun == true }} |
| 66 | + env: |
| 67 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + NPM_CONFIG_PROVENANCE: true |
| 70 | + run: | |
| 71 | + git config --global user.name "${{ github.actor }}" |
| 72 | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" |
| 73 | + npm whoami |
| 74 | + npx release-it --ci --dry-run |
| 75 | +
|
| 76 | + - name: OTP |
| 77 | + if: ${{ inputs.dryrun != true }} |
| 78 | + uses: step-security/wait-for-secrets@v1 |
| 79 | + id: wait-for-secrets |
| 80 | + with: |
| 81 | + secrets: | |
| 82 | + OTP: |
| 83 | + name: 'OTP to publish package' |
| 84 | + description: 'OTP from authenticator app' |
| 85 | +
|
| 86 | + - name: Fixed Version Release ⚙️ / NPM Publish 📦 |
| 87 | + if: ${{ inputs.version != '' }} |
| 88 | + env: |
| 89 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 90 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + NPM_CONFIG_PROVENANCE: true |
| 92 | + run: | |
| 93 | + git config --global user.name "${{ github.actor }}" |
| 94 | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" |
| 95 | + npm whoami |
| 96 | + npx release-it ${{ inputs.version }} --ci --plugins.'@release-it/conventional-changelog'.ignoreRecommendedBump=false --npm.otp=${{ steps.wait-for-secrets.outputs.OTP }} |
| 97 | +
|
| 98 | + - name: GitHub Release 🏷️ / NPM Publish 📦 |
| 99 | + if: ${{ inputs.dryrun != true && inputs.version == '' }} |
| 100 | + env: |
| 101 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 102 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 103 | + NPM_CONFIG_PROVENANCE: true |
| 104 | + run: | |
| 105 | + git config --global user.name "${{ github.actor }}" |
| 106 | + git config --global user.email "${{ github.actor }}@users.noreply.github.com" |
| 107 | + npm whoami |
| 108 | + npx release-it --ci --npm.otp=${{ steps.wait-for-secrets.outputs.OTP }} |
0 commit comments