|
| 1 | +name: Release Tests Image |
| 2 | + |
| 3 | +# Publishes the gts-spec test runner image to GHCR on every semver tag. |
| 4 | +# Tag format: vMAJOR.MINOR.PATCH (e.g. v0.11.3). |
| 5 | +# MAJOR.MINOR must match the spec version declared in README.md. |
| 6 | +on: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - 'v*.*.*' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write # create GitHub Release |
| 13 | + packages: write # push to ghcr.io |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + # Only publish from the canonical repository, never from forks. |
| 19 | + if: github.repository == 'GlobalTypeSystem/gts-spec' |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 23 | + with: |
| 24 | + # Defense in depth: don't leave the GITHUB_TOKEN in .git/config. |
| 25 | + # The workflow doesn't currently upload artifacts or cache .git, |
| 26 | + # but this guards against future modifications that might. |
| 27 | + persist-credentials: false |
| 28 | + |
| 29 | + - name: Verify spec version matches tag |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | + TAG="${GITHUB_REF#refs/tags/}" # v0.11.3 or v0.11.3-rc.1 |
| 33 | + VERSION="${TAG#v}" # 0.11.3 or 0.11.3-rc.1 |
| 34 | + # Extract leading "MAJOR.MINOR" — anchored at the start so any patch |
| 35 | + # and/or prerelease suffix is ignored (e.g. 0.11.3-rc.1 -> 0.11). |
| 36 | + MAJOR_MINOR=$(printf '%s' "$VERSION" | grep -oE '^[0-9]+\.[0-9]+' || true) |
| 37 | + if [ -z "${MAJOR_MINOR:-}" ]; then |
| 38 | + echo "::error::Tag $TAG does not start with MAJOR.MINOR" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | +
|
| 42 | + # The canonical spec version is the machine-readable marker in README.md: |
| 43 | + # <!-- gts-spec-version: X.Y --> |
| 44 | + # The human-readable "**VERSION**" line below it is for readers only and |
| 45 | + # may be reworded freely. |
| 46 | + SPEC_VERSION=$(grep -oE '<!-- gts-spec-version: [0-9]+\.[0-9]+ -->' README.md \ |
| 47 | + | grep -oE '[0-9]+\.[0-9]+') |
| 48 | +
|
| 49 | + if [ -z "${SPEC_VERSION:-}" ]; then |
| 50 | + echo "::error file=README.md::Missing or malformed '<!-- gts-spec-version: X.Y -->' marker in README.md" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + MARKER_COUNT=$(grep -cE '<!-- gts-spec-version: [0-9]+\.[0-9]+ -->' README.md) |
| 55 | + if [ "$MARKER_COUNT" -ne 1 ]; then |
| 56 | + echo "::error file=README.md::Expected exactly one gts-spec-version marker in README.md, found $MARKER_COUNT" |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "Tag: $TAG" |
| 61 | + echo "Tag major.minor: $MAJOR_MINOR" |
| 62 | + echo "README spec version: $SPEC_VERSION" |
| 63 | +
|
| 64 | + if [ "$MAJOR_MINOR" != "$SPEC_VERSION" ]; then |
| 65 | + echo "::error::Tag $TAG (major.minor=$MAJOR_MINOR) does not match README spec version $SPEC_VERSION" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Set up QEMU |
| 70 | + uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3 |
| 71 | + |
| 72 | + - name: Set up Docker Buildx |
| 73 | + uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 |
| 74 | + |
| 75 | + - name: Log in to GHCR |
| 76 | + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 |
| 77 | + with: |
| 78 | + registry: ghcr.io |
| 79 | + username: ${{ github.actor }} |
| 80 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + |
| 82 | + - name: Compute image tags |
| 83 | + id: meta |
| 84 | + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5 |
| 85 | + with: |
| 86 | + images: ghcr.io/globaltypesystem/gts-spec-tests |
| 87 | + # `latest` is intentionally NOT set automatically: backport patches to |
| 88 | + # older spec lines (e.g. v0.9.4 cut from release/v0.9 while main is at |
| 89 | + # 0.11) would otherwise silently move `latest` backwards. Consumers |
| 90 | + # should pin to `vX.Y.Z` for reproducibility or use the rolling |
| 91 | + # `vX.Y` tag for the freshest patch of a given spec version. |
| 92 | + tags: | |
| 93 | + type=semver,pattern=v{{version}} |
| 94 | + type=semver,pattern=v{{major}}.{{minor}} |
| 95 | +
|
| 96 | + - name: Build and push image |
| 97 | + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 |
| 98 | + with: |
| 99 | + context: tests |
| 100 | + file: tests/Dockerfile |
| 101 | + platforms: linux/amd64,linux/arm64 |
| 102 | + push: true |
| 103 | + tags: ${{ steps.meta.outputs.tags }} |
| 104 | + labels: ${{ steps.meta.outputs.labels }} |
| 105 | + |
| 106 | + - name: Create GitHub Release |
| 107 | + uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2 |
| 108 | + with: |
| 109 | + name: ${{ github.ref_name }} |
| 110 | + generate_release_notes: true |
| 111 | + body: | |
| 112 | + Docker image for the GTS specification e2e test runner. |
| 113 | +
|
| 114 | + ``` |
| 115 | + docker pull ghcr.io/globaltypesystem/gts-spec-tests:${{ github.ref_name }} |
| 116 | + ``` |
| 117 | +
|
| 118 | + Run against a server reachable from the container (Mac/Docker Desktop): |
| 119 | + ``` |
| 120 | + docker run --rm ghcr.io/globaltypesystem/gts-spec-tests:${{ github.ref_name }} \ |
| 121 | + --gts-base-url http://host.docker.internal:8000 |
| 122 | + ``` |
| 123 | +
|
| 124 | + Linux hosts: |
| 125 | + ``` |
| 126 | + docker run --rm --add-host=host.docker.internal:host-gateway \ |
| 127 | + ghcr.io/globaltypesystem/gts-spec-tests:${{ github.ref_name }} \ |
| 128 | + --gts-base-url http://host.docker.internal:8000 |
| 129 | + ``` |
0 commit comments