-
Notifications
You must be signed in to change notification settings - Fork 1
156 lines (135 loc) · 4.74 KB
/
main.yaml
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: CI
on:
push:
branches: [ "main" ]
env:
GO_VERSION: 1.23.1
permissions: read-all
jobs:
tests:
name: Unit tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- name: Go Test
run: go test -shuffle=on -tags testing -race -v -covermode=atomic -coverprofile=coverage.out ./...
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
codecov_yml_path: .github/codecov.yml
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint
uses: golangci/golangci-lint-action@aaa42aa0628b4ae2578232a66b541047968fac86 # v6.1.0
with:
install-mode: 'goinstall'
version: latest
args: '--build-tags testing'
versioning:
name: Versioning
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
release: ${{ steps.go-semver.outputs.MAIN_NEW_RELEASE }}
semver: ${{ steps.go-semver.outputs.MAIN_SEMVER }}
needs:
- tests
- lint
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: ${{ env.GO_VERSION }}
- name: Set up GPG key
run: |
mkdir -p ~/secrets
echo "${{ secrets.GPG_PRIVATE_KEY }}" > ~/secrets/private.asc
GO_SEMVER_GPG_KEY_PATH="${HOME}/secrets/private.asc"
chmod 600 "${GO_SEMVER_GPG_KEY_PATH}"
echo "GO_SEMVER_GPG_KEY_PATH=${GO_SEMVER_GPG_KEY_PATH}" >> $GITHUB_ENV
- name: Download latest stable release
run: |
chmod +x ./build/download_latest_release.sh
bash ./build/download_latest_release.sh
- name: Go Semver Release
id: go-semver
run: |
if [ ! -f "${GO_SEMVER_GPG_KEY_PATH}" ]; then
echo "Error: GPG key file not found at ${GO_SEMVER_GPG_KEY_PATH}"
exit 1
fi
./go-semver-release-linux-amd64 release https://github.com/s0ders/go-semver-release.git \
--config .semver.yaml \
--access-token ${{ secrets.GO_SEMVER_RELEASE_ACCESS_TOKEN }} \
--gpg-key-path "${GO_SEMVER_GPG_KEY_PATH}" \
--verbose
docker-release:
name: Docker release
runs-on: ubuntu-latest
permissions:
contents: read
needs:
- versioning
if: ${{needs.versioning.outputs.release == 'true'}}
env:
VERSION: ${{needs.versioning.outputs.semver}}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
- name: Login to Docker Hub
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker build
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: .
file: ./build/Dockerfile
push: true
build-args: |
APP_VERSION="${{ env.VERSION }}"
APP_BUILD_NUMBER="${{ github.run_id }}"
APP_COMMIT_HASH="${{ github.sha }}"
tags: s0ders/go-semver-release:${{ env.VERSION }}
slsa-build:
name: SLSA build and release
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
needs:
- versioning
- docker-release
if: ${{needs.versioning.outputs.release == 'true'}}
strategy:
matrix:
os:
- linux
- windows
- darwin
arch:
- amd64
- arm64
permissions:
id-token: write
contents: write
actions: read
with:
go-version: 1.23
config-file: .github/slsa-goreleaser/${{ matrix.os }}-${{ matrix.arch }}.yml
evaluated-envs: "VERSION:${{ needs.versioning.outputs.semver }}, COMMIT_HASH:${{ github.sha }}, BUILD_NUMBER:${{ github.run_id }}"
upload-assets: true
upload-tag-name: ${{ needs.versioning.outputs.semver }}