ci: create a gitea release on version bump when all tests pass
Adds a Gitea Actions workflow triggered by changes to the `version` file. It builds and runs the full test suite, then publishes a release and tag only when every test succeeds and the version is new. Releasing is gated on the test job succeeding, so a broken suite blocks it automatically. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
1 file changed
+109
@@ -0,0 +1,109 @@
|
||||
# Gitea Actions — Release
|
||||
#
|
||||
# Triggered whenever the `version` file at the repository root is bumped.
|
||||
# It builds the application, runs the full test suite (ctest), and creates a
|
||||
# Gitea release tagged with the new version — but ONLY if:
|
||||
# - the version in `version` differs from the latest released tag, and
|
||||
# - every test passes.
|
||||
#
|
||||
# Because the release job `needs: build-test`, it never runs when a test fails:
|
||||
# Gitea skips dependent jobs after a failure, so a broken suite blocks the
|
||||
# release automatically.
|
||||
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- version
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
# Build the project and run every test. Fails the run if any test fails,
|
||||
# which in turn stops the `release` job below.
|
||||
build-test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
cmake g++ make qt6-base-dev
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake -B build \
|
||||
-DFWS_BUILD_EXAMPLE_PLUGIN=ON \
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cmake --build build -j$(nproc)
|
||||
|
||||
- name: Run all tests
|
||||
run: |
|
||||
cd build
|
||||
ctest --output-on-failure
|
||||
|
||||
# Reads the new version and publishes a release + git tag. Only reached when
|
||||
# build-test succeeded (Gitea `needs` skips the job otherwise) and when the
|
||||
# version genuinely changed.
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-test # guarantees all tests passed before releasing
|
||||
steps:
|
||||
- name: Checkout with full history and tags
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-tags: true
|
||||
|
||||
- name: Read version
|
||||
id: version
|
||||
run: |
|
||||
VERSION=$(tr -d ' \n' < version)
|
||||
echo "value=${VERSION}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Check whether the version already has a release
|
||||
id: check
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.value }}"
|
||||
TAG="v${VERSION}"
|
||||
if git tag --list | grep -qx "${TAG}"; then
|
||||
echo "Tag ${TAG} already exists — nothing to release"
|
||||
echo "new=false" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "new=true" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Create release
|
||||
if: steps.check.outputs.new == 'true'
|
||||
env:
|
||||
# The token used to create the release. For the automatic one to have
|
||||
# write access it must be granted the 'repository contents' (write)
|
||||
# permission on the repo. Otherwise set a GITEA_TOKEN secret.
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.value }}"
|
||||
TAG="v${VERSION}"
|
||||
BODY=$(cat <<'EOF'
|
||||
Release automatically generated by the `release` workflow when the
|
||||
`version` file was bumped and all tests passed.
|
||||
EOF
|
||||
)
|
||||
curl -sS -X POST "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d @- <<JSON
|
||||
{
|
||||
"tag_name": "${TAG}",
|
||||
"target_commitish": "main",
|
||||
"name": "v${VERSION}",
|
||||
"body": "${BODY}"
|
||||
}
|
||||
JSON
|
||||
Reference in new issue
Block a user