Skip to content

Commit 50054d8

Browse files
authored
Add more checks for the release commit (#9792)
Check that it's on the corresponding release branch in case of tag, or is targeted there in case of PR.
1 parent ab529af commit 50054d8

1 file changed

Lines changed: 125 additions & 14 deletions

File tree

.github/workflows/prerelease-sanity.yaml

Lines changed: 125 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,167 @@ name: Prerelease Sanity
33
push:
44
branches:
55
- prerelease_test
6+
- trigger/prerelease-sanity
7+
- "?.*.x"
8+
69
pull_request:
7-
branches: "?.*.x"
8-
paths:
9-
- version.config
10-
- .github/workflows/prerelease-sanity.yaml
10+
1111
workflow_dispatch:
1212

1313
jobs:
14+
# We need two disjoint conditions for pull requests that are combined with OR,
15+
# and it is impossible to set up through the "on" key, so check that in a
16+
# separate step below.
17+
config:
18+
name: Check the configuration
19+
runs-on: timescaledb-runner-arm64
20+
outputs:
21+
should_run: ${{ steps.check.outputs.should_run }}
22+
steps:
23+
- name: Checkout TimescaleDB
24+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25+
26+
- name: Check the configuration
27+
id: check
28+
run: |
29+
set -xeu
30+
31+
if [[ "${{ github.event_name }}" == "pull_request" ]]
32+
then
33+
base="${{ github.event.pull_request.base.sha }}"
34+
git fetch origin "${base}"
35+
36+
# PR that modifies the workflow.
37+
if ! git diff "${base}" --name-only --exit-code -- .github/workflows/prerelease-sanity.yaml
38+
then
39+
echo "should_run=true" >> "${GITHUB_OUTPUT}"
40+
exit 0
41+
fi
42+
43+
# PR into a release branch that modifies the version.
44+
if [[ "${{ github.event.pull_request.base.ref }}" == ?.*.x ]] \
45+
&& ! git diff "${base}" --name-only --exit-code -- version.config
46+
then
47+
echo "should_run=true" >> "${GITHUB_OUTPUT}"
48+
exit 0
49+
fi
50+
51+
# Don't run on other PRs.
52+
echo "should_run=false" >> "${GITHUB_OUTPUT}"
53+
exit 0
54+
fi
55+
56+
# No additional filtering for other event types.
57+
echo "should_run=true" >> "${GITHUB_OUTPUT}"
58+
1459
check_release_commit:
1560
name: Check Release Commit
61+
needs: config
62+
if: needs.config.outputs.should_run == 'true'
1663
runs-on: timescaledb-runner-arm64
1764

1865
steps:
1966
- name: Checkout TimescaleDB
2067
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21-
# GitHub creates an empty merge commit even for fast-fordward merges, which
68+
# GitHub creates an empty merge commit even for fast-forward merges, which
2269
# makes it needlessly difficult to inspect the actual commit title. Since
2370
# we require the PRs to release branches to be up to date before merging,
2471
# we can just work with the PR head here.
2572
with:
26-
ref: ${{ github.event.pull_request.head.sha }}
27-
fetch-depth: 2
73+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
74+
fetch-depth: 0
2875

2976
# The combined changelog must reference all changes, and the respective
3077
# change files in the .unreleased folder must be deleted.
3178
- name: No .unreleased files are left behind
3279
run: |
33-
! compgen -G .unreleased/*
80+
! compgen -G '.unreleased/*'
3481
3582
# The messages of the release commit and tag must start with Release <version>.
3683
# If this is the release tag, it must point to the release commit
3784
# and not something else.
3885
- name: The release commit message references the respective version
3986
run: |
4087
required_title=$(sed -n "s/^version = /Release /p" version.config)
41-
echo $required_title
88+
echo "Required title: $required_title"
4289
4390
tag_title=$(git log --oneline -1 --pretty=format:%s)
44-
echo $tag_title
91+
echo "Tag title: $tag_title"
4592
grep "$required_title" <<<"$tag_title"
4693
4794
# Our reference might be a tag, so check the pointed-to commit as well,
4895
# using the ^0 git path specification to find it.
4996
commit_title=$(git log --oneline -1 --pretty=format:%s @^0)
50-
echo $commit_title
97+
echo "Commit title: $commit_title"
5198
grep "$required_title" <<<"$commit_title"
5299
53100
# The release commit must modify the version.config
54-
- name: The release commit modifies the version.config
101+
- name: The release commit must modify the version.config
55102
run: |
103+
set -xeu
104+
105+
if [[ "${{ github.event_name }}" == "pull_request" ]]
106+
then
107+
git remote set-branches origin '*'
108+
git fetch origin "${{ github.event.pull_request.base.ref }}"
109+
110+
# We're working with pull request head here, see the comment
111+
# at checkout step.
112+
base="$(git merge-base "${{ github.event.pull_request.base.sha }}" @)"
113+
else
114+
base="${{ github.sha }}~"
115+
fi
116+
56117
git log --oneline -1 @^0
57-
git log --oneline -1 @^0~
58-
! git diff --exit-code @^0~ @^0 -- version.config
118+
git log --oneline -1 "${base}"
119+
! git diff --exit-code "${base}" @^0 -- version.config
120+
121+
# The SQL upgrade scripts must be moved from the development files to
122+
# the respective versioned files.
123+
- name: The latest-dev.sql and the reverse-dev.sql must be empty
124+
run: |
125+
if [ -s sql/updates/latest-dev.sql ]
126+
then
127+
echo "latest-dev.sql is not empty"
128+
exit 1
129+
fi
130+
131+
if [ -s sql/updates/reverse-dev.sql ]
132+
then
133+
echo "reverse-dev.sql is not empty"
134+
exit 1
135+
fi
136+
137+
- name: The release commit must not use the -dev versions
138+
run: |
139+
! grep 'version = .*-dev$' version.config
140+
141+
- name: The tagged release commit must belong to the corresponding release branch
142+
if: github.event_name == 'push'
143+
run: |
144+
set -xeu
145+
146+
version=$(sed -n "s/^version = //p" version.config)
147+
echo "Version ${version}"
148+
149+
branch=$(echo "${version}" | sed 's/\([0-9]\+\.[0-9]\+\.\).*/\1x/')
150+
echo "Expected branch ${branch}"
151+
152+
git remote set-branches origin '*'
153+
git fetch origin "${branch}"
154+
155+
git branch --contains @ | grep -Fx "${branch}"
156+
157+
- name: The release PR must target the corresponding release branch
158+
if: github.event_name == 'pull_request'
159+
run: |
160+
set -xeu
161+
162+
version=$(sed -n "s/^version = //p" version.config)
163+
echo "Version ${version}"
164+
165+
branch=$(echo "${version}" | sed 's/\([0-9]\+\.[0-9]\+\.\).*/\1x/')
166+
echo "Expected branch ${branch}"
167+
168+
echo "PR base: ${{ github.event.pull_request.base.ref }}"
169+
[[ "${{ github.event.pull_request.base.ref }}" == "${branch}" ]]

0 commit comments

Comments
 (0)