aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/draft-release.yml
blob: ecd678bb56847e03eed2f1e0cef6295bb52a1898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Draft Release

on:
  pull_request_target:
    types:
      - closed
    paths:
      - 'CHANGELOG.md'

permissions:
  contents: write # to create releases

jobs:
  draft_release:
    name: Draft Release
    if: >
      startsWith(github.event.pull_request.title, 'chore(release):')
      && github.event.pull_request.merged
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - name: Checkout
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          fetch-depth: 0 # we need the tags and the commit history for the gh release create command
          ref: ${{ github.event.pull_request.base.ref }}

      - name: Gather release information
        run: |
          RELEASE_VERSION=$(jq -r '.version' package.json)
          echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
          PREVIOUS_VERSION=$(git describe --tags --abbrev=0)
          echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV
          if [[ "$RELEASE_VERSION" == *"-"* ]]; then
            RELEASE_ARGS="--prerelease"
          else
            RELEASE_ARGS="--latest"
          fi
          echo "RELEASE_ARGS=$RELEASE_ARGS" >> $GITHUB_ENV

      - name: Create draft release
        run: |
          gh release create \
            v$RELEASE_VERSION \
            --draft \
            $RELEASE_ARGS \
            --generate-notes \
            --notes-start-tag $PREVIOUS_VERSION \
            --title v$RELEASE_VERSION
        env:
          GH_TOKEN: ${{ github.token }}