Skip to content

Commit 1dd17f0

Browse files
committed
Add a GH action to create release binaries
Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 159a7b2 commit 1dd17f0

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Release Binaries
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Tag to build and publish'
11+
required: true
12+
type: string
13+
14+
jobs:
15+
build-and-release:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write # Needed for creating GitHub releases
19+
packages: read
20+
21+
strategy:
22+
matrix:
23+
goos: [linux]
24+
goarch: [amd64, arm64]
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
with:
30+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
31+
fetch-depth: 0 # Fetch all history for proper versioning
32+
33+
- name: Set up Go
34+
uses: actions/setup-go@v5
35+
with:
36+
go-version: '1.24'
37+
cache: true
38+
39+
- name: Set VERSION environment variable
40+
run: |
41+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
42+
echo "VERSION=${{ inputs.tag }}" >> $GITHUB_ENV
43+
else
44+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
45+
fi
46+
47+
- name: Build binary
48+
env:
49+
GOOS: ${{ matrix.goos }}
50+
GOARCH: ${{ matrix.goarch }}
51+
OUTPUT_NAME_WITH_ARCH: "true"
52+
BUILD_USER: "github-actions"
53+
BUILD_DATE: ${{ github.event.repository.updated_at }}
54+
GO_FLAGS: "-tags=netgo"
55+
run: ./build/build.sh
56+
57+
- name: Prepare binary for upload
58+
run: |
59+
cd _output
60+
sha256sum cadvisor-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }} > cadvisor-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}.sha256
61+
62+
- name: Upload artifacts
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: cadvisor-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}
66+
path: |
67+
_output/cadvisor-${{ env.VERSION }}-${{ matrix.goos }}-${{ matrix.goarch }}*
68+
retention-days: 1
69+
70+
create-release:
71+
needs: build-and-release
72+
runs-on: ubuntu-latest
73+
permissions:
74+
contents: write # Needed for creating GitHub releases
75+
steps:
76+
- name: Checkout repository
77+
uses: actions/checkout@v4
78+
with:
79+
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
80+
81+
- name: Set VERSION environment variable
82+
run: |
83+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
84+
echo "VERSION=${{ inputs.tag }}" >> $GITHUB_ENV
85+
else
86+
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
87+
fi
88+
89+
- name: Download all artifacts
90+
uses: actions/download-artifact@v4
91+
with:
92+
path: artifacts
93+
94+
- name: Display structure of downloaded files
95+
run: ls -R artifacts
96+
97+
- name: Create Release
98+
id: create_release
99+
uses: softprops/action-gh-release@v2
100+
with:
101+
tag_name: ${{ env.VERSION }}
102+
name: cAdvisor ${{ env.VERSION }}
103+
draft: false
104+
prerelease: ${{ contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta') || contains(env.VERSION, 'rc') }}
105+
generate_release_notes: true
106+
files: |
107+
artifacts/**/*

0 commit comments

Comments
 (0)