|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + release-check: |
| 10 | + name: Check if version changed |
| 11 | + runs-on: ubuntu-latest |
| 12 | + defaults: |
| 13 | + run: |
| 14 | + shell: bash |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + ref: main |
| 20 | + |
| 21 | + - name: Use Node.js from nvmrc |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version-file: '.nvmrc' |
| 25 | + |
| 26 | + - name: Check if version has been updated |
| 27 | + id: check |
| 28 | + uses: EndBug/version-check@v2 |
| 29 | + |
| 30 | + outputs: |
| 31 | + publish: ${{ steps.check.outputs.changed }} |
| 32 | + |
| 33 | + release: |
| 34 | + name: Release |
| 35 | + needs: release-check |
| 36 | + if: ${{ needs.release-check.outputs.publish == 'true' }} |
| 37 | + runs-on: ubuntu-latest |
| 38 | + defaults: |
| 39 | + run: |
| 40 | + shell: bash |
| 41 | + steps: |
| 42 | + |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + ref: main |
| 47 | + |
| 48 | + - name: Use Node.js from nvmrc |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version-file: '.nvmrc' |
| 52 | + registry-url: 'https://registry.npmjs.org' |
| 53 | + |
| 54 | + - name: Get version |
| 55 | + id: package-version |
| 56 | + uses: martinbeentjes/[email protected] |
| 57 | + |
| 58 | + - name: Install |
| 59 | + run: npm ci |
| 60 | + |
| 61 | + - name: Prepare release |
| 62 | + id: prepare_release |
| 63 | + run: | |
| 64 | + RELEASE_TYPE=$(node -e "console.log(require('semver').prerelease('${{ steps.package-version.outputs.current-version }}') ? 'prerelease' : 'regular')") |
| 65 | + echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT |
| 66 | +
|
| 67 | + - name: Build |
| 68 | + run: | |
| 69 | + npm run build |
| 70 | +
|
| 71 | + - name: Publish NPM package (regular) |
| 72 | + if: ${{ steps.prepare_release.outputs.release_type == 'regular' }} |
| 73 | + run: | |
| 74 | + npm publish |
| 75 | + env: |
| 76 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_ORG_TOKEN }} |
| 77 | + |
| 78 | + - name: Publish NPM package (pre-release) |
| 79 | + if: ${{ steps.prepare_release.outputs.release_type == 'prerelease' }} |
| 80 | + run: | |
| 81 | + npm publish --tag next |
| 82 | + env: |
| 83 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_ORG_TOKEN }} |
| 84 | + |
| 85 | + - name: Tag commit and push |
| 86 | + id: tag_version |
| 87 | + uses: mathieudutour/[email protected] |
| 88 | + with: |
| 89 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + custom_tag: ${{ steps.package-version.outputs.current-version }} |
| 91 | + |
| 92 | + - name: Create Archive |
| 93 | + run: | |
| 94 | + zip -r dist dist |
| 95 | +
|
| 96 | + - name: Create GitHub Release |
| 97 | + uses: ncipollo/release-action@v1 |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + with: |
| 101 | + tag: ${{ steps.tag_version.outputs.new_tag }} |
| 102 | + name: ${{ steps.tag_version.outputs.new_tag }} |
| 103 | + artifacts: "dist.zip" |
| 104 | + artifactContentType: "application/zip" |
| 105 | + allowUpdates: true |
| 106 | + draft: false |
| 107 | + prerelease: ${{ steps.prepare_release.outputs.release_type == 'prerelease' }} |
0 commit comments