-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (112 loc) · 3.83 KB
/
Copy pathdocker.yml
File metadata and controls
127 lines (112 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: Docker
on:
push:
branches:
- master
tags:
- "v*.*.*"
pull_request:
branches:
- master
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }}
cancel-in-progress: false
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Run lint checks
run: make lint
- name: Run tests
run: make test
prepare-tag:
needs: lint-and-test
if: github.event_name == 'push'
runs-on: ubuntu-latest
outputs:
tag_name: ${{ steps.resolve.outputs.tag_name || steps.bump.outputs.new_tag }}
version: ${{ steps.resolve.outputs.version || steps.bump.outputs.version }}
steps:
- name: Check out repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Resolve existing tag
id: resolve
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "tag_name=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Bump patch tag
id: bump
if: github.ref == 'refs/heads/master'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
for attempt in 1 2 3; do
git fetch --tags --force origin
latest=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1)
latest="${latest:-v0.0.0}"
version="${latest#v}"
IFS=. read -r major minor patch <<< "${version}"
new_tag="v${major}.${minor}.$((patch + 1))"
echo "Attempt ${attempt}: tagging ${new_tag} (previous: ${latest})"
if git tag -a "${new_tag}" -m "Release ${new_tag}" && git push origin "refs/tags/${new_tag}"; then
echo "new_tag=${new_tag}" >> "$GITHUB_OUTPUT"
echo "version=${new_tag#v}" >> "$GITHUB_OUTPUT"
break
fi
echo "Push failed (tag may already exist); retrying after refetch"
git tag -d "${new_tag}" 2>/dev/null || true
if [[ "${attempt}" -eq 3 ]]; then
echo "Failed to push a unique tag after 3 attempts"
exit 1
fi
done
docker:
needs: [lint-and-test, prepare-tag]
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=raw,value=${{ needs.prepare-tag.outputs.version }}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=sha-
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: true
sbom: true