Skip to content

Commit 3a374ec

Browse files
committed
ci: harden current repository release workflow
1 parent d065349 commit 3a374ec

2 files changed

Lines changed: 62 additions & 9 deletions

File tree

.github/workflows/binary-release.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ on:
1414
description: 'Enable UPX compression (true/false)'
1515
required: false
1616
default: 'true'
17+
release_name:
18+
description: 'Optional GitHub Release title for manual runs'
19+
required: false
20+
default: ''
21+
release_notes:
22+
description: 'Optional GitHub Release notes for manual runs'
23+
required: false
24+
default: ''
1725

1826
permissions:
1927
contents: write
@@ -82,17 +90,20 @@ jobs:
8290
- name: Prepare build vars
8391
id: vars
8492
shell: bash
93+
env:
94+
INPUT_VERSION: ${{ github.event.inputs.version || 'dev' }}
95+
INPUT_ENABLE_UPX: ${{ github.event.inputs.enable_upx || 'true' }}
8596
run: |
8697
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
8798
VERSION="${GITHUB_REF_NAME}"
8899
else
89-
VERSION="${{ github.event.inputs.version || 'dev' }}"
100+
VERSION="${INPUT_VERSION}"
90101
fi
91102
BUILDTIME="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
92103
REVISION="${GITHUB_SHA}"
93104
94105
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
95-
ENABLE_UPX_RAW="${{ github.event.inputs.enable_upx }}"
106+
ENABLE_UPX_RAW="${INPUT_ENABLE_UPX}"
96107
else
97108
ENABLE_UPX_RAW="true"
98109
fi
@@ -168,13 +179,30 @@ jobs:
168179
- name: Prepare release vars
169180
id: release_vars
170181
shell: bash
182+
env:
183+
INPUT_VERSION: ${{ github.event.inputs.version || 'dev' }}
184+
INPUT_RELEASE_NAME: ${{ github.event.inputs.release_name || '' }}
185+
INPUT_RELEASE_NOTES: ${{ github.event.inputs.release_notes || '' }}
171186
run: |
172187
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
173188
RELEASE_VERSION="${GITHUB_REF_NAME}"
189+
RELEASE_NAME="${GITHUB_REF_NAME}"
190+
RELEASE_BODY=""
174191
else
175-
RELEASE_VERSION="${{ github.event.inputs.version || 'dev' }}"
192+
RELEASE_VERSION="${INPUT_VERSION}"
193+
RELEASE_NAME="${INPUT_RELEASE_NAME}"
194+
RELEASE_BODY="${INPUT_RELEASE_NOTES}"
195+
fi
196+
if [[ -z "${RELEASE_NAME}" ]]; then
197+
RELEASE_NAME="${RELEASE_VERSION}"
176198
fi
177199
echo "release_version=${RELEASE_VERSION}" >> "${GITHUB_OUTPUT}"
200+
echo "release_name=${RELEASE_NAME}" >> "${GITHUB_OUTPUT}"
201+
{
202+
echo "release_body<<EOF"
203+
printf '%s\n' "${RELEASE_BODY}"
204+
echo "EOF"
205+
} >> "${GITHUB_OUTPUT}"
178206
179207
- name: Download all artifacts
180208
uses: actions/download-artifact@v4
@@ -187,12 +215,14 @@ jobs:
187215
uses: softprops/action-gh-release@v2
188216
with:
189217
tag_name: ${{ steps.release_vars.outputs.release_version }}
218+
name: ${{ steps.release_vars.outputs.release_name }}
219+
body: ${{ steps.release_vars.outputs.release_body }}
190220
files: dist/*
191221
fail_on_unmatched_files: true
192222
overwrite_files: true
193223

194-
- name: Load source release metadata
195-
id: source_release
224+
- name: Load current release metadata
225+
id: current_release
196226
env:
197227
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
198228
shell: bash
@@ -221,7 +251,7 @@ jobs:
221251
if: ${{ env.TELEGRAM_BOT_TOKEN != '' && env.TELEGRAM_CHANNEL_ID != '' }}
222252
env:
223253
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
224-
RELEASE_BODY: ${{ steps.source_release.outputs.release_body }}
254+
RELEASE_BODY: ${{ steps.current_release.outputs.release_body }}
225255
shell: bash
226256
run: |
227257
set -euo pipefail

scripts/ci.sh

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ dependency_hygiene() {
7777
printf '\n==> dependency hygiene ok\n'
7878
}
7979

80+
release_hygiene() {
81+
local workflow
82+
workflow=".github/workflows/binary-release.yml"
83+
if [[ ! -f "$workflow" ]]; then
84+
printf 'release workflow not found: %s\n' "$workflow" >&2
85+
return 1
86+
fi
87+
if git grep -nE 'repository:[[:space:]]*[^[:space:]]+|GH[_]PAT|vohive[-]release|github[.]com/iniwex5' -- "$workflow"; then
88+
printf 'release workflow must publish only to the current repository without cross-repo PAT wiring\n' >&2
89+
return 1
90+
fi
91+
if ! git grep -n 'softprops/action-gh-release' -- "$workflow" >/dev/null; then
92+
printf 'release workflow does not publish through softprops/action-gh-release\n' >&2
93+
return 1
94+
fi
95+
if ! git grep -n 'files: dist/*' -- "$workflow" >/dev/null; then
96+
printf 'release workflow must upload dist artifacts to the current release\n' >&2
97+
return 1
98+
fi
99+
printf '\n==> release hygiene ok\n'
100+
}
101+
80102
web_build() {
81103
run npm ci --prefix web
82104
run npm run build --prefix web
@@ -108,9 +130,9 @@ go_build() {
108130

109131
usage() {
110132
cat <<'USAGE'
111-
Usage: scripts/ci.sh [all|workflow-lint|hygiene|web|tidy|test|build ...]
133+
Usage: scripts/ci.sh [all|workflow-lint|hygiene|release-hygiene|web|tidy|test|build ...]
112134
113-
Default all runs workflow-lint, hygiene, web, tidy, test, and build.
135+
Default all runs workflow-lint, hygiene, release-hygiene, web, tidy, test, and build.
114136
115137
Environment:
116138
GO_BIN path to go binary
@@ -126,7 +148,7 @@ USAGE
126148
GO_BIN="$(find_go)"
127149

128150
if [[ $# -eq 0 || "${1:-}" == "all" ]]; then
129-
tasks=(workflow-lint hygiene web tidy test build)
151+
tasks=(workflow-lint hygiene release-hygiene web tidy test build)
130152
else
131153
tasks=("$@")
132154
fi
@@ -138,6 +160,7 @@ for task in "${tasks[@]}"; do
138160
case "$task" in
139161
workflow-lint | actionlint) workflow_lint ;;
140162
hygiene | dependency-hygiene) dependency_hygiene ;;
163+
release-hygiene | release) release_hygiene ;;
141164
web | frontend) web_build ;;
142165
tidy | tidy-check) tidy_check ;;
143166
test | go-test) go_tests ;;

0 commit comments

Comments
 (0)