|
| 1 | +# ----------------------------------------------------------------------------- |
| 2 | +# Build & publish the multi-architecture image. |
| 3 | +# |
| 4 | +# Triggers: |
| 5 | +# - a Git version tag (e.g. `v1.2.0`) pushed by hand -> release build; |
| 6 | +# - a manual run (workflow_dispatch) on any branch -> test build; |
| 7 | +# - called by the Release workflow (workflow_call) -> release build for the |
| 8 | +# version it just bumped and tagged. |
| 9 | +# Result: an image pushed to the GitHub Container Registry (ghcr.io), for |
| 10 | +# linux/amd64 AND linux/arm64 (Raspberry Pi, etc.). |
| 11 | +# |
| 12 | +# Manual runs tag the image with the branch name (or the `image-tag` input) |
| 13 | +# and never touch `latest`. Release builds tag `:<version>` AND `:latest`. |
| 14 | +# |
| 15 | +# That is ALL it takes to "publish": tag, push, and the decentralized indexer |
| 16 | +# does the rest (no review, no account to create). |
| 17 | +# ----------------------------------------------------------------------------- |
| 18 | +name: Build and publish image |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + tags: |
| 23 | + - 'v*' |
| 24 | + workflow_dispatch: |
| 25 | + inputs: |
| 26 | + image-tag: |
| 27 | + description: 'Image tag to publish (defaults to the branch name)' |
| 28 | + required: false |
| 29 | + default: '' |
| 30 | + # Called by release.yml after it bumps the version and pushes the tag. |
| 31 | + # A tag pushed with the default GITHUB_TOKEN does NOT re-trigger the |
| 32 | + # `push: tags` build above, so the Release workflow calls this one directly. |
| 33 | + workflow_call: |
| 34 | + inputs: |
| 35 | + version: |
| 36 | + description: 'Released version, e.g. 1.2.0 (publishes :<version> + :latest)' |
| 37 | + required: true |
| 38 | + type: string |
| 39 | + |
| 40 | +jobs: |
| 41 | + build: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + permissions: |
| 44 | + contents: read |
| 45 | + packages: write |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + # Release build (called by release.yml): check out the tag it just |
| 51 | + # created, otherwise the default checkout would be the pre-bump |
| 52 | + # commit and the image would bundle a stale manifest. Hand-pushed |
| 53 | + # tags and manual runs keep the default checkout. |
| 54 | + ref: ${{ inputs.version != '' && format('v{0}', inputs.version) || '' }} |
| 55 | + |
| 56 | + - name: Set up QEMU |
| 57 | + uses: docker/setup-qemu-action@v3 |
| 58 | + |
| 59 | + - name: Set up Docker Buildx |
| 60 | + uses: docker/setup-buildx-action@v3 |
| 61 | + |
| 62 | + - name: Log in to GitHub Container Registry |
| 63 | + uses: docker/login-action@v3 |
| 64 | + with: |
| 65 | + registry: ghcr.io |
| 66 | + username: ${{ github.actor }} |
| 67 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + |
| 69 | + - name: Derive image tags |
| 70 | + id: meta |
| 71 | + env: |
| 72 | + INPUT_IMAGE_TAG: ${{ inputs.image-tag }} |
| 73 | + INPUT_VERSION: ${{ inputs.version }} |
| 74 | + run: | |
| 75 | + image="ghcr.io/${GITHUB_REPOSITORY,,}" |
| 76 | + # Detect a release build by the `version` input, NOT the event name: |
| 77 | + # inside a called (workflow_call) workflow, GITHUB_EVENT_NAME is the |
| 78 | + # caller's event ("workflow_dispatch"), so it cannot tell the two |
| 79 | + # apart. The input is only set when release.yml calls us. |
| 80 | + if [ -n "$INPUT_VERSION" ]; then |
| 81 | + # Release build driven by release.yml: it already bumped and tagged |
| 82 | + # this exact version. Publish `:<version>` AND move `latest`. |
| 83 | + version="${INPUT_VERSION}" |
| 84 | + tags="${image}:${version},${image}:latest" |
| 85 | + elif [ "$GITHUB_EVENT_NAME" = "workflow_dispatch" ]; then |
| 86 | + # Manual test build: use the input tag, or the branch name |
| 87 | + # (slashes replaced by dashes). Never move `latest`. |
| 88 | + version="${INPUT_IMAGE_TAG:-${GITHUB_REF_NAME//\//-}}" |
| 89 | + if [ "$version" = "latest" ]; then |
| 90 | + echo "::error::Cannot use 'latest' as a manual image tag." |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + tags="${image}:${version}" |
| 94 | + else |
| 95 | + # Hand-pushed tag `v1.2.0` -> 1.2.0 |
| 96 | + version="${GITHUB_REF_NAME#v}" |
| 97 | + tags="${image}:${version},${image}:latest" |
| 98 | + fi |
| 99 | + echo "image_ref=${image}:${version}" >> "$GITHUB_OUTPUT" |
| 100 | + echo "tags=$tags" >> "$GITHUB_OUTPUT" |
| 101 | +
|
| 102 | + - name: Build and push (amd64 + arm64) |
| 103 | + uses: docker/build-push-action@v6 |
| 104 | + with: |
| 105 | + context: . |
| 106 | + platforms: linux/amd64,linux/arm64 |
| 107 | + push: true |
| 108 | + tags: ${{ steps.meta.outputs.tags }} |
| 109 | + |
| 110 | + - name: Docker build summary |
| 111 | + env: |
| 112 | + IMAGE_REF: ${{ steps.meta.outputs.image_ref }} |
| 113 | + run: | |
| 114 | + # Manifest with `docker_image` pointing at the image just pushed, |
| 115 | + # ready to paste into Gladys developer mode. |
| 116 | + manifest=$(jq --arg image "$IMAGE_REF" '.docker_image = $image' \ |
| 117 | + gladys-assistant-integration.json) |
| 118 | + { |
| 119 | + echo "## Docker build summary" |
| 120 | + echo "" |
| 121 | + echo "Image pushed (linux/amd64 + linux/arm64):" |
| 122 | + echo "" |
| 123 | + echo '```' |
| 124 | + echo "$IMAGE_REF" |
| 125 | + echo '```' |
| 126 | + echo "" |
| 127 | + echo "### Test this build in Gladys" |
| 128 | + echo "" |
| 129 | + echo "1. In Gladys, open **Integrations → Install an integration → Developer mode**." |
| 130 | + echo "2. Copy the manifest below (its \`docker_image\` already points to this build):" |
| 131 | + echo "" |
| 132 | + echo '```json' |
| 133 | + echo "$manifest" |
| 134 | + echo '```' |
| 135 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments