|
| 1 | +name: Create a release |
| 2 | + |
| 3 | +on: |
| 4 | + # Trigger a stable version release via GitHub's UI, with the ability to specify the type of release. |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + release_type: |
| 8 | + description: Release type |
| 9 | + required: true |
| 10 | + type: choice |
| 11 | + default: auto |
| 12 | + options: |
| 13 | + - auto |
| 14 | + - custom |
| 15 | + - patch |
| 16 | + - minor |
| 17 | + - major |
| 18 | + custom_version: |
| 19 | + description: The custom version to bump to (only for "custom" type) |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + default: "" |
| 23 | + |
| 24 | +concurrency: |
| 25 | + group: release |
| 26 | + cancel-in-progress: false |
| 27 | + |
| 28 | +jobs: |
| 29 | + release_metadata: |
| 30 | + name: Prepare release metadata |
| 31 | + runs-on: ubuntu-latest |
| 32 | + outputs: |
| 33 | + version_number: ${{ steps.release_metadata.outputs.version_number }} |
| 34 | + tag_name: ${{ steps.release_metadata.outputs.tag_name }} |
| 35 | + changelog: ${{ steps.release_metadata.outputs.changelog }} |
| 36 | + release_notes: ${{ steps.release_metadata.outputs.release_notes }} |
| 37 | + steps: |
| 38 | + - uses: apify/workflows/git-cliff-release@main |
| 39 | + name: Prepare release metadata |
| 40 | + id: release_metadata |
| 41 | + with: |
| 42 | + release_type: ${{ inputs.release_type }} |
| 43 | + custom_version: ${{ inputs.custom_version }} |
| 44 | + existing_changelog_path: CHANGELOG.md |
| 45 | + |
| 46 | + update_changelog: |
| 47 | + needs: [ release_metadata ] |
| 48 | + name: Update changelog |
| 49 | + runs-on: ubuntu-latest |
| 50 | + outputs: |
| 51 | + changelog_commitish: ${{ steps.commit.outputs.commit_long_sha || github.sha }} |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Checkout repository |
| 55 | + uses: actions/checkout@v4 |
| 56 | + with: |
| 57 | + token: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }} |
| 58 | + |
| 59 | + - name: Use Node.js 22 |
| 60 | + uses: actions/setup-node@v4 |
| 61 | + with: |
| 62 | + node-version: 22 |
| 63 | + |
| 64 | + - name: Update package version in package.json |
| 65 | + run: npm version --no-git-tag-version --allow-same-version ${{ needs.release_metadata.outputs.version_number }} |
| 66 | + |
| 67 | + - name: Update CHANGELOG.md |
| 68 | + uses: DamianReeves/write-file-action@master |
| 69 | + with: |
| 70 | + path: CHANGELOG.md |
| 71 | + write-mode: overwrite |
| 72 | + contents: ${{ needs.release_metadata.outputs.changelog }} |
| 73 | + |
| 74 | + - name: Commit changes |
| 75 | + id: commit |
| 76 | + uses: EndBug/add-and-commit@v9 |
| 77 | + with: |
| 78 | + author_name: Apify Release Bot |
| 79 | + |
| 80 | + message: "chore(release): Update changelog and package version [skip ci]" |
| 81 | + |
| 82 | + create_github_release: |
| 83 | + name: Create github release |
| 84 | + needs: [release_metadata, update_changelog] |
| 85 | + runs-on: ubuntu-latest |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + steps: |
| 89 | + - name: Create release |
| 90 | + uses: softprops/action-gh-release@v2 |
| 91 | + with: |
| 92 | + tag_name: ${{ needs.release_metadata.outputs.tag_name }} |
| 93 | + name: ${{ needs.release_metadata.outputs.version_number }} |
| 94 | + target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }} |
| 95 | + body: ${{ needs.release_metadata.outputs.release_notes }} |
| 96 | + |
| 97 | + publish_to_npm: |
| 98 | + name: Publish to NPM |
| 99 | + needs: [ update_changelog ] |
| 100 | + runs-on: ubuntu-latest |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + ref: ${{ needs.update_changelog.changelog_commitish }} |
| 105 | + - name: Use Node.js 22 |
| 106 | + uses: actions/setup-node@v4 |
| 107 | + with: |
| 108 | + node-version: 22 |
| 109 | + cache: 'npm' |
| 110 | + cache-dependency-path: 'package-lock.json' |
| 111 | + - name: Install dependencies |
| 112 | + run: | |
| 113 | + echo "access=public" >> .npmrc |
| 114 | + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc |
| 115 | + npm ci |
| 116 | + - name: Build module |
| 117 | + run: npm run build |
| 118 | + - name: Publish to NPM |
| 119 | + run: npm publish --tag latest |
| 120 | + |
| 121 | +env: |
| 122 | + NODE_AUTH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} |
| 123 | + NPM_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_NPM_TOKEN }} |
0 commit comments