Skip to content

Commit 2023b09

Browse files
RafaelGSSaduh95
authored andcommitted
build: add create release proposal action
PR-URL: #55690 Refs: nodejs/security-wg#860 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 1e0decb commit 2023b09

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# This action requires the following secrets to be set on the repository:
2+
# GH_USER_NAME: GitHub user whose Jenkins and GitHub token are defined below
3+
# 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
5+
6+
name: Create Release Proposal
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
release-line:
12+
required: true
13+
type: number
14+
default: 23
15+
description: 'The release line (without dots or prefix). e.g: 22'
16+
release-date:
17+
required: true
18+
type: string
19+
default: YYYY-MM-DD
20+
description: The release date in YYYY-MM-DD format
21+
22+
concurrency: ${{ github.workflow }}
23+
24+
env:
25+
NODE_VERSION: lts/*
26+
27+
permissions:
28+
contents: write
29+
30+
jobs:
31+
releasePrepare:
32+
env:
33+
STAGING_BRANCH: v${{ inputs.release-line }}.x-staging
34+
RELEASE_BRANCH: v${{ inputs.release-line }}.x
35+
RELEASE_DATE: ${{ inputs.release-date }}
36+
RELEASE_LINE: ${{ inputs.release-line }}
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
40+
with:
41+
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
45+
46+
# Install dependencies
47+
- name: Install Node.js
48+
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
49+
with:
50+
node-version: ${{ env.NODE_VERSION }}
51+
52+
- name: Install @node-core/utils
53+
run: npm install -g @node-core/utils
54+
55+
- name: Configure @node-core/utils
56+
run: |
57+
ncu-config set branch "${RELEASE_BRANCH}"
58+
ncu-config set upstream origin
59+
ncu-config set username "$USERNAME"
60+
ncu-config set token "$GH_TOKEN"
61+
ncu-config set jenkins_token "$JENKINS_TOKEN"
62+
ncu-config set repo "$(echo "$GITHUB_REPOSITORY" | cut -d/ -f2)"
63+
ncu-config set owner "${GITHUB_REPOSITORY_OWNER}"
64+
env:
65+
USERNAME: ${{ secrets.JENKINS_USER }}
66+
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}
67+
JENKINS_TOKEN: ${{ secrets.JENKINS_TOKEN }}
68+
69+
- name: Set up ghauth config (Ubuntu)
70+
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
76+
77+
- name: Setup git author
78+
run: |
79+
git config --local user.email "[email protected]"
80+
git config --local user.name "Node.js GitHub Bot"
81+
82+
- name: Start git node release prepare
83+
run: |
84+
./tools/actions/create-release.sh "${RELEASE_DATE}" "${RELEASE_LINE}"
85+
env:
86+
GH_TOKEN: ${{ secrets.GH_USER_TOKEN }}

tools/actions/create-release.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
set -xe
4+
5+
RELEASE_DATE=$1
6+
RELEASE_LINE=$2
7+
8+
if [ -z "$RELEASE_DATE" ] || [ -z "$RELEASE_LINE" ]; then
9+
echo "Usage: $0 <RELEASE_DATE> <RELEASE_LINE>"
10+
exit 1
11+
fi
12+
13+
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
18+
19+
TITLE=$(awk "/^## ${RELEASE_DATE}/ { print substr(\$0, 4) }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md")
20+
21+
# Use a temporary file for the PR body
22+
TEMP_BODY="$(awk "/## ${RELEASE_DATE}/,/^<a id=/{ if (!/^<a id=/) print }" "doc/changelogs/CHANGELOG_V${RELEASE_LINE}.md")"
23+
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|")"
28+
29+
# Replace "TODO" with the PR URL in the last commit
30+
git commit --amend --no-edit -m "$AMENDED_COMMIT_MSG" || true
31+
32+
# Force-push the amended commit
33+
git push --force

0 commit comments

Comments
 (0)