Skip to content

Commit 3bf2272

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

File tree

2 files changed

+70
-22
lines changed

2 files changed

+70
-22
lines changed

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ env:
2525
NODE_VERSION: lts/*
2626

2727
permissions:
28-
contents: write
28+
contents: read
2929

3030
jobs:
3131
releasePrepare:
@@ -39,9 +39,6 @@ jobs:
3939
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4040
with:
4141
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
4542

4643
# Install dependencies
4744
- name: Install Node.js
@@ -63,16 +60,15 @@ jobs:
6360
ncu-config set owner "${GITHUB_REPOSITORY_OWNER}"
6461
env:
6562
USERNAME: ${{ secrets.JENKINS_USER }}
66-
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
63+
GH_TOKEN: ${{ github.token }}
6764
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
6865

6966
- name: Set up ghauth config (Ubuntu)
7067
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
68+
jq '{user: env.USERNAME, token: env.TOKEN}' > "${XDG_CONFIG_HOME:-~/.config}/changelog-maker/config.json"
69+
env:
70+
USERNAME: ${{ secrets.JENKINS_USER }}
71+
TOKEN: ${{ github.token }}
7672

7773
- name: Setup git author
7874
run: |

tools/actions/create-release.sh

Lines changed: 64 additions & 12 deletions
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)