|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: release |
| 16 | + |
| 17 | +on: |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + tag: |
| 21 | + description: 'Image tag (e.g. v1.2.3-rc1). Leave blank to auto-generate from branch+SHA.' |
| 22 | + required: false |
| 23 | + create_release: |
| 24 | + description: 'Create a GitHub release' |
| 25 | + type: boolean |
| 26 | + default: false |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: write |
| 30 | + packages: write |
| 31 | + |
| 32 | +jobs: |
| 33 | + release: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Validate and resolve tag |
| 41 | + id: tag |
| 42 | + run: | |
| 43 | + TAG="${{ inputs.tag }}" |
| 44 | + if [[ -z "${TAG}" ]]; then |
| 45 | + BRANCH="${GITHUB_REF_NAME//\//-}" |
| 46 | + SHA="$(git rev-parse --short HEAD)" |
| 47 | + TAG="${BRANCH}-${SHA}" |
| 48 | + fi |
| 49 | + if [[ "${{ inputs.create_release }}" == "true" ]]; then |
| 50 | + if [[ ! "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$ ]]; then |
| 51 | + echo "::error::Tag '${TAG}' must match vMAJOR.MINOR.PATCH[-prerelease] when creating a release (e.g. v1.2.3 or v1.2.3-rc1)" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + fi |
| 55 | + echo "value=${TAG}" >> "$GITHUB_OUTPUT" |
| 56 | + if [[ "${{ inputs.create_release }}" == "true" ]]; then |
| 57 | + echo "tags=${TAG},latest" >> "$GITHUB_OUTPUT" |
| 58 | + else |
| 59 | + echo "tags=${TAG}" >> "$GITHUB_OUTPUT" |
| 60 | + fi |
| 61 | +
|
| 62 | + - name: Setup Go |
| 63 | + uses: actions/setup-go@v5 |
| 64 | + with: |
| 65 | + go-version-file: 'go.mod' |
| 66 | + |
| 67 | + - name: Install ko |
| 68 | + uses: ko-build/setup-ko@v0.7 |
| 69 | + |
| 70 | + - name: Log in to GHCR |
| 71 | + uses: docker/login-action@v3 |
| 72 | + with: |
| 73 | + registry: ghcr.io |
| 74 | + username: ${{ github.actor }} |
| 75 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Set up QEMU (multi-arch) |
| 78 | + uses: docker/setup-qemu-action@v3 |
| 79 | + |
| 80 | + - name: Build and push images |
| 81 | + env: |
| 82 | + # ghcr.io/<owner>/<repo> — resolves correctly in forks |
| 83 | + KO_DOCKER_REPO: ghcr.io/${{ github.repository }} |
| 84 | + run: | |
| 85 | + ./hack/run-tool.sh ko build \ |
| 86 | + --tags "${{ steps.tag.outputs.tags }}" \ |
| 87 | + --platform linux/amd64,linux/arm64 \ |
| 88 | + --bare \ |
| 89 | + ./cmd/ateapi \ |
| 90 | + ./cmd/atelet \ |
| 91 | + ./cmd/podcertcontroller \ |
| 92 | + ./cmd/atenet |
| 93 | +
|
| 94 | + - name: Create GitHub Release |
| 95 | + if: inputs.create_release |
| 96 | + uses: softprops/action-gh-release@v2 |
| 97 | + with: |
| 98 | + tag_name: ${{ steps.tag.outputs.value }} |
| 99 | + generate_release_notes: true |
0 commit comments