mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-24 11:48:39 +08:00
[CI] Make versioned releases immutable (#289)
This commit is contained in:
@@ -7,6 +7,8 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "**"
|
- "**"
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- "**/*.md"
|
- "**/*.md"
|
||||||
- "**/*.png"
|
- "**/*.png"
|
||||||
@@ -53,6 +55,11 @@ jobs:
|
|||||||
release_tag="v${version}"
|
release_tag="v${version}"
|
||||||
release_name="SharpEmu v${version}"
|
release_name="SharpEmu v${version}"
|
||||||
|
|
||||||
|
if [ "${GITHUB_REF_TYPE}" = "tag" ] && [ "${GITHUB_REF_NAME}" != "${release_tag}" ]; then
|
||||||
|
echo "Release tag ${GITHUB_REF_NAME} does not match project version ${release_tag}." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
{
|
{
|
||||||
echo "short-sha=${short_sha}"
|
echo "short-sha=${short_sha}"
|
||||||
echo "safe-ref=${safe_ref}"
|
echo "safe-ref=${safe_ref}"
|
||||||
@@ -203,7 +210,9 @@ jobs:
|
|||||||
- init
|
- init
|
||||||
- build
|
- build
|
||||||
- build-posix
|
- build-posix
|
||||||
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
|
# Versioned releases are immutable and tag-driven. Branch and manual runs
|
||||||
|
# still produce Actions artifacts without modifying a published release.
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
@@ -213,7 +222,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: release
|
path: release
|
||||||
|
|
||||||
- name: Create or update release
|
- name: Create release
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
GH_REPO: ${{ github.repository }}
|
GH_REPO: ${{ github.repository }}
|
||||||
@@ -231,26 +240,11 @@ jobs:
|
|||||||
notes="Automated SharpEmu v${VERSION} build for commit ${GITHUB_SHA}."
|
notes="Automated SharpEmu v${VERSION} build for commit ${GITHUB_SHA}."
|
||||||
|
|
||||||
if gh release view "${RELEASE_TAG}" >/dev/null 2>&1; then
|
if gh release view "${RELEASE_TAG}" >/dev/null 2>&1; then
|
||||||
gh release upload "${RELEASE_TAG}" "${assets[@]}" --clobber
|
echo "Release ${RELEASE_TAG} already exists and will not be modified." >&2
|
||||||
gh release edit "${RELEASE_TAG}" --title "${RELEASE_NAME}" --notes "${notes}"
|
exit 1
|
||||||
else
|
|
||||||
gh release create "${RELEASE_TAG}" "${assets[@]}" \
|
|
||||||
--title "${RELEASE_NAME}" \
|
|
||||||
--notes "${notes}" \
|
|
||||||
--target "${GITHUB_SHA}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
keep=()
|
gh release create "${RELEASE_TAG}" "${assets[@]}" \
|
||||||
for asset_path in "${assets[@]}"; do
|
--verify-tag \
|
||||||
keep+=("$(basename "${asset_path}")")
|
--title "${RELEASE_NAME}" \
|
||||||
done
|
--notes "${notes}"
|
||||||
mapfile -t release_assets < <(gh release view "${RELEASE_TAG}" --json assets --jq '.assets[].name' | sort)
|
|
||||||
for asset in "${release_assets[@]}"; do
|
|
||||||
case "${asset}" in
|
|
||||||
sharpemu-${VERSION}-*.zip|sharpemu-${VERSION}-*.tar.gz)
|
|
||||||
if ! printf '%s\n' "${keep[@]}" | grep -Fxq "${asset}"; then
|
|
||||||
gh release delete-asset "${RELEASE_TAG}" "${asset}" --yes
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|||||||
Reference in New Issue
Block a user