1212 GO_VERSION : " 1.24.3"
1313
1414jobs :
15+ version :
16+ runs-on : ubuntu-latest
17+ outputs :
18+ VERSION : ${{ steps.setver.outputs.VERSION }}
19+ DATE : ${{ steps.setver.outputs.DATE }}
20+ steps :
21+ - uses : actions/checkout@v4
22+ - id : setver
23+ run : |
24+ if [[ "${{ github.ref_type }}" == "tag" ]]; then
25+ VERSION=${GITHUB_REF_NAME#v}
26+ elif [ -f .version ]; then
27+ VERSION=$(cat .version)
28+ else
29+ VERSION="dev-${GITHUB_SHA::8}"
30+ fi
31+ echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
32+ echo "DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_OUTPUT
33+
1534 test :
1635 name : Test
1736 runs-on : ubuntu-latest
37+ needs : [version]
1838 steps :
1939 - uses : actions/checkout@v4
2040
@@ -152,7 +172,7 @@ jobs:
152172 build :
153173 name : Build
154174 runs-on : ubuntu-latest
155- needs : test
175+ needs : [ test, version]
156176 if : always() && (needs.test.result == 'success')
157177 strategy :
158178 matrix :
@@ -215,9 +235,9 @@ jobs:
215235 BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
216236
217237 go build -v -ldflags="-w -s \
218- -X github.com/ofkm/arcane-agent/internal/version.Version=${{ steps .version.outputs.VERSION }} \
238+ -X github.com/ofkm/arcane-agent/internal/version.Version=${{ needs .version.outputs.VERSION }} \
219239 -X github.com/ofkm/arcane-agent/internal/version.Commit=${GITHUB_SHA} \
220- -X github.com/ofkm/arcane-agent/internal/version.Date=${BUILD_DATE }" \
240+ -X github.com/ofkm/arcane-agent/internal/version.Date=${{ needs.version.outputs.DATE } }" \
221241 -o bin/${{ env.BINARY_NAME }}-${{ matrix.platform }}${{ matrix.extension }} \
222242 ./cmd/agent
223243
@@ -231,7 +251,7 @@ jobs:
231251 docker :
232252 name : Build Docker Image
233253 runs-on : ubuntu-latest
234- needs : test
254+ needs : [ test, version]
235255 if : github.event_name == 'push'
236256
237257 steps :
@@ -260,7 +280,7 @@ jobs:
260280 type=semver,pattern={{major}}.{{minor}}
261281 type=semver,pattern={{major}}
262282 type=sha
263- type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
283+ type=raw,value=latest
264284
265285 - name : Build and push Docker image
266286 uses : docker/build-push-action@v6
@@ -272,6 +292,10 @@ jobs:
272292 labels : ${{ steps.meta.outputs.labels }}
273293 cache-from : type=gha
274294 cache-to : type=gha,mode=max
295+ build-args : |
296+ VERSION=${{ needs.version.outputs.VERSION }}
297+ COMMIT=${{ github.sha }}
298+ DATE=${{ needs.version.outputs.DATE }}
275299
276300 auto-release :
277301 name : Auto Release
0 commit comments