Skip to content

Commit 0333607

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

File tree

2 files changed

+96
-25
lines changed

2 files changed

+96
-25
lines changed

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

Lines changed: 17 additions & 13 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,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,29 +54,37 @@ 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+
echo '{}' | jq '{user: env.USERNAME, token: env.TOKEN}' > "${XDG_CONFIG_HOME:-~/.config}/changelog-maker/config.json"
67+
env:
68+
USERNAME: ${{ secrets.JENKINS_USER }}
69+
TOKEN: ${{ github.token }}
7670

7771
- name: Setup git author
7872
run: |
7973
git config --local user.email "[email protected]"
8074
git config --local user.name "Node.js GitHub Bot"
75+
# Workaround, see https://github.com/nodejs/node-core-utils/pull/876
76+
git fetch origin --shallow-exclude v23.3.0 v23.x-staging
77+
git fetch origin --deepen=1 v23.x-staging
8178
8279
- name: Start git node release prepare
80+
# The curl command is to make sure we run the version of the script corresponding to the current workflow.
8381
run: |
82+
curl -L https://github.com/${GITHUB_REPOSITORY}/raw/${GITHUB_SHA}/tools/actions/create-release.sh > tools/actions/create-release.sh
8483
./tools/actions/create-release.sh "${RELEASE_DATE}" "${RELEASE_LINE}"
8584
env:
8685
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
86+
87+
- uses: actions/upload-artifact@v4
88+
with:
89+
name: query.gql
90+
path: query.gql

tools/actions/create-release.sh

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

13+
buildMutationQuery() {
14+
repo=$1
15+
branch=$2
16+
commit="${3:-HEAD}"
17+
commit_title="${4:-$(git log -1 "$commit" --format=%s)}"
18+
commit_body="${5:-$(git log -1 "$commit" --format=%b)}"
19+
cat - <<'EOF'
20+
mutation ($repo: String! $branch: String!, $parent: GitObjectID!, $commit_title: String!, $commit_body: String) {
21+
createCommitOnBranch(input: {
22+
branch: {
23+
repositoryNameWithOwner: $repo,
24+
branchName: $branch
25+
},
26+
message: {
27+
headline: $commit_title,
28+
body: $commit_body
29+
},
30+
expectedHeadOid: $parent,
31+
fileChanges: {
32+
additions: [
33+
EOF
34+
git show "$commit" --diff-filter=d --name-only --format= | while read -r FILE; do
35+
echo "{ path: "
36+
node -p 'JSON.stringify(process.argv[1])' "$FILE"
37+
printf ", contents: \""
38+
base64 -b 0 -i "$FILE"
39+
echo "\"},"
40+
done
41+
echo '], deletions: ['
42+
git show "$commit" --diff-filter=D --name-only --format= | while read -r FILE; do
43+
echo "$(node -p 'JSON.stringify(process.argv[1])' "$FILE"),"
44+
done
45+
cat - <<'EOF'
46+
]
47+
}}) {
48+
commit {
49+
url
50+
}
51+
}
52+
}
53+
EOF
54+
node -p '"variables " + JSON.stringify({
55+
repo: process.argv[1],
56+
branch: process.argv[2],
57+
parent: process.argv[3],
58+
commit_title: process.argv[4],
59+
commit_body: process.argv[5]
60+
}, undefined, 2)' "$repo" "$branch" "$(git rev-parse "${commit}^")" "$commit_title" "${commit_body}"
61+
}
62+
63+
echo "No exit"
64+
1365
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
66+
67+
HEAD_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
1868

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

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

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|")"
74+
# Create the proposal branch
75+
# gh api \
76+
# --method POST \
77+
# -H "Accept: application/vnd.github+json" \
78+
# -H "X-GitHub-Api-Version: 2022-11-28" \
79+
# "/repos/${GITHUB_REPOSITORY}/git/refs" \
80+
# -f "ref=refs/heads/$HEAD_BRANCH" -f "sha=$(git rev-parse HEAD^)"
2881

29-
# Replace "TODO" with the PR URL in the last commit
30-
git commit --amend --no-edit -m "$AMENDED_COMMIT_MSG" || true
82+
# Create the proposal PR
83+
# PR_URL="$(gh api \
84+
# --method POST \
85+
# --jq .html_url \
86+
# -H "Accept: application/vnd.github+json" \
87+
# -H "X-GitHub-Api-Version: 2022-11-28" \
88+
# "/repos/${GITHUB_REPOSITORY}/pulls" \
89+
# -f "title=$TITLE" -f "body=$TEMP_BODY" -f "head=$HEAD_BRANCH" -f "base=v$RELEASE_LINE.x")"
3190

32-
# Force-push the amended commit
33-
git push --force
91+
# Push the release commit to the proposal branch
92+
buildMutationQuery \
93+
"$GITHUB_REPOSITORY" \
94+
"$HEAD_BRANCH" \
95+
HEAD \
96+
"$(git log -1 HEAD --format=%s)" \
97+
"$(git log -1 HEAD --format=%b | sed "s|PR-URL: TODO|PR-URL: $PR_URL|")" \
98+
> query.gql
99+
# | node --input-type=module -e 'console.log(JSON.stringify({ query: Buffer.concat(await process.stdin.toArray()).toString() }))' \
100+
# | curl -fS -H "Authorization: bearer ${GH_TOKEN}" -X POST --data @- https://api.github.com/graphql

0 commit comments

Comments
 (0)