Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions .github/workflows/internal-image.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Internal image

on:
workflow_dispatch:
inputs:
tag:
description: Existing internal release tag to publish
required: true
type: string
pull_request:
branches: [internal/main]
paths: [.github/workflows/internal-image.yml]
Expand All @@ -11,7 +17,7 @@ permissions:
contents: read

concurrency:
group: internal-image-${{ github.ref }}
group: internal-image-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false

env:
Expand All @@ -28,26 +34,30 @@ jobs:
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.ref }}
fetch-depth: 0
persist-credentials: false
- name: Check release version and ancestry
id: version
env:
EVENT: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
REF_NAME: ${{ inputs.tag || github.ref_name }}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
tag=internal-v${version}-1
if [ "$EVENT" = push ]; then
if [ "$EVENT" != pull_request ]; then
if [ "$EVENT" = workflow_dispatch ]; then
test "$GITHUB_REF" = refs/heads/internal/main
fi
tag=$REF_NAME
[[ $tag =~ ^internal-v([0-9]+\.[0-9]+\.[0-9]+)-([1-9][0-9]*)$ ]]
test "${BASH_REMATCH[1]}" = "$version"
revision=${BASH_REMATCH[2]}
git fetch --no-tags origin internal/main
git merge-base --is-ancestor "$GITHUB_SHA" origin/internal/main
git merge-base --is-ancestor HEAD origin/internal/main
# A published version is immutable; retries must use a new version.
releases=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq '.[].tag_name')
if grep -Fxq "$tag" <<< "$releases"; then
Expand All @@ -59,6 +69,18 @@ jobs:
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "chart=$version-internal.$revision" >> "$GITHUB_OUTPUT"
- name: Test image reference validation
shell: bash
run: |
set -euo pipefail
valid_reference() {
[[ $1 =~ ^ghcr\.io/profiling/git-cache-proxy@sha256:[0-9a-f]{64}$ ]]
}
digest=sha256:$(printf '%064d' 1)
valid_reference "$IMAGE@$digest"
for reference in "git-cache-proxy@$digest" "other.example/profiling/git-cache-proxy@$digest" "$IMAGE@sha256:abc"; do
if valid_reference "$reference"; then exit 1; fi
done
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
Expand Down Expand Up @@ -93,6 +115,7 @@ jobs:
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.ref }}
persist-credentials: false
- uses: docker/setup-buildx-action@v4
- name: Build test image
Expand Down Expand Up @@ -122,25 +145,27 @@ jobs:
sleep 3
if docker exec smoke ps -o stat | grep -q '^Z'; then exit 1; fi
- uses: docker/login-action@v4
if: github.event_name == 'push'
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Push tested image by digest
if: github.event_name == 'push'
if: github.event_name != 'pull_request'
id: push
shell: bash
run: |
set -euo pipefail
# Unique staging tags keep version tags untouched until both arches pass.
docker tag git-cache-proxy:ci "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}"
docker push "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}"
digest=$(docker image inspect "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}" --format '{{index .RepoDigests 0}}')
digest=$(docker buildx imagetools inspect "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}" --format '{{json .Manifest}}' | jq -er .digest)
[[ $digest =~ ^sha256:[0-9a-f]{64}$ ]]
digest="$IMAGE@$digest"
mkdir -p digests
printf '%s\n' "$digest" > digests/${{ matrix.arch }}
- uses: actions/upload-artifact@v7
if: github.event_name == 'push'
if: github.event_name != 'pull_request'
with:
name: internal-digest-${{ matrix.arch }}
path: digests/*
Expand All @@ -149,7 +174,7 @@ jobs:
publish:
name: Publish internal release
needs: [prepare, build]
if: github.event_name == 'push'
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -161,6 +186,7 @@ jobs:
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.ref }}
persist-credentials: false
- uses: actions/download-artifact@v8
with:
Expand All @@ -185,6 +211,10 @@ jobs:
token=$(curl -fsS --retry 3 -u "$GITHUB_ACTOR:$GH_TOKEN" "https://ghcr.io/token?service=ghcr.io&scope=repository:profiling/charts/git-cache-proxy:pull" | jq -er .token)
status=$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $token" "https://ghcr.io/v2/profiling/charts/git-cache-proxy/manifests/$CHART_VERSION")
test "$status" = 404 || { echo "Chart version exists or registry check failed: $status" >&2; exit 1; }
for arch in amd64 arm64; do
reference=$(<"digests/$arch")
[[ $reference =~ ^ghcr\.io/profiling/git-cache-proxy@sha256:[0-9a-f]{64}$ ]]
done
docker buildx imagetools create -t "$IMAGE:$TAG" $(<digests/amd64) $(<digests/arm64)
docker buildx imagetools inspect "$IMAGE:$TAG" | tee image-manifest.txt
# Only the packaged chart changes; the upstream source stays untouched.
Expand All @@ -199,7 +229,7 @@ jobs:
shell: bash
run: |
{
printf 'Source: `%s`\n\nImage: `%s:%s`\n\nChart: `oci://ghcr.io/profiling/charts/git-cache-proxy`, version `%s`\n\n' "$GITHUB_SHA" "$IMAGE" "$TAG" "$CHART_VERSION"
printf 'Source: `%s`\n\nImage: `%s:%s`\n\nChart: `oci://ghcr.io/profiling/charts/git-cache-proxy`, version `%s`\n\n' "$(git rev-parse HEAD)" "$IMAGE" "$TAG" "$CHART_VERSION"
printf 'Platforms: linux/amd64, linux/arm64. No crate published. No deployment performed.\n\n'
printf '```text\n'; cat image-manifest.txt; printf '```\n\n'
printf 'Validation: %s/%s/actions/runs/%s\n' "$GITHUB_SERVER_URL" "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID"
Expand Down
Loading