Remove trailing slashes from job result endpoints #22
Workflow file for this run
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: Release (only when tag is on main) | |
| on: | |
| push: | |
| tags: | |
| - 'v*.*.*' # e.g. v1.2.3 | |
| permissions: | |
| contents: write # to move git tags v1 / v1.2 | |
| packages: write # to push to GHCR | |
| jobs: | |
| precheck: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| on_main: ${{ steps.onmain.outputs.on_main }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # needed for ancestry check | |
| # Proceed only if the tagged commit is reachable from main | |
| - name: Check if tag commit is on main | |
| id: onmain | |
| run: | | |
| git fetch origin main | |
| if git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then | |
| echo "on_main=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "on_main=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| release: | |
| needs: precheck | |
| if: needs.precheck.outputs.on_main == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # needed for ancestry check and retagging | |
| # Parse tag components (you always use the 'v' prefix) | |
| - name: Parse version components | |
| id: ver | |
| run: | | |
| VERSION="${GITHUB_REF_NAME}" # v1.2.4 | |
| MAJOR="${VERSION%%.*}" # v1 | |
| MINOR="${VERSION%.*}" # v1.2 | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "major=${MAJOR}" >> "$GITHUB_OUTPUT" | |
| echo "minor=${MINOR}" >> "$GITHUB_OUTPUT" | |
| # Move floating Git tags (v1, v1.2) now that it's on main | |
| - name: Move floating git tags | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag -fa ${{ steps.ver.outputs.major }} -m "${{ steps.ver.outputs.major }} -> ${{ steps.ver.outputs.version }}" | |
| git tag -fa ${{ steps.ver.outputs.minor }} -m "${{ steps.ver.outputs.minor }} -> ${{ steps.ver.outputs.version }}" | |
| git push origin ${{ steps.ver.outputs.major }} --force | |
| git push origin ${{ steps.ver.outputs.minor }} --force | |
| # Prepare meta for GHCR (owner lowercased, build date) | |
| - name: Prepare meta | |
| id: meta | |
| shell: bash | |
| run: | | |
| echo "owner_lc=$(echo "${GITHUB_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT" | |
| echo "build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT" | |
| - name: Log in to GHCR | |
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
| - name: Build & push image | |
| run: | | |
| set -euo pipefail | |
| OWNER="${{ steps.meta.outputs.owner_lc }}" | |
| VERSION="${{ steps.ver.outputs.version }}" | |
| MINOR="${{ steps.ver.outputs.minor }}" | |
| MAJOR="${{ steps.ver.outputs.major }}" | |
| BUILD_DATE="${{ steps.meta.outputs.build_date }}" | |
| COMMIT_SHA="${GITHUB_SHA}" | |
| IMAGE="ghcr.io/${OWNER}/doc-api" | |
| CONTEXT="./doc_api" | |
| DOCKERFILE="./doc_api/Dockerfile" | |
| echo "==> Building doc-api -> ${IMAGE}:${VERSION}" | |
| docker build \ | |
| -f "${DOCKERFILE}" \ | |
| -t "${IMAGE}:${VERSION}" \ | |
| --build-arg VERSION="${VERSION}" \ | |
| --build-arg COMMIT_SHA="${COMMIT_SHA}" \ | |
| --build-arg BUILD_DATE="${BUILD_DATE}" \ | |
| "${CONTEXT}" | |
| docker push "${IMAGE}:${VERSION}" | |
| # Floating tags + latest | |
| docker tag "${IMAGE}:${VERSION}" "${IMAGE}:${MINOR}" | |
| docker tag "${IMAGE}:${VERSION}" "${IMAGE}:${MAJOR}" | |
| docker tag "${IMAGE}:${VERSION}" "${IMAGE}:latest" | |
| docker push "${IMAGE}:${MINOR}" | |
| docker push "${IMAGE}:${MAJOR}" | |
| docker push "${IMAGE}:latest" |