|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + release-check: |
| 10 | + name: Check if version is published |
| 11 | + runs-on: ubuntu-latest |
| 12 | + defaults: |
| 13 | + run: |
| 14 | + shell: bash |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: 22 |
| 21 | + |
| 22 | + - name: Check if version is published |
| 23 | + id: check |
| 24 | + run: | |
| 25 | + currentVersion="$( node -e "console.log(require('./package.json').version)" )" |
| 26 | + isPublished="$( npm view @mapbox/node-pre-gyp versions --json | jq -c --arg cv "$currentVersion" 'any(. == $cv)' )" |
| 27 | + echo "published=$isPublished" >> "$GITHUB_OUTPUT" |
| 28 | + echo "currentVersion: $currentVersion" |
| 29 | + echo "isPublished: $isPublished" |
| 30 | + outputs: |
| 31 | + published: ${{ steps.check.outputs.published }} |
| 32 | + |
| 33 | + publish: |
| 34 | + needs: release-check |
| 35 | + if: ${{ needs.release-check.outputs.published == 'false' }} |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: write |
| 39 | + defaults: |
| 40 | + run: |
| 41 | + shell: bash |
| 42 | + |
| 43 | + steps: |
| 44 | + - uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - uses: actions/setup-node@v4 |
| 47 | + with: |
| 48 | + node-version: 22 |
| 49 | + |
| 50 | + - run: npm ci |
| 51 | + |
| 52 | + - run: npm audit |
| 53 | + |
| 54 | + - run: npm run lint |
| 55 | + |
| 56 | + - run: npm run update-crosswalk # To support newer versions of Node.js |
| 57 | + |
| 58 | + - run: npm run build --if-present |
| 59 | + |
| 60 | + - run: npm test |
| 61 | + |
| 62 | + - name: Get version |
| 63 | + id: package-version |
| 64 | + uses: martinbeentjes/[email protected] |
| 65 | + |
| 66 | + - name: Prepare release changelog |
| 67 | + id: prepare_release |
| 68 | + run: | |
| 69 | + RELEASE_TYPE="$(node -e "console.log(require('semver').prerelease('${{ steps.package-version.outputs.current-version }}') ? 'prerelease' : 'regular')")" |
| 70 | + if [[ $RELEASE_TYPE == 'regular' ]]; then |
| 71 | + echo "prerelease=false" >> "$GITHUB_OUTPUT" |
| 72 | + else |
| 73 | + echo "prerelease=true" >> "$GITHUB_OUTPUT" |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Extract changelog for version |
| 77 | + run: | |
| 78 | + awk '/^##/ { p = 0 }; p == 1 { print }; $0 == "## ${{ steps.package-version.outputs.current-version }}" { p = 1 };' CHANGELOG.md > changelog_for_version.md |
| 79 | + cat changelog_for_version.md |
| 80 | +
|
| 81 | + - name: Publish to Github |
| 82 | + uses: ncipollo/release-action@v1 |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + with: |
| 86 | + tag: v${{ steps.package-version.outputs.current-version }} |
| 87 | + name: v${{ steps.package-version.outputs.current-version }} |
| 88 | + bodyFile: changelog_for_version.md |
| 89 | + allowUpdates: true |
| 90 | + draft: false |
| 91 | + prerelease: ${{ steps.prepare_release.outputs.prerelease }} |
| 92 | + |
| 93 | + - name: Publish to NPM (release) |
| 94 | + if: ${{ steps.prepare_release.outputs.prerelease == 'false' }} |
| 95 | + run: | |
| 96 | + npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}" |
| 97 | + npm publish --access public |
| 98 | + env: |
| 99 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 100 | + |
| 101 | + - name: Publish to NPM (prerelease) |
| 102 | + if: ${{ steps.prepare_release.outputs.prerelease == 'true' }} |
| 103 | + run: | |
| 104 | + npm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}" |
| 105 | + npm publish --tag next --access public |
| 106 | + env: |
| 107 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments