Skip to content

Commit 7898bc2

Browse files
committed
add pr check for node version consistency
1 parent 6b5b958 commit 7898bc2

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

.github/update-release-branch.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,13 @@ def main():
255255
print(f'No commits to merge from {source_branch} to {target_branch}.')
256256
return
257257

258+
# define distinct prefix in order to support specific pr checks on backports
259+
branch_prefix = 'update' if is_primary_release else 'backport'
260+
258261
# The branch name is based off of the name of branch being merged into
259262
# and the SHA of the branch being merged from. Thus if the branch already
260263
# exists we can assume we don't need to recreate it.
261-
new_branch_name = f'update-v{version}-{source_branch_short_sha}'
264+
new_branch_name = f'{branch_prefix}-v{version}-{source_branch_short_sha}'
262265
print(f'Branch name is {new_branch_name}.')
263266

264267
# Check if the branch already exists. If so we can abort as this script

.github/workflows/pr-checks.yml

+41
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,44 @@ jobs:
114114
# we won't be able to find them on Windows.
115115
npm config set script-shell bash
116116
npm test
117+
118+
check-node-version:
119+
if: ${{ github.event.pull_request }}
120+
name: Check node version consistency
121+
runs-on: ubuntu-latest
122+
timeout-minutes: 45
123+
env:
124+
BASE_REF: ${{ github.base_ref }}
125+
126+
steps:
127+
- uses: actions/checkout@v4
128+
- id: head-version
129+
name: check HEAD node version
130+
run: |
131+
NODE_VERSION=$(find . -name "action.yml" -exec yq -e '.runs.using' {} \; | grep node | sort | uniq)
132+
echo "NODE_VERSION: ${NODE_VERSION}"
133+
if [[ $(echo "$NODE_VERSION" | wc -l) -gt 1 ]]; then
134+
echo "Error: More than one node version used in actions."
135+
exit 1
136+
fi
137+
echo "node_version=${NODE_VERSION}" >> $GITHUB_OUTPUT
138+
139+
- id: checkout-base
140+
name: check out base ref for backport check
141+
if: ${{ startsWith(github.head_ref, 'backport-') }}
142+
uses: actions/checkout@v4
143+
with:
144+
ref: ${{ env.BASE_REF }}
145+
146+
- name: compare with node version on base ref for backport check
147+
if: steps.checkout-base.outcome == 'success'
148+
env:
149+
HEAD_VERSION: ${{ steps.head-version.outputs.node_version }}
150+
run: |
151+
BASE_VERSION=$(find . -name "action.yml" -exec yq -e '.runs.using' {} \; | grep node | sort | uniq)
152+
echo "HEAD_VERSION: ${HEAD_VERSION}"
153+
echo "BASE_VERSION: ${BASE_VERSION}"
154+
if [[ "$BASE_VERSION" != "$HEAD_VERSION" ]]; then
155+
echo "Error: Cannot change node version in a backport PR."
156+
exit 1
157+
fi

0 commit comments

Comments
 (0)