Repository navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Docker Images (main) | |
| on: | |
| pull_request_target: | |
| types: [ closed ] | |
| branches: [ "main" ] | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| bump-version: | |
| name: Bump VERSION file | |
| if: github.event.pull_request.merged == true | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # needed to push back VERSION + Git tag | |
| outputs: | |
| new_version: ${{ steps.bump.outputs.version }} | |
| version_changed: ${{ steps.bump.outputs.changed }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.PIPELINE_PAT }} | |
| ref: ${{ github.event.pull_request.base.ref }} | |
| fetch-depth: 0 | |
| - name: Detect source branch and bump version | |
| id: bump | |
| run: | | |
| SOURCE="${{ github.event.pull_request.head.ref }}" | |
| if [[ -z "$SOURCE" ]]; then | |
| SOURCE="unknown" | |
| echo "::warning::Could not detect source branch from pull request metadata; defaulting to 'unknown' (no bump)." | |
| fi | |
| echo "Detected source branch: ${SOURCE}" | |
| # ── Read and parse current VERSION ────────────────────────────────── | |
| RAW="$(cat VERSION | tr -d '[:space:]')" | |
| CLEAN="${RAW#v}" # strip leading v | |
| while [[ "$CLEAN" == *-dev ]]; do | |
| CLEAN="${CLEAN%-dev}" | |
| done | |
| if [[ ! "$CLEAN" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
| echo "::error::VERSION must be in the form v<major>.<minor>.<patch>[-dev], got '${RAW}'" | |
| exit 1 | |
| fi | |
| MAJOR="${BASH_REMATCH[1]}" | |
| MINOR="${BASH_REMATCH[2]}" | |
| PATCH="${BASH_REMATCH[3]}" | |
| # ── Decide bump strategy ───────────────────────────────────────────── | |
| # When the source branch is 'dev', the version was already incremented | |
| # on the dev side — just promote it by stripping '-dev' (no new bump). | |
| # For any other source branch, apply the normal semver bump. | |
| if [[ "$SOURCE" != "dev" ]]; then | |
| PREFIX="${SOURCE%%/*}" | |
| case "$PREFIX" in | |
| feature) | |
| MINOR=$(( MINOR + 1 )); PATCH=0 | |
| ;; | |
| bugfix|hotfix) | |
| PATCH=$(( PATCH + 1 )) | |
| ;; | |
| release) | |
| MAJOR=$(( MAJOR + 1 )); MINOR=0; PATCH=0 | |
| ;; | |
| *) | |
| # unknown prefix → no bump | |
| ;; | |
| esac | |
| fi | |
| # ── Compose new version (no -dev suffix on main) ───────────────────── | |
| NEW_VERSION="v${MAJOR}.${MINOR}.${PATCH}" | |
| echo "${NEW_VERSION}" > VERSION | |
| echo "version=${NEW_VERSION}" >> "$GITHUB_OUTPUT" | |
| if [[ "$RAW" != "$NEW_VERSION" ]]; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| echo "New version: ${NEW_VERSION}" | |
| - name: Commit and push updated VERSION | |
| if: steps.bump.outputs.changed == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add VERSION | |
| if git diff --cached --quiet; then | |
| echo "No VERSION changes to commit." | |
| exit 0 | |
| fi | |
| git commit -m "chore: release ${{ steps.bump.outputs.version }} [skip ci]" | |
| git push | |
| - name: Create and push Git release tag | |
| run: | | |
| if git rev-parse -q --verify "refs/tags/${{ steps.bump.outputs.version }}" >/dev/null 2>&1; then | |
| echo "Tag '${{ steps.bump.outputs.version }}' already exists; skipping." | |
| exit 0 | |
| fi | |
| git tag "${{ steps.bump.outputs.version }}" | |
| git push origin "${{ steps.bump.outputs.version }}" | |
| build-and-push: | |
| name: Build & Push ${{ matrix.container }} | |
| if: github.event.pull_request.merged == true | |
| needs: bump-version | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| container: | |
| - detector | |
| - inspector | |
| - logcollector | |
| - logserver | |
| - prefilter | |
| - monitoring | |
| - alerter | |
| permissions: | |
| contents: read | |
| packages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.pull_request.base.ref }} | |
| - name: Derive partial version tags | |
| id: version | |
| run: | | |
| VERSION="$(cat VERSION | tr -d '[:space:]')" | |
| CLEAN="${VERSION#v}" | |
| MAJOR="${CLEAN%%.*}" | |
| MINOR_PATCH="${CLEAN#*.}" | |
| MINOR="${MINOR_PATCH%%.*}" | |
| echo "major=v${MAJOR}" >> "$GITHUB_OUTPUT" | |
| echo "major_minor=v${MAJOR}.${MINOR}" >> "$GITHUB_OUTPUT" | |
| - name: Setup Docker buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log into registry ${{ env.REGISTRY }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ github.repository }}-${{ matrix.container }} | |
| tags: | | |
| type=raw,value=${{ needs.bump-version.outputs.new_version }} | |
| type=raw,value=${{ steps.version.outputs.major_minor }} | |
| type=raw,value=${{ steps.version.outputs.major }} | |
| type=raw,value=latest | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| file: ./docker/dockerfiles/Dockerfile.${{ matrix.container }} |