Release / Plan (reuse the published image?) (push) Successful in 5s
Release / ci (push) Skipped
Release / Build hub image (amd64) (push) Skipped
Release / Build probe image (amd64) (push) Skipped
Release / Build hub image (arm64) (push) Skipped
Release / Build probe image (arm64) (push) Skipped
Release / Publish tags (probe) (push) Successful in 16s
Release / Publish tags (hub) (push) Successful in 17s
Release / Gitea release (push) Skipped
The release ran per ref, so main and a tag pushed together both planned before any image existed and built everything twice; it also re-ran the whole CI that the pull request had already passed on the same commit, and the PR CI built the images a third time. Now: one release queue (the tag waits for main and only re-points tags), the release skips CI when the pull request already passed for this commit, and the PR CI no longer builds images (the release builds once per input hash and smoke-tests before publishing). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
208 lines
9.8 KiB
YAML
208 lines
9.8 KiB
YAML
name: Release
|
|
|
|
# Publishes the two multi-arch Urutau images (linux/amd64 + linux/arm64) to the
|
|
# Gitea container registry: the hub (<repo>) and the probe (<repo>-probe), both
|
|
# built from the same Dockerfile. A merge into main publishes `edge`; a v* tag
|
|
# re-points the images already built for the same inputs to X.Y.Z, X.Y and
|
|
# latest (no rebuild) and creates the Gitea Release. Needs the secret REGISTRY_TOKEN (Gitea token
|
|
# with write:package) visible to this repository.
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ['v*']
|
|
workflow_dispatch:
|
|
|
|
# One queue for main and tags: a tag pushed together with main waits for the
|
|
# main run, then finds the images already published and only re-points tags.
|
|
# (A per-ref group let both runs plan at once, see nothing, and build twice.)
|
|
concurrency:
|
|
group: release
|
|
cancel-in-progress: false
|
|
|
|
env:
|
|
REGISTRY: git.lucasrguerra.dev.br
|
|
|
|
jobs:
|
|
# The images are built only from these paths, so their tree hashes identify
|
|
# them. When inputs-<hash> already exists for BOTH images (docs-only merge, workflow change, or a tag
|
|
# on a commit main already published), nothing is built or tested again.
|
|
plan:
|
|
name: Plan (reuse the published image?)
|
|
runs-on: linux-arm64
|
|
outputs:
|
|
inputs: ${{ steps.plan.outputs.inputs }}
|
|
reuse: ${{ steps.plan.outputs.reuse }}
|
|
tested: ${{ steps.tested.outputs.tested }}
|
|
image: ${{ steps.plan.outputs.image }}
|
|
probe_image: ${{ steps.plan.outputs.probe_image }}
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- id: plan
|
|
env:
|
|
REPO: ${{ gitea.repository }}
|
|
run: |
|
|
paths="Dockerfile .dockerignore go.mod cmd internal logo.png"
|
|
# go.sum only exists once a dependency is added (the code is stdlib-only today).
|
|
git cat-file -e HEAD:go.sum 2>/dev/null && paths="$paths go.sum"
|
|
inputs=$(for p in $paths; do git rev-parse "HEAD:$p"; done | sha256sum | cut -c1-16)
|
|
ns="${REPO,,}"
|
|
reuse=true
|
|
for repo in "$ns" "$ns-probe"; do
|
|
token=$(curl -fsS "https://$REGISTRY/v2/token?service=container_registry&scope=repository:$repo:pull" | jq -r .token)
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' -I \
|
|
-H "Authorization: Bearer $token" \
|
|
-H 'Accept: application/vnd.oci.image.index.v1+json,application/vnd.docker.distribution.manifest.list.v2+json' \
|
|
"https://$REGISTRY/v2/$repo/manifests/inputs-$inputs")
|
|
echo "$repo inputs-$inputs -> HTTP $code"
|
|
[ "$code" = 200 ] || reuse=false
|
|
done
|
|
echo "inputs=$inputs" >> "$GITHUB_OUTPUT"
|
|
echo "reuse=$reuse" >> "$GITHUB_OUTPUT"
|
|
echo "image=$REGISTRY/$ns" >> "$GITHUB_OUTPUT"
|
|
echo "probe_image=$REGISTRY/$ns-probe" >> "$GITHUB_OUTPUT"
|
|
# The pull request already ran the whole CI on this exact commit (the
|
|
# merge is a fast-forward): do not run the same tests again here.
|
|
- id: tested
|
|
env:
|
|
REPO: ${{ gitea.repository }}
|
|
SHA: ${{ gitea.sha }}
|
|
# The job token reads this repository's runs; on any error the answer
|
|
# is false and the CI simply runs (never skips tests by mistake).
|
|
TOKEN: ${{ gitea.token }}
|
|
run: |
|
|
tested=$(curl -fsS -H "Authorization: token $TOKEN" "https://$REGISTRY/api/v1/repos/$REPO/actions/runs?limit=50" \
|
|
| jq -r --arg sha "$SHA" '[.workflow_runs[] | select(.head_sha == $sha and (.path | startswith("ci.yml")) and .conclusion == "success")] | length > 0' 2>/dev/null) || tested=false
|
|
[ "$tested" = true ] || tested=false
|
|
echo "CI already passed for $SHA: $tested"
|
|
echo "tested=$tested" >> "$GITHUB_OUTPUT"
|
|
|
|
ci:
|
|
needs: plan
|
|
if: ${{ needs.plan.outputs.reuse != 'true' && needs.plan.outputs.tested != 'true' }}
|
|
uses: ./.gitea/workflows/ci.yml
|
|
|
|
# Each architecture of each image is built on a native runner (no QEMU) and
|
|
# pushed under a per-architecture tag; publish joins them into one manifest list.
|
|
build:
|
|
name: Build ${{ matrix.target }} image (${{ matrix.arch }})
|
|
needs: [plan, ci]
|
|
# ci is skipped (not failed) when the pull request already tested this commit.
|
|
if: ${{ !cancelled() && needs.plan.result == 'success' && needs.plan.outputs.reuse != 'true' && (needs.ci.result == 'success' || needs.ci.result == 'skipped') }}
|
|
runs-on: ${{ matrix.runner }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- { target: hub, arch: amd64, platform: linux/amd64, runner: linux-amd64 }
|
|
- { target: hub, arch: arm64, platform: linux/arm64, runner: linux-arm64 }
|
|
- { target: probe, arch: amd64, platform: linux/amd64, runner: linux-amd64 }
|
|
- { target: probe, arch: arm64, platform: linux/arm64, runner: linux-arm64 }
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
- uses: docker/setup-buildx-action@v4
|
|
- uses: docker/login-action@v4
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
# Plain `docker buildx build` instead of docker/build-push-action: that
|
|
# action's large upstream repo reliably hangs the act runner's clone.
|
|
# Same end result, no action to clone.
|
|
- name: Build and push (per architecture)
|
|
run: |
|
|
image='${{ matrix.target == 'probe' && needs.plan.outputs.probe_image || needs.plan.outputs.image }}'
|
|
docker buildx build \
|
|
--target "${{ matrix.target }}" \
|
|
--platform "${{ matrix.platform }}" \
|
|
--push \
|
|
-t "$image:build-${{ gitea.sha }}-${{ matrix.arch }}" \
|
|
--cache-from "type=registry,ref=$image:buildcache-${{ matrix.arch }}" \
|
|
--cache-to "type=registry,ref=$image:buildcache-${{ matrix.arch }},mode=max" \
|
|
.
|
|
# Runs the image that was just pushed, on its own architecture.
|
|
- name: Smoke test
|
|
run: |
|
|
image='${{ matrix.target == 'probe' && needs.plan.outputs.probe_image || needs.plan.outputs.image }}'
|
|
scripts/smoke-${{ matrix.target == 'probe' && 'probe' || 'image' }}.sh "$image:build-${{ gitea.sha }}-${{ matrix.arch }}"
|
|
|
|
publish:
|
|
name: Publish tags (${{ matrix.target }})
|
|
needs: [plan, build]
|
|
# build is skipped, not successful, when the image is reused.
|
|
if: ${{ !cancelled() && needs.plan.result == 'success' && (needs.build.result == 'success' || needs.plan.outputs.reuse == 'true') }}
|
|
runs-on: linux-arm64
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
target: [hub, probe]
|
|
env:
|
|
IMAGE: ${{ matrix.target == 'probe' && needs.plan.outputs.probe_image || needs.plan.outputs.image }}
|
|
steps:
|
|
- uses: docker/setup-buildx-action@v4
|
|
- uses: docker/login-action@v4
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
|
- name: Tags
|
|
id: meta
|
|
uses: docker/metadata-action@v6
|
|
with:
|
|
images: ${{ env.IMAGE }}
|
|
flavor: latest=false
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=semver,pattern={{major}}.{{minor}}
|
|
type=raw,value=latest,enable=${{ startsWith(gitea.ref, 'refs/tags/v') && !contains(gitea.ref_name, '-') }}
|
|
type=raw,value=edge,enable=${{ gitea.ref == 'refs/heads/main' }}
|
|
type=sha,format=long
|
|
- name: Apply tags
|
|
run: |
|
|
image="$IMAGE"
|
|
tags=$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< '${{ steps.meta.outputs.json }}')
|
|
inputs='${{ needs.plan.outputs.inputs }}'
|
|
if [ '${{ needs.plan.outputs.reuse }}' = true ]; then
|
|
docker buildx imagetools create $tags "$image:inputs-$inputs"
|
|
else
|
|
docker buildx imagetools create $tags -t "$image:inputs-$inputs" \
|
|
"$image:build-${{ gitea.sha }}-amd64" "$image:build-${{ gitea.sha }}-arm64"
|
|
fi
|
|
- name: Check architectures
|
|
run: |
|
|
docker buildx imagetools inspect "$IMAGE:inputs-${{ needs.plan.outputs.inputs }}" \
|
|
--format '{{json .Manifest}}' \
|
|
| jq -r '.manifests[] | select(.platform.os == "linux") | "\(.platform.os)/\(.platform.architecture)"' \
|
|
| tee platforms.txt
|
|
grep -qx linux/amd64 platforms.txt && grep -qx linux/arm64 platforms.txt
|
|
- name: Summary
|
|
run: |
|
|
{ echo "### Urutau ${{ matrix.target }} image published (linux/amd64, linux/arm64)"; echo; echo '```'
|
|
echo "${{ steps.meta.outputs.tags }}"; echo '```'; } >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
gitea-release:
|
|
name: Gitea release
|
|
needs: [plan, publish]
|
|
if: ${{ !cancelled() && needs.publish.result == 'success' && startsWith(gitea.ref, 'refs/tags/v') }}
|
|
runs-on: linux-arm64
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Release
|
|
env:
|
|
TAG: ${{ gitea.ref_name }}
|
|
TOKEN: ${{ gitea.token }}
|
|
API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}
|
|
IMAGE: ${{ needs.plan.outputs.image }}
|
|
PROBE_IMAGE: ${{ needs.plan.outputs.probe_image }}
|
|
run: |
|
|
if curl -fsS -H "Authorization: token $TOKEN" "$API/releases/tags/$TAG" >/dev/null 2>&1; then
|
|
echo "release $TAG already exists"; exit 0
|
|
fi
|
|
{ scripts/release-notes.sh "$TAG"; echo; echo '```bash'; echo "docker pull $IMAGE:${TAG#v}"; echo "docker pull $PROBE_IMAGE:${TAG#v}"; echo '```'; } > notes.md
|
|
pre=false; case "$TAG" in *-*) pre=true ;; esac
|
|
jq -n --arg tag "$TAG" --arg name "Urutau ${TAG#v}" --rawfile body notes.md --argjson pre "$pre" \
|
|
'{tag_name:$tag, name:$name, body:$body, prerelease:$pre}' > release.json
|
|
curl -fsS -X POST "$API/releases" -H "Authorization: token $TOKEN" \
|
|
-H 'Content-Type: application/json' -d @release.json >/dev/null
|