Repository navigation
135 lines (115 loc) · 3.7 KB
/
Copy pathbuild.yml
File metadata and controls
135 lines (115 loc) · 3.7 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
128
129
130
131
132
133
134
135
name: Build and Publish
on:
push:
branches: [main]
tags: ['v*']
pull_request:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
check-latest: true
- name: Vet
run: go vet ./...
- name: Format
run: |
out=$(gofmt -l .)
if [ -n "$out" ]; then echo "gofmt needed:"; echo "$out"; exit 1; fi
- name: Test
run: go test -race ./...
- name: Vulnerability check
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
"$(go env GOPATH)/bin/govulncheck" ./...
- name: Smoke test
run: bash scripts/smoke-test.sh
- name: Build binary
if: startsWith(github.ref, 'refs/tags/v')
run: |
VERSION=$(echo "${GITHUB_REF##*/}" | sed 's/^v//')
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w -X main.version=${VERSION}" \
-o dockify-linux-amd64 \
./cmd/dockify
sha256sum dockify-linux-amd64 > dockify-linux-amd64.sha256
- name: Upload binary
if: startsWith(github.ref, 'refs/tags/v')
uses: actions/upload-artifact@v4
with:
name: dockify-linux-amd64
path: |
dockify-linux-amd64
dockify-linux-amd64.sha256
retention-days: 7
- name: Set up Docker Buildx
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
if: startsWith(github.ref, 'refs/tags/v')
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Build and push Docker image
if: startsWith(github.ref, 'refs/tags/v')
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
build-args: |
VERSION=${{ github.ref_name }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Clean up untagged Docker images
if: startsWith(github.ref, 'refs/tags/v')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PACKAGE=$(echo '${{ github.repository }}' | cut -d'/' -f2)
for id in $(gh api "/user/packages/container/${PACKAGE}/versions" \
--paginate -q '.[] | select(.metadata.container.tags == []) | .id'); do
echo "Deleting untagged version $id"
gh api -X DELETE "/user/packages/container/${PACKAGE}/versions/$id"
done
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download binary
uses: actions/download-artifact@v4
with:
name: dockify-linux-amd64
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: |
dockify-linux-amd64
dockify-linux-amd64.sha256
generate_release_notes: true