Skip to content

Commit 1936db6

Browse files
committed
ci: add GitHub Actions workflow for building and publishing Docker image
1 parent d84d9db commit 1936db6

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

.github/workflows/release.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
repository_dispatch:
5+
types: [speedtest-tracker-release]
6+
workflow_dispatch:
7+
inputs:
8+
release_tag:
9+
description: 'Release tag from speedtest-tracker repository'
10+
required: true
11+
type: string
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to Container Registry
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract metadata
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
tags: |
44+
type=semver,pattern={{version}},value=${{ github.event.client_payload.tag_name || inputs.release_tag }}
45+
type=semver,pattern={{major}}.{{minor}},value=${{ github.event.client_payload.tag_name || inputs.release_tag }}
46+
type=semver,pattern={{major}},value=${{ github.event.client_payload.tag_name || inputs.release_tag }}
47+
type=raw,value=latest
48+
49+
- name: Determine release tag
50+
id: release-tag
51+
run: |
52+
# Get the release tag from either repository_dispatch or workflow_dispatch
53+
if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then
54+
RELEASE_TAG="${{ github.event.client_payload.tag_name }}"
55+
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
56+
RELEASE_TAG="${{ inputs.release_tag }}"
57+
else
58+
echo "Unexpected event type: ${{ github.event_name }}"
59+
exit 1
60+
fi
61+
62+
# Remove 'v' prefix if present
63+
RELEASE_TAG="${RELEASE_TAG#v}"
64+
echo "release_tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
65+
echo "Using release tag: ${RELEASE_TAG}"
66+
67+
- name: Build and push Docker image
68+
id: build
69+
uses: docker/build-push-action@v5
70+
with:
71+
context: .
72+
platforms: linux/amd64,linux/arm64
73+
push: true
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
build-args: |
77+
RELEASE_TAG=${{ steps.release-tag.outputs.release_tag }}
78+
cache-from: type=gha
79+
cache-to: type=gha,mode=max
80+
81+
- name: Generate artifact attestation
82+
uses: actions/attest-build-provenance@v1
83+
with:
84+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
85+
subject-digest: ${{ steps.build.outputs.digest }}
86+
push-to-registry: true

0 commit comments

Comments
 (0)