Skip to content

Commit a8325c9

Browse files
authored
Merge pull request #286 from adfinis-forks/ci/harden-shell-interpolation
ci(workflows): harden release input handling
2 parents 45fc083 + 15b0349 commit a8325c9

6 files changed

Lines changed: 23 additions & 5 deletions

File tree

.github/workflows/ffi-build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ jobs:
136136
shell: bash
137137
env:
138138
GH_TOKEN: ${{ github.token }}
139+
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
139140
run: |
140141
set -euo pipefail
141142
mapfile -t assets < <(
@@ -148,4 +149,4 @@ jobs:
148149
exit 1
149150
fi
150151
bash scripts/upload-release-asset.sh \
151-
"${{ inputs.release_tag || github.ref_name }}" "${assets[@]}"
152+
"$RELEASE_TAG" "${assets[@]}"

.github/workflows/go-embed.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ jobs:
146146
shell: bash
147147
env:
148148
GH_TOKEN: ${{ github.token }}
149+
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
149150
run: |
150151
set -euo pipefail
151152
mapfile -t assets < <(find staged -type f -name 'secretspec_ffi_*' -print | sort)
@@ -155,7 +156,7 @@ jobs:
155156
exit 1
156157
fi
157158
bash scripts/upload-release-asset.sh \
158-
"${{ inputs.release_tag || github.ref_name }}" "${assets[@]}"
159+
"$RELEASE_TAG" "${assets[@]}"
159160
160161
- name: Publish the Go module tag
161162
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')

.github/workflows/go-static.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ jobs:
136136
shell: bash
137137
env:
138138
GH_TOKEN: ${{ github.token }}
139+
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
139140
run: |
140141
set -euo pipefail
141142
asset="secretspec-go-static-x86_64-linux-musl.tar.gz"
142143
tar -czf "$asset" -C staged .
143144
bash scripts/upload-release-asset.sh \
144-
"${{ inputs.release_tag || github.ref_name }}" "$asset"
145+
"$RELEASE_TAG" "$asset"

.github/workflows/php-ext.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,6 @@ jobs:
148148
shell: bash
149149
env:
150150
GH_TOKEN: ${{ github.token }}
151-
run: bash scripts/upload-release-asset.sh "${{ inputs.release_tag || github.ref_name }}" "${{ steps.stage.outputs.asset }}"
151+
RELEASE_ASSET: ${{ steps.stage.outputs.asset }}
152+
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
153+
run: bash scripts/upload-release-asset.sh "$RELEASE_TAG" "$RELEASE_ASSET"

.github/workflows/swift-package.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ jobs:
173173
- name: Attach the XCFramework to the GitHub Release
174174
env:
175175
GH_TOKEN: ${{ github.token }}
176+
RELEASE_TAG: ${{ inputs.release_tag || github.ref_name }}
176177
run: >-
177178
bash scripts/upload-release-asset.sh
178-
"${{ inputs.release_tag || github.ref_name }}"
179+
"$RELEASE_TAG"
179180
artifacts/CSecretSpec.xcframework.zip

scripts/upload-release-asset.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,21 @@
1010
# retry). Needs GH_TOKEN with contents: write.
1111
set -euo pipefail
1212

13+
if (( $# < 2 )); then
14+
echo "usage: upload-release-asset.sh <tag> <asset> [asset...]" >&2
15+
exit 2
16+
fi
17+
1318
tag="$1"
1419
shift
1520

21+
# Release publication uses version tags. Reject malformed input before it is
22+
# passed to gh, while allowing SemVer prerelease and build suffixes.
23+
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([+-][0-9A-Za-z][0-9A-Za-z.+-]*)?$ ]]; then
24+
echo "invalid release tag: $tag" >&2
25+
exit 2
26+
fi
27+
1628
files=()
1729
for asset in "$@"; do
1830
# Record only the basename so `sha256sum -c` works after users download the

0 commit comments

Comments
 (0)