|
| 1 | +name: Build and Push Setup |
| 2 | +description: Checkout, version.json, image tag, buildx, GCP auth, and registry logins |
| 3 | + |
| 4 | +inputs: |
| 5 | + version_json_path: |
| 6 | + description: Path for version.json |
| 7 | + required: false |
| 8 | + default: ./version.json |
| 9 | + workload_identity_provider: |
| 10 | + description: GCP Workload Identity provider |
| 11 | + required: true |
| 12 | + gcp_service_account: |
| 13 | + description: GCP service account email |
| 14 | + required: true |
| 15 | + |
| 16 | +outputs: |
| 17 | + image_tag: |
| 18 | + description: Computed image tag |
| 19 | + value: ${{ steps.tag.outputs.value }} |
| 20 | + push_latest: |
| 21 | + description: Whether to push a latest tag |
| 22 | + value: ${{ steps.tag.outputs.push_latest }} |
| 23 | + |
| 24 | +runs: |
| 25 | + using: composite |
| 26 | + steps: |
| 27 | + - name: Create version.json |
| 28 | + shell: bash |
| 29 | + run: | |
| 30 | + printf '{"commit":"%s","version":"%s","source":"%s","build":"%s"}\n' \ |
| 31 | + "$GITHUB_SHA" "$GITHUB_REF_NAME" \ |
| 32 | + "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ |
| 33 | + "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \ |
| 34 | + > ${{ inputs.version_json_path }} |
| 35 | +
|
| 36 | + - name: Compute image tag |
| 37 | + id: tag |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then |
| 41 | + echo "value=$GITHUB_REF_NAME" >> "$GITHUB_OUTPUT" |
| 42 | + echo "push_latest=true" >> "$GITHUB_OUTPUT" |
| 43 | + else |
| 44 | + echo "value=${GITHUB_SHA:0:10}" >> "$GITHUB_OUTPUT" |
| 45 | + echo "push_latest=false" >> "$GITHUB_OUTPUT" |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4 |
| 50 | + |
| 51 | + - name: GCP auth |
| 52 | + id: gcp_auth |
| 53 | + uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3 |
| 54 | + with: |
| 55 | + workload_identity_provider: ${{ inputs.workload_identity_provider }} |
| 56 | + service_account: ${{ inputs.gcp_service_account }} |
| 57 | + token_format: access_token |
| 58 | + |
| 59 | + - name: Log in to GAR |
| 60 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 61 | + with: |
| 62 | + registry: us-docker.pkg.dev |
| 63 | + username: oauth2accesstoken |
| 64 | + password: ${{ steps.gcp_auth.outputs.access_token }} |
| 65 | + |
| 66 | + - name: Log in to GHCR |
| 67 | + uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0 |
| 68 | + with: |
| 69 | + registry: ghcr.io |
| 70 | + username: ${{ github.actor }} |
| 71 | + password: ${{ github.token }} |
0 commit comments