Skip to content

Commit 9d89f30

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

File tree

2 files changed

+72
-25
lines changed

2 files changed

+72
-25
lines changed

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

+8-13
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,6 @@ 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
4541

4642
# Install dependencies
4743
- name: Install Node.js
@@ -58,21 +54,20 @@ jobs:
5854
ncu-config set upstream origin
5955
ncu-config set username "$USERNAME"
6056
ncu-config set token "$GH_TOKEN"
61-
ncu-config set jenkins_token "$JENKINS_TOKEN"
6257
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
6358
ncu-config set owner "${GITHUB_REPOSITORY_OWNER}"
6459
env:
6560
USERNAME: ${{ secrets.JENKINS_USER }}
66-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
67-
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
61+
GH_TOKEN: ${{ github.token }}
6862

6963
- name: Set up ghauth config (Ubuntu)
7064
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
65+
mkdir -p "${XDG_CONFIG_HOME:-~/.config}/changelog-maker"
66+
jq '{user: env.USERNAME, token: env.TOKEN}' > "${XDG_CONFIG_HOME:-~/.config}/changelog-maker/config.json"
67+
cat "${XDG_CONFIG_HOME:-~/.config}/changelog-maker/config.json"
68+
env:
69+
USERNAME: ${{ secrets.JENKINS_USER }}
70+
TOKEN: token
7671

7772
- name: Setup git author
7873
run: |

tools/actions/create-release.sh

+64-12
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,76 @@ if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
1010
exit 1
1111
fi
1212

13+
buildMutationQuery() {
14+
cat - <<'EOF'
15+
mutation ($repo: String! $branch: String!, $parent: GitObjectID!, $commit_title: String!, $commit_body: String) {
16+
createCommitOnBranch(input: {
17+
branch: {
18+
repositoryNameWithOwner: $repo,
19+
branchName: $branch
20+
},
21+
message: {
22+
headline: $commit_title,
23+
body: $commit_body
24+
},
25+
expectedHeadOid: $parent,
26+
fileChanges: {
27+
additions: [
28+
EOF
29+
git show HEAD --diff-filter=d --name-only --format= | while read -r FILE; do
30+
echo "{ path: $(
31+
node -p 'JSON.stringify(process.argv[1])' "$FILE"
32+
), contents: $(
33+
node -p 'JSON.stringify(fs.readFileSync(process.argv[1]).toString("base64"))' "$FILE"
34+
) },"
35+
done
36+
echo '], deletions: ['
37+
git show HEAD --diff-filter=D --name-only --format= | while read -r FILE; do
38+
echo "$(node -p 'JSON.stringify(process.argv[1])' "$FILE"),"
39+
done
40+
cat - <<'EOF'
41+
]
42+
}}) {
43+
commit {
44+
url
45+
}
46+
}
47+
}
48+
EOF
49+
}
50+
51+
1352
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
53+
54+
HEAD="$(git rev-parse --abbrev-ref HEAD)"
1855

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

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

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|")"
61+
# Create the proposal branch
62+
gh api \
63+
--method POST \
64+
-H "Accept: application/vnd.github+json" \
65+
-H "X-GitHub-Api-Version: 2022-11-28" \
66+
"/repos/${GITHUB_REPOSITORY}/git/refs" \
67+
-f "ref=refs/heads/$HEAD" -f "sha=$(git rev-parse HEAD^)"
2868

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

32-
# Force-push the amended commit
33-
git push --force
78+
# Push the release commit to the proposal branch
79+
gh api graphql \
80+
-F repo="$GITHUB_REPOSITORY" \
81+
-F branch="$HEAD" \
82+
-F parent="$(git rev-parse HEAD^)" \
83+
-F commit_title="$(git log -1 HEAD --format=%s)" \
84+
-F commit_body="$(git log -1 HEAD --format=%b | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")" \
85+
-f query="$(buildMutationQuery)"

0 commit comments

Comments
 (0)