|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - main |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + pull-requests: write |
| 9 | + |
| 10 | +name: release |
| 11 | + |
| 12 | +env: |
| 13 | + IS_MERGED_RELEASE_PR: ${{ startsWith(github.event.head_commit.message, '🚀 release:') }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Setup GIT |
| 25 | + uses: fregante/setup-git-user@v2 |
| 26 | + |
| 27 | + - name: Setup Node |
| 28 | + uses: actions/setup-node@v3 |
| 29 | + with: |
| 30 | + node-version: 16 |
| 31 | + registry-url: 'https://registry.npmjs.org' |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }} |
| 35 | + run: npm ci --ignore-scripts |
| 36 | + |
| 37 | + - name: Install dependencies and build package |
| 38 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }} |
| 39 | + run: npm ci |
| 40 | + |
| 41 | + # release-it configuration reference |
| 42 | + # https://github.com/release-it/release-it/blob/fdcf005ced6967a86305a3e10fd1d61a3149407b/docs/configuration.md#configuration |
| 43 | + # https://github.com/release-it/release-it/blob/HEAD/config/release-it.json |
| 44 | + |
| 45 | + - name: Bump version and update changelog |
| 46 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }} |
| 47 | + run: npx release-it --no-npm.publish --no-git --no-github.release --ci |
| 48 | + |
| 49 | + - name: Preview changelog |
| 50 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }} |
| 51 | + id: preview-changelog |
| 52 | + run: | |
| 53 | + { |
| 54 | + echo 'changelog<<EOF' |
| 55 | + npx conventional-changelog -p @favoloso/emoji -u |
| 56 | + echo EOF |
| 57 | + } > "$GITHUB_OUTPUT" |
| 58 | +
|
| 59 | + - name: Read package.json version |
| 60 | + id: package-version |
| 61 | + uses: martinbeentjes/npm-get-version-action@v1.3.1 |
| 62 | + |
| 63 | + - name: Create release PR |
| 64 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'false' }} |
| 65 | + uses: peter-evans/create-pull-request@v5 |
| 66 | + with: |
| 67 | + branch: "release" |
| 68 | + commit-message: "🚀 release: ${{ steps.package-version.outputs.current-version }}" |
| 69 | + delete-branch: true |
| 70 | + labels: release-preview |
| 71 | + title: ${{ steps.package-version.outputs.current-version }} |
| 72 | + body: ${{ steps.preview-changelog.outputs.changelog }} |
| 73 | + |
| 74 | + - name: Read changelog |
| 75 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }} |
| 76 | + id: read-changelog |
| 77 | + run: | |
| 78 | + { |
| 79 | + echo 'changelog<<EOF' |
| 80 | + npx conventional-changelog -p @favoloso/emoji -r 1 |
| 81 | + echo EOF |
| 82 | + } > "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + - name: Git tag, GitHub release |
| 85 | + if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }} |
| 86 | + uses: avakar/tag-and-release@v1 |
| 87 | + with: |
| 88 | + tag_name: ${{ steps.package-version.outputs.current-version }} |
| 89 | + release_name: ${{ steps.package-version.outputs.current-version }} |
| 90 | + body: ${{ steps.read-changelog.outputs.changelog }} |
| 91 | + env: |
| 92 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + |
| 94 | +# - name: Publish NPM package |
| 95 | +# if: ${{ env.IS_MERGED_RELEASE_PR == 'true' }} |
| 96 | +# run: npm publish |
| 97 | +# env: |
| 98 | +# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments