ci: make ci.yml the single coordinator workflow
- Trigger ci on push and pull_request only - Convert publish-image and stable-tag to reusable workflows (workflow_call) - Add detect-release job for strict SemVer tag detection (vX.Y.Z) - Run tests first, then publish image, then move stable tag - Remove direct tag/push triggers from publish-image and stable-tag https://chatgpt.com/share/e/699044d3-c1d8-8013-a40d-974d1fc69974
This commit is contained in:
44
.github/workflows/ci.yml
vendored
44
.github/workflows/ci.yml
vendored
@@ -1,11 +1,47 @@
|
|||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request: {}
|
||||||
push:
|
push: {}
|
||||||
branches:
|
|
||||||
- main
|
permissions:
|
||||||
|
contents: write
|
||||||
|
packages: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
detect-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
is_semver_tag: ${{ steps.detect.outputs.is_semver_tag }}
|
||||||
|
steps:
|
||||||
|
- id: detect
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
# Only true for tag refs like v1.2.3 (no suffix)
|
||||||
|
if [[ "${GITHUB_REF}" == refs/tags/* ]] && [[ "${GITHUB_REF_NAME}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "is_semver_tag=true" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "is_semver_tag=false" >> "$GITHUB_OUTPUT"
|
||||||
|
fi
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
uses: ./.github/workflows/reusable-test.yml
|
uses: ./.github/workflows/reusable-test.yml
|
||||||
|
with:
|
||||||
|
python-version: "3.12"
|
||||||
|
matomo-token-description: "ci-token"
|
||||||
|
|
||||||
|
publish-image:
|
||||||
|
if: needs.detect-release.outputs.is_semver_tag == 'true'
|
||||||
|
needs: [detect-release, tests]
|
||||||
|
uses: ./.github/workflows/publish-image.yml
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
tag-stable:
|
||||||
|
if: needs.detect-release.outputs.is_semver_tag == 'true'
|
||||||
|
needs: [detect-release, tests, publish-image]
|
||||||
|
uses: ./.github/workflows/stable-tag.yml
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|||||||
24
.github/workflows/publish-image.yml
vendored
24
.github/workflows/publish-image.yml
vendored
@@ -1,20 +1,10 @@
|
|||||||
name: publish-image
|
name: publish-image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_call: {}
|
||||||
tags:
|
|
||||||
- "v*.*.*"
|
|
||||||
|
|
||||||
workflow_run:
|
|
||||||
workflows: ["Stable Tag"] # MUST match stable-tag.yml -> name: Stable Tag
|
|
||||||
types: [completed]
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
if: |
|
|
||||||
(github.event_name == 'push') ||
|
|
||||||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@@ -24,9 +14,8 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
# push: checks out the tag ref
|
fetch-depth: 0
|
||||||
# workflow_run: checks out the exact commit that the Stable Tag workflow ran on
|
ref: ${{ github.ref }} # bei tag-push ist das der Tag-Ref
|
||||||
ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.ref }}
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@v3
|
||||||
@@ -47,14 +36,9 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
IMAGE="ghcr.io/${{ github.repository }}"
|
IMAGE="ghcr.io/${{ github.repository }}"
|
||||||
|
|
||||||
if [ "${{ github.event_name }}" = "push" ]; then
|
|
||||||
RAW_TAG="${{ github.ref_name }}" # e.g. v1.1.7
|
RAW_TAG="${{ github.ref_name }}" # e.g. v1.1.7
|
||||||
TAG="${RAW_TAG#v}" # -> 1.1.7 (only strips leading 'v')
|
TAG="${RAW_TAG#v}" # -> 1.1.7
|
||||||
echo "tags=$IMAGE:$TAG,$IMAGE:latest" >> "$GITHUB_OUTPUT"
|
echo "tags=$IMAGE:$TAG,$IMAGE:latest" >> "$GITHUB_OUTPUT"
|
||||||
else
|
|
||||||
echo "tags=$IMAGE:stable" >> "$GITHUB_OUTPUT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
|
|||||||
13
.github/workflows/stable-tag.yml
vendored
13
.github/workflows/stable-tag.yml
vendored
@@ -1,24 +1,14 @@
|
|||||||
name: Stable Tag
|
name: Stable Tag
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
workflow_call: {}
|
||||||
tags:
|
|
||||||
- "v*"
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
|
||||||
uses: ./.github/workflows/reusable-test.yml
|
|
||||||
with:
|
|
||||||
python-version: "3.12"
|
|
||||||
matomo-token-description: "stable-ci-token"
|
|
||||||
|
|
||||||
tag-stable:
|
tag-stable:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: test
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout (full history for tags)
|
- name: Checkout (full history for tags)
|
||||||
@@ -37,6 +27,5 @@ jobs:
|
|||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
git fetch --tags --force
|
git fetch --tags --force
|
||||||
|
|
||||||
git tag -fa stable -m "stable -> ${GITHUB_REF_NAME} (${GITHUB_SHA})" "${GITHUB_SHA}"
|
git tag -fa stable -m "stable -> ${GITHUB_REF_NAME} (${GITHUB_SHA})" "${GITHUB_SHA}"
|
||||||
git push --force origin stable
|
git push --force origin stable
|
||||||
|
|||||||
Reference in New Issue
Block a user