Files
Discord-Audio-Stream/.gitea/workflows/Build-Rollout.yml
T
fraujulianandClaude Fable 5.2 ecd37584a0
CI / format (push) Successful in 28s
CI / lint (push) Successful in 35s
CI / typecheck (push) Successful in 35s
CI / test-and-build (push) Successful in 37s
ci: harden release workflow
Pin actions to commit SHAs, restrict releases to main, serialize runs
and run the full check before publishing.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-13 15:20:10 +01:00

111 lines
4.7 KiB
YAML

name: CD
on:
workflow_dispatch:
permissions:
contents: write
# Never run two releases at once: both would publish the same commit under different versions.
concurrency:
group: release
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
if: gitea.ref == 'refs/heads/main'
steps:
- name: Checkout Repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
fetch-tags: true
- name: Use Node.js 24.17.0
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
with:
node-version: '24.17.0'
registry-url: 'https://registry.npmjs.org'
package-manager-cache: false
- name: Install Dependencies
run: npm ci
- name: Run Checks
run: npm run check
- name: Set Release Version
run: npm run version:place
env:
VERSION_PATCH: ${{ gitea.run_number }}
- name: Export Release Version
id: release_version
run: |
package_version="$(node -p "require('./package.json').version")"
echo "tag=${package_version}" >> "$GITEA_OUTPUT"
- name: Run Build
run: npm run build
# npm trusted publishing (OIDC) does not support Gitea runners, so this uses npm's
# documented fallback: a granular access token scoped to this package, with
# bypass 2FA and a short expiry.
- name: Publish Library
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Gitea release
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_API_URL: ${{ gitea.api_url }}
GITEA_REPOSITORY: ${{ gitea.repository }}
GITEA_SERVER_URL: ${{ gitea.server_url }}
GITEA_SHA: ${{ gitea.sha }}
RELEASE_TAG: v${{ steps.release_version.outputs.tag }}
run: |
git fetch --force --tags
releases_url="${GITEA_API_URL}/repos/${GITEA_REPOSITORY}/releases"
previous_tag="$(curl --fail --silent --show-error --header "Authorization: token ${GITEA_TOKEN}" "${releases_url}?limit=50" | jq -r --arg tag "$RELEASE_TAG" '[.[] | select(.draft == false and .tag_name != $tag)][0].tag_name // empty')"
if [ -n "$previous_tag" ]; then
if git rev-parse --verify --quiet "${previous_tag}^{commit}" >/dev/null; then
commit_messages="$(git log --reverse --format='- %s' "${previous_tag}..${GITEA_SHA}")"
else
commit_messages="$(git log --reverse --format='- %s' "${GITEA_SHA}")"
fi
full_changelog="${GITEA_SERVER_URL}/${GITEA_REPOSITORY}/compare/${previous_tag}...${RELEASE_TAG}"
else
commit_messages="$(git log --reverse --format='- %s' "${GITEA_SHA}")"
full_changelog=""
fi
if [ -z "$commit_messages" ]; then
commit_messages='- No commits since the previous release'
fi
{
echo '## Changes'
echo
printf '%s\n' "$commit_messages"
echo
if [ -n "$full_changelog" ]; then
echo "**Full Changelog**: ${full_changelog}"
fi
} > release-notes.md
jq -n --arg tag "$RELEASE_TAG" --arg target "$GITEA_SHA" --rawfile body release-notes.md \
'{tag_name: $tag, target_commitish: $target, name: $tag, body: $body, draft: false, prerelease: false}' > release.json
release_id="$(curl --silent --header "Authorization: token ${GITEA_TOKEN}" "${releases_url}/tags/${RELEASE_TAG}" | jq -r '.id // empty')"
if [ -n "$release_id" ]; then
curl --fail-with-body --request PATCH --header "Authorization: token ${GITEA_TOKEN}" --header 'Content-Type: application/json' --data @release.json "${releases_url}/${release_id}"
else
curl --fail-with-body --request POST --header "Authorization: token ${GITEA_TOKEN}" --header 'Content-Type: application/json' --data @release.json "$releases_url"
fi