|
11 | 11 | ACTIONS_BOT_TOKEN: |
12 | 12 | required: true |
13 | 13 |
|
14 | | -env: |
15 | | - PR_BRANCH: 'actions/draft-release-${{ github.ref_name }}' |
16 | | - |
17 | 14 | jobs: |
18 | 15 | draft-release: |
19 | 16 | name: 'Draft Release' |
20 | 17 | runs-on: 'ubuntu-latest' |
21 | | - permissions: |
22 | | - contents: 'write' |
23 | 18 | steps: |
24 | 19 | - uses: 'actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11' # ratchet:actions/checkout@v4 |
25 | 20 |
|
26 | 21 | - uses: 'actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8' # ratchet:actions/setup-node@v4 |
27 | 22 | with: |
28 | 23 | node-version: '22.x' |
29 | 24 |
|
30 | | - - name: 'Build and push' |
| 25 | + - name: 'Build' |
| 26 | + id: 'build' |
31 | 27 | shell: 'bash' |
32 | 28 | env: |
33 | 29 | VERSION_STRATEGY: '${{ inputs.version_strategy }}' |
34 | 30 | run: |- |
35 | | - # configure username and email for git to show who made the changes |
36 | | - git config user.name "google-github-actions-bot" |
37 | | - git config user.email "github-actions-bot@google.com" |
38 | | -
|
39 | | - git checkout -b $PR_BRANCH |
40 | | -
|
41 | | - npm version $VERSION_STRATEGY --git-tag-version=false |
42 | | -
|
43 | | - NEW_VERSION=$(cat package.json | jq -r .version) |
44 | | - echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV |
| 31 | + CURRENT_VERSION="$(jq -r .version ./package.json)" |
| 32 | + echo "::debug::computed current version: ${CURRENT_VERSION}" |
| 33 | + echo "current_version=${CURRENT_VERSION}" >> $GITHUB_ENV |
| 34 | +
|
| 35 | + npm version "${VERSION_STRATEGY}" \ |
| 36 | + --no-git-tag-version \ |
| 37 | + --no-commit-hooks \ |
| 38 | + --no-workspaces-update |
| 39 | + NEXT_VERSION="$(jq -r .version ./package.json)" |
| 40 | + echo "::debug::computed next version: ${NEXT_VERSION}" |
| 41 | + echo "next_version=${NEXT_VERSION}" >> $GITHUB_ENV |
45 | 42 |
|
46 | 43 | npm ci |
47 | 44 | [[ "$(npm run --json | jq -r 'has("docs")')" == "true" ]] && npm run docs |
48 | 45 | npm run build |
49 | 46 |
|
50 | | - git add . |
51 | | - git commit -m "Release: v${NEW_VERSION}" |
52 | | - git push origin $PR_BRANCH --force |
53 | | -
|
54 | 47 | - name: 'Generate release notes' |
| 48 | + id: 'generate-release-notes' |
55 | 49 | uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7 |
| 50 | + env: |
| 51 | + CURRENT_VERSION: '${{ steps.build.outputs.current_version }}' |
| 52 | + NEXT_VERSION: '${{ steps.build.outputs.next_version }}' |
56 | 53 | with: |
| 54 | + github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}' |
57 | 55 | script: |- |
58 | | - let previousTagName = ""; |
59 | | -
|
| 56 | + let releaseNotes = ''; |
60 | 57 | try { |
61 | | - const latestRelease = await github.rest.repos.getLatestRelease({ |
| 58 | + const releaseNotesResponse = await github.rest.repos.generateReleaseNotes({ |
62 | 59 | owner: context.repo.owner, |
63 | 60 | repo: context.repo.repo, |
| 61 | + tag_name: `v${process.env.NEXT_VERSION}`, |
| 62 | + previous_tag_name: `v${process.env.CURRENT_VERSION}`, |
64 | 63 | }); |
65 | | - previousTagName = latestRelease.data.tag_name; |
66 | | - } catch (err) { |
67 | | - if (err["status"] !== 404) { |
68 | | - core.setFailed(`Failed to load latest release: ${err}`); |
69 | | - } |
70 | | -
|
71 | | - core.info(`No existing releases found`); |
| 64 | + releaseNotes = releaseNotesResponse.data.body; |
| 65 | + } catch(err) { |
| 66 | + core.warning('No existing releases found, assuming initial release'); |
| 67 | + releaseNotes = 'Initial release' |
72 | 68 | } |
| 69 | + core.setOutput('release_notes', releaseNotes) |
73 | 70 |
|
74 | | - try { |
75 | | - const releaseNotesRequest = { |
76 | | - owner: context.repo.owner, |
77 | | - repo: context.repo.repo, |
78 | | - tag_name: context.sha, |
79 | | - target_commitish: context.sha, |
80 | | - }; |
81 | | -
|
82 | | - if (previousTagName) { |
83 | | - releaseNotesRequest.previous_tag_name = previousTagName; |
84 | | - } |
85 | | -
|
86 | | - const releaseNotes = await github.rest.repos.generateReleaseNotes( |
87 | | - releaseNotesRequest |
88 | | - ); |
89 | | -
|
90 | | - core.exportVariable("RELEASE_NOTES", releaseNotes.data.body) |
91 | | - } catch (err) { |
92 | | - core.setFailed(`Failed to generate release notes: ${err}`); |
93 | | - } |
| 71 | + # TODO(sethvargo): remove |
| 72 | + - name: 'debug' |
| 73 | + run: |- |
| 74 | + echo "::notice::${{ toJSON(github) }}" |
94 | 75 |
|
95 | | - - name: 'Create Pull Request' |
96 | | - uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7 |
| 76 | + - name: 'Create/Update Pull Request' |
| 77 | + uses: 'abcxyz/pkg/.github/actions/create-pull-request@main' # ratchet:exclude |
97 | 78 | with: |
98 | | - github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}' |
99 | | - script: |- |
100 | | - const tag = "v" + process.env.NEW_VERSION; |
101 | | -
|
102 | | - try { |
103 | | - const listResponse = await github.rest.pulls.list({ |
104 | | - owner: context.repo.owner, |
105 | | - repo: context.repo.repo, |
106 | | - state: "open", |
107 | | - head: context.repo.owner + ":" + process.env.PR_BRANCH, |
108 | | - base: process.env.GITHUB_REF_NAME, |
109 | | - }); |
110 | | -
|
111 | | - core.isDebug() && console.log(listResponse); |
112 | | -
|
113 | | - if (!listResponse.data.length) { |
114 | | - const createResponse = await github.rest.pulls.create({ |
115 | | - owner: context.repo.owner, |
116 | | - repo: context.repo.repo, |
117 | | - title: "Release: " + tag, |
118 | | - body: process.env.RELEASE_NOTES, |
119 | | - head: process.env.PR_BRANCH, |
120 | | - base: process.env.GITHUB_REF_NAME, |
121 | | - }); |
122 | | -
|
123 | | - core.info( |
124 | | - `Created PR #${createResponse.data.number} at ${createResponse.data.html_url}` |
125 | | - ); |
126 | | - } else { |
127 | | - const updateResponse = await github.rest.pulls.update({ |
128 | | - owner: context.repo.owner, |
129 | | - repo: context.repo.repo, |
130 | | - pull_number: listResponse.data[0].number, |
131 | | - title: "Release: " + tag, |
132 | | - body: process.env.RELEASE_NOTES, |
133 | | - }); |
134 | | -
|
135 | | - core.info( |
136 | | - `Updated PR #${updateResponse.data.number} at ${updateResponse.data.html_url}` |
137 | | - ); |
138 | | - } |
139 | | - } catch (err) { |
140 | | - console.error(err); |
141 | | - core.setFailed(`Failed to create pull request: ${err}`); |
142 | | - } |
| 79 | + token: '${{ secrets.ACTIONS_BOT_TOKEN }}' |
| 80 | + base_branch: '${{ github.event.repository.default_branch }}' # TODO: pull from trigger branch instead (for release builds) |
| 81 | + head_branch: 'actions/draft-release-${{ github.ref_name }}' |
| 82 | + title: 'Release: v${{ steps.build.outputs.next_version }}' |
| 83 | + body: '${{ steps.generate-release-notes.outputs.release_notes }}' |
| 84 | + compute_paths: true |
0 commit comments