|
| 1 | +name: Create release PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "The new version number with 'v' prefix. Example: v1.40.1" |
| 8 | + required: true |
| 9 | + |
| 10 | +jobs: |
| 11 | + init_release: |
| 12 | + name: 🚀 Create release PR |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + with: |
| 17 | + fetch-depth: 0 # gives the changelog generator access to all previous commits |
| 18 | + |
| 19 | + - name: Get current tag |
| 20 | + id: previoustag |
| 21 | + uses: WyriHaximus/github-action-get-previous-tag@v1 |
| 22 | + |
| 23 | + - name: Ensure version number higher than current |
| 24 | + uses: actions/github-script@v5 |
| 25 | + env: |
| 26 | + PREVIOUS_TAG: ${{ steps.previoustag.outputs.tag }} |
| 27 | + DESTINATION_TAG: ${{ github.event.inputs.version }} |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const { PREVIOUS_TAG, DESTINATION_TAG } = process.env; |
| 31 | + const result = DESTINATION_TAG.localeCompare(PREVIOUS_TAG, undefined, { numeric: true, sensitivity: 'base' }) |
| 32 | +
|
| 33 | + if (result != 1) { |
| 34 | + throw new Error('The new version number must be greater than the previous one.') |
| 35 | + } |
| 36 | +
|
| 37 | + - name: Restore dependencies |
| 38 | + uses: ./.github/actions/setup-node |
| 39 | + |
| 40 | + - name: Update CHANGELOG.md, package.json and push release branch |
| 41 | + uses: actions/github-script@v5 |
| 42 | + env: |
| 43 | + VERSION: ${{ github.event.inputs.version }} |
| 44 | + run: | |
| 45 | + npm run changelog |
| 46 | + git config --global user.name 'github-actions' |
| 47 | + git config --global user.email '[email protected]' |
| 48 | + git checkout -q -b "release-$VERSION" |
| 49 | + git commit -am "chore(release): $VERSION" |
| 50 | + git push -q -u origin "release-$VERSION" |
| 51 | +
|
| 52 | + - name: Get changelog diff |
| 53 | + uses: actions/github-script@v5 |
| 54 | + with: |
| 55 | + script: | |
| 56 | + const get_change_log_diff = require('./scripts/get_changelog_diff.js') |
| 57 | + core.exportVariable('CHANGELOG', get_change_log_diff()) |
| 58 | +
|
| 59 | + - name: Open pull request |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + run: | |
| 63 | + gh pr create \ |
| 64 | + -t "Release ${{ github.event.inputs.version }}" \ |
| 65 | + -b "# :rocket: ${{ github.event.inputs.version }} |
| 66 | + Make sure to use squash & merge when merging! |
| 67 | + Once this is merged, another job will kick off automatically and publish the package. |
| 68 | + # :memo: Changelog |
| 69 | + ${{ env.CHANGELOG }}" |
0 commit comments