@@ -10,24 +10,87 @@ if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
1010 exit 1
1111fi
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+
1353git 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
1958TITLE=$( awk " /^## ${RELEASE_DATE} / { print substr(\$ 0, 4) }" " doc/changelogs/CHANGELOG_V${RELEASE_LINE} .md" )
2059
2160# Use a temporary file for the PR body
2261TEMP_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