Skip to content

Commit a879368

Browse files
committed
tools: update create-release-proposal workflow
1 parent 853b304 commit a879368

File tree

3 files changed

+100
-28
lines changed

3 files changed

+100
-28
lines changed

.github/workflows/create-release-proposal.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# This action requires the following secrets to be set on the repository:
22
# GH_USER_NAME: GitHub user whose Jenkins and GitHub token are defined below
33
# GH_USER_TOKEN: GitHub user token, to be used by ncu and to push changes
4-
# JENKINS_TOKEN: Jenkins token, to be used to check CI status
54

65
name: Create Release Proposal
76

@@ -25,7 +24,7 @@ env:
2524
NODE_VERSION: lts/*
2625

2726
permissions:
28-
contents: write
27+
contents: read
2928

3029
jobs:
3130
releasePrepare:
@@ -39,9 +38,7 @@ jobs:
3938
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4039
with:
4140
ref: ${{ env.STAGING_BRANCH }}
42-
# Needs the whole git history for ncu to work
43-
# See https://github.com/nodejs/node-core-utils/pull/486
44-
fetch-depth: 0
41+
persist-credentials: false
4542

4643
# Install dependencies
4744
- name: Install Node.js
@@ -58,29 +55,33 @@ jobs:
5855
ncu-config set upstream origin
5956
ncu-config set username "$USERNAME"
6057
ncu-config set token "$GH_TOKEN"
61-
ncu-config set jenkins_token "$JENKINS_TOKEN"
6258
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
6359
ncu-config set owner "${GITHUB_REPOSITORY_OWNER}"
6460
env:
6561
USERNAME: ${{ secrets.JENKINS_USER }}
66-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
67-
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
62+
GH_TOKEN: ${{ github.token }}
6863

6964
- name: Set up ghauth config (Ubuntu)
7065
run: |
71-
mkdir -p ~/.config/changelog-maker/
72-
echo '{
73-
"user": "'$(ncu-config get username)'",
74-
"token": "'$(ncu-config get token)'"
75-
}' > ~/.config/changelog-maker/config.json
66+
mkdir -p "${XDG_CONFIG_HOME:-~/.config}/changelog-maker"
67+
echo '{}' | jq '{user: env.USERNAME, token: env.TOKEN}' > "${XDG_CONFIG_HOME:-~/.config}/changelog-maker/config.json"
68+
env:
69+
USERNAME: ${{ secrets.JENKINS_USER }}
70+
TOKEN: ${{ github.token }}
7671

7772
- name: Setup git author
7873
run: |
7974
git config --local user.email "[email protected]"
8075
git config --local user.name "Node.js GitHub Bot"
76+
# Workaround, see https://github.com/nodejs/node-core-utils/pull/876
77+
git fetch origin --shallow-exclude v23.3.0 v23.x-staging
78+
git fetch origin --deepen=1 v23.x-staging
8179
8280
- name: Start git node release prepare
81+
# The curl command is to make sure we run the version of the script corresponding to the current workflow.
8382
run: |
83+
curl -L https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/create-release.sh > tools/actions/create-release.sh
8484
./tools/actions/create-release.sh "${RELEASE_DATE}" "${RELEASE_LINE}"
8585
env:
86-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
86+
GH_TOKEN: ${{ github.token }}
87+
BOT_TOKEN: ${{ secrets.GH_USER_TOKEN }}

doc/contributing/releases.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ official release builds for Node.js, hosted on <https://nodejs.org/>.
3333
* [17. Create a blog post](#17-create-a-blog-post)
3434
* [18. Create the release on GitHub](#18-create-the-release-on-github)
3535
* [19. Announce](#19-announce)
36-
* [20. Celebrate](#20-celebrate)
36+
* [20. Re-enable the backport-queue workflow](#20-re-enable-the-backport-queue-workflow)
37+
* [21. Celebrate](#21-celebrate)
3738
* [LTS releases](#lts-releases)
3839
* [Major releases](#major-releases)
3940

@@ -140,6 +141,11 @@ of the `nodejs-private/node-private` repository a day or so before the
140141
[CI lockdown procedure][] begins. This is to confirm that Jenkins can properly
141142
access the private repository.
142143

144+
### 1. Disable the backport-queue workflow
145+
146+
Having the staging branch and the proposal branch starting to differ will make
147+
the release work harder.
148+
143149
### 1. Update the staging branch
144150

145151
Checkout the staging branch locally.
@@ -1096,7 +1102,9 @@ Let the security release steward know the releases are available.
10961102

10971103
</details>
10981104

1099-
### 20. Celebrate
1105+
### 20. Re-enable the backport-queue workflow
1106+
1107+
### 21. Celebrate
11001108

11011109
_In whatever form you do this..._
11021110

tools/actions/create-release.sh

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,87 @@ if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
1010
exit 1
1111
fi
1212

13+
createCommitAPICall() {
14+
commit="${1:-HEAD}"
15+
cat - <<'EOF'
16+
mutation ($repo: String! $branch: String!, $parent: GitObjectID!, $commit_title: String!, $commit_body: String) {
17+
createCommitOnBranch(input: {
18+
branch: {
19+
repositoryNameWithOwner: $repo,
20+
branchName: $branch
21+
},
22+
message: {
23+
headline: $commit_title,
24+
body: $commit_body
25+
},
26+
expectedHeadOid: $parent,
27+
fileChanges: {
28+
additions: [
29+
EOF
30+
git show "$commit" --diff-filter=d --name-only --format= | while read -r FILE; do
31+
printf " { path: "
32+
node -p 'JSON.stringify(process.argv[1])' "$FILE"
33+
printf " , contents: \""
34+
base64 -w 0 -i "$FILE"
35+
echo "\"},"
36+
done
37+
echo ' ], deletions: ['
38+
git show "$commit" --diff-filter=D --name-only --format= | while read -r FILE; do
39+
echo " $(node -p 'JSON.stringify(process.argv[1])' "$FILE"),"
40+
done
41+
cat - <<'EOF'
42+
]
43+
}
44+
}) {
45+
commit {
46+
url
47+
}
48+
}
49+
}
50+
EOF
51+
}
52+
1353
git node release --prepare --skipBranchDiff --yes --releaseDate "$RELEASE_DATE"
14-
# We use it to not specify the branch name as it changes based on
15-
# the commit list (semver-minor/semver-patch)
16-
git config push.default current
17-
git push
54+
55+
HEAD_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
56+
HEAD_SHA="$(git rev-parse HEAD^)"
1857

1958
TITLE=$(awk "/^## ${RELEASE_DATE}/ { print substr(\$0, 4) }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md")
2059

2160
# Use a temporary file for the PR body
2261
TEMP_BODY="$(awk "/## ${RELEASE_DATE}/,/^<a id=/{ if (!/^<a id=/) print }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md")"
2362

24-
PR_URL="$(gh pr create --title "$TITLE" --body "$TEMP_BODY" --base "v$RELEASE_LINE.x")"
25-
26-
# Amend commit message so it contains the correct PR-URL trailer.
27-
AMENDED_COMMIT_MSG="$(git log -1 --pretty=%B | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")"
63+
# Create the proposal branch
64+
gh api \
65+
--method POST \
66+
-H "Accept: application/vnd.github+json" \
67+
-H "X-GitHub-Api-Version: 2022-11-28" \
68+
"/repos/${GITHUB_REPOSITORY}/git/refs" \
69+
-f "ref=refs/heads/$HEAD_BRANCH" -f "sha=$HEAD_SHA"
2870

29-
# Replace "TODO" with the PR URL in the last commit
30-
git commit --amend --no-edit -m "$AMENDED_COMMIT_MSG" || true
71+
# Create the proposal PR
72+
PR_URL="$(gh api \
73+
--method POST \
74+
--jq .html_url \
75+
-H "Accept: application/vnd.github+json" \
76+
-H "X-GitHub-Api-Version: 2022-11-28" \
77+
"/repos/${GITHUB_REPOSITORY}/pulls" \
78+
-f "title=$TITLE" -f "body=$TEMP_BODY" -f "head=$HEAD_BRANCH" -f "base=v$RELEASE_LINE.x")"
3179

32-
# Force-push the amended commit
33-
git push --force
80+
# Push the release commit to the proposal branch
81+
createCommitAPICall | node --input-type=module -e 'console.log(JSON.stringify({
82+
query: Buffer.concat(await process.stdin.toArray()).toString(),
83+
variables: {
84+
repo: process.argv[1],
85+
branch: process.argv[2],
86+
parent: process.argv[3],
87+
commit_title: process.argv[4],
88+
commit_body: process.argv[5]
89+
}
90+
}))' \
91+
"$GITHUB_REPOSITORY" \
92+
"$HEAD_BRANCH" \
93+
"$HEAD_SHA" \
94+
"$(git log -1 HEAD --format=%s)" \
95+
"$(git log -1 HEAD --format=%b | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")" \
96+
| curl -fS -H "Authorization: bearer ${BOT_TOKEN}" -X POST --data @- https://api.github.com/graphql

0 commit comments

Comments
 (0)