-
Notifications
You must be signed in to change notification settings - Fork 1.1k
151 lines (127 loc) · 7.41 KB
/
Copy pathloader_check.yml
File metadata and controls
151 lines (127 loc) · 7.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Check for loader changes
"on":
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled, edited]
jobs:
check_loader_change:
name: Check for loader changes
# Ignore loader changes if acknowledged already
if: ${{ !contains(github.event.pull_request.labels.*.name, 'upgrade-requires-restart') }}
runs-on: timescaledb-runner-arm64
steps:
- name: Checkout source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Check if the pull request changes the loader
shell: bash --norc --noprofile {0}
env:
BODY: ${{ github.event.pull_request.body }}
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if ! echo "$BODY" | grep -Eqsi '^disable-check:.*\<loader-change\>'; then
# Get the list of modified files in this pull request
files=$(gh pr view $PR_NUMBER --json files --jq '.files.[].path')
# Check for loader changes
if echo "${files}" | grep -Eq "^src/loader/.+$"; then
echo "Warning: This PR changes the loader. Therefore, upgrading to the next TimescaleDB"
echo "version requires a restart of PostgreSQL. Make sure to bump the loader version if"
echo "necessary and coordinate the release with the cloud team before merging."
echo
echo "After the release is coordinated, add the 'upgrade-requires-restart' label"
echo "to the PR to acknowledge this warning."
echo
echo "To disable this check, add this trailer to pull request message:"
echo
echo "Disable-check: loader-change"
echo
exit 1
fi
fi
check_loader_version_bump:
name: Check if loader versions are incremented for required restart
# If the label is present, validate the loader version is bumped
if: ${{ contains(github.event.pull_request.labels.*.name, 'upgrade-requires-restart') }}
runs-on: timescaledb-runner-arm64
steps:
- name: Checkout source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Checkout ${{ github.event.pull_request.base.ref }} branch
run: git checkout ${{ github.event.pull_request.base.ref }}
- name: Extract versions from ${{ github.event.pull_request.base.ref }} branch
id: upstream-versions
run: |
# Extract version from bgw_interface.c
BGW_VERSION_MAIN=$(grep -oP 'const int32 ts_bgw_loader_api_version = \K\d+' src/loader/bgw_interface.c || echo "0")
echo "bgw_version_main=$BGW_VERSION_MAIN" >> $GITHUB_OUTPUT
# Extract version from launcher_interface.c
LAUNCHER_VERSION_MAIN=$(grep -oP '#define MIN_LOADER_API_VERSION \K\d+' src/bgw/launcher_interface.c || echo "0")
echo "launcher_version_main=$LAUNCHER_VERSION_MAIN" >> $GITHUB_OUTPUT
echo "${{ github.event.pull_request.base.ref }} branch:"
echo "src/loader/bgw_interface.c:const int32 ts_bgw_loader_api_version = $BGW_VERSION_MAIN"
echo "src/bgw/launcher_interface.c:#define MIN_LOADER_API_VERSION $LAUNCHER_VERSION_MAIN"
- name: Checkout PR branch
run: git checkout ${{ github.event.pull_request.head.sha }}
- name: Extract versions from PR branch
id: pr-versions
run: |
# Extract version from bgw_interface.c
BGW_VERSION_PR=$(grep -oP 'const int32 ts_bgw_loader_api_version = \K\d+' src/loader/bgw_interface.c || echo "0")
echo "bgw_version_pr=$BGW_VERSION_PR" >> $GITHUB_OUTPUT
# Extract version from launcher_interface.c
LAUNCHER_VERSION_PR=$(grep -oP '#define MIN_LOADER_API_VERSION \K\d+' src/bgw/launcher_interface.c || echo "0")
echo "launcher_version_pr=$LAUNCHER_VERSION_PR" >> $GITHUB_OUTPUT
echo "PR:"
echo "src/loader/bgw_interface.c:const int32 ts_bgw_loader_api_version = $BGW_VERSION_PR"
echo "src/bgw/launcher_interface.c:#define MIN_LOADER_API_VERSION $LAUNCHER_VERSION_PR"
- name: Validate version increments
run: |
BGW_MAIN=${{ steps.upstream-versions.outputs.bgw_version_main }}
BGW_PR=${{ steps.pr-versions.outputs.bgw_version_pr }}
LAUNCHER_MAIN=${{ steps.upstream-versions.outputs.launcher_version_main }}
LAUNCHER_PR=${{ steps.pr-versions.outputs.launcher_version_pr }}
echo "Validating version increments..."
echo "bgw_interface.c: $BGW_MAIN -> $BGW_PR (expected: $((BGW_MAIN + 1)))"
echo "launcher_interface.c: $LAUNCHER_MAIN -> $LAUNCHER_PR (expected: $((LAUNCHER_MAIN + 1)))"
VALIDATION_FAILED=false
# Check bgw_interface version
if [ "$BGW_PR" -ne "$((BGW_MAIN + 1))" ]; then
echo "❌ ERROR: bgw_interface.c version should be incremented by 1, expected: $((BGW_MAIN + 1)), Found: $BGW_PR"
VALIDATION_FAILED=true
else
echo "✅ bgw_interface.c version correctly incremented"
fi
# Check launcher_interface.c version
if [ "$LAUNCHER_PR" -ne "$((LAUNCHER_MAIN + 1))" ]; then
echo "❌ ERROR: launcher_interface.c version should be incremented by 1, expected: $((LAUNCHER_MAIN + 1)), Found: $LAUNCHER_PR"
VALIDATION_FAILED=true
else
echo "✅ launcher_interface.c version correctly incremented"
fi
if [ "$VALIDATION_FAILED" = true ]; then
echo "Version validation failed. Please ensure: Both version numbers are incremented by exactly 1 from ${{ github.event.pull_request.base.ref }} branch"
exit 1
fi
- name: Add comment to PR (if validation fails)
if: failure()
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const bgwMain = '${{ steps.upstream-versions.outputs.bgw_version_main }}';
const bgwPr = '${{ steps.pr-versions.outputs.bgw_version_pr }}';
const launcherMain = '${{ steps.upstream-versions.outputs.launcher_version_main }}';
const launcherPr = '${{ steps.pr-versions.outputs.launcher_version_pr }}';
const comment = `## ❌ Loader Version Validation Failed
The version numbers in your PR do not meet the requirements, to indicate a acknowledged loader change.
| File | ${{ github.event.pull_request.base.ref }} | PR | Expected |
|------|-------------|-----------|----------|
| \`src/loader/bgw_interface.c:const int32 ts_bgw_loader_api_version\` | ${bgwMain} | ${bgwPr} | ${parseInt(bgwMain) + 1} |
| \`src/bgw/launcher_interface.c:#define MIN_LOADER_API_VERSION\` | ${launcherMain} | ${launcherPr} | ${parseInt(launcherMain) + 1} |
**Requirements:** Both version numbers must be incremented by 1 from the ${{ github.event.pull_request.base.ref }} branch. Please update the version numbers and push your changes.`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});