1
- name : nightly_binaries
1
+ # A reusable workflow that builds and archives binaries for multiple platforms.
2
+ name : Build Binaries
2
3
3
4
on :
5
+ workflow_call :
6
+ inputs :
7
+ checksum :
8
+ description : Generate a SHA256 checksum for the archives
9
+ type : boolean
10
+ default : true
11
+
12
+ combine :
13
+ description : Create a `binaries` artifact containing all artifacts.
14
+ type : boolean
15
+ default : false
16
+
4
17
workflow_dispatch :
18
+ inputs :
19
+ checksum :
20
+ description : Generate a SHA256 checksum for the archives
21
+ type : boolean
22
+ default : true
23
+
24
+ combine :
25
+ description : Create a `binaries` artifact containing all artifacts.
26
+ type : boolean
27
+ default : false
28
+
29
+ push :
30
+ branches :
31
+ - " *"
32
+ tags :
33
+ - " *"
34
+ pull_request :
35
+ branches :
36
+ - " *"
5
37
6
38
jobs :
7
- nightly_binaries :
8
- runs-on : ubuntu-22.04
39
+ build :
40
+ runs-on : ubuntu-latest
41
+
42
+ env :
43
+ CGO_ENABLED : 0
44
+ BINARY_NAME : mediamtx
45
+
46
+ outputs :
47
+ combine : ${{ env.COMBINE }}
48
+
49
+ strategy :
50
+ matrix :
51
+ include :
52
+ - goos : windows
53
+ goarch : amd64
54
+ binary_extension : .exe
55
+ archive_suffix : windows_amd64.zip
56
+
57
+ - goos : windows
58
+ goarch : arm
59
+ binary_extension : .exe
60
+ archive_suffix : windows_arm.zip
61
+
62
+ - goos : windows
63
+ goarch : arm64
64
+ binary_extension : .exe
65
+ archive_suffix : windows_arm64.zip
66
+
67
+ - goos : linux
68
+ goarch : amd64
69
+ archive_suffix : linux_amd64.tar.gz
70
+
71
+ - goos : darwin
72
+ goarch : amd64
73
+ archive_suffix : darwin_amd64.tar.gz
74
+
75
+ - goos : darwin
76
+ goarch : arm64
77
+ archive_suffix : darwin_arm64.tar.gz
78
+
79
+ - goos : linux
80
+ goarch : arm
81
+ goarm : 6
82
+ archive_suffix : linux_armv6.tar.gz
83
+
84
+ - goos : linux
85
+ goarch : arm
86
+ goarm : 7
87
+ archive_suffix : linux_armv7.tar.gz
88
+
89
+ - goos : linux
90
+ goarch : arm64
91
+ goarm : 8
92
+ archive_suffix : linux_arm64v8.tar.gz
9
93
10
94
steps :
95
+ - name : Set checksum environment variable
96
+ run : |
97
+ if [[ ! -z "${{ inputs.checksum }}" ]]; then
98
+ if [[ "${{ inputs.checksum }}" == "true" ]]; then
99
+ echo "CHECKSUM=1" >> $GITHUB_ENV
100
+ else
101
+ echo "CHECKSUM=0" >> $GITHUB_ENV
102
+ fi
103
+ else
104
+ # Check if the event is a push or pull request
105
+ if [ "${{ github.event_name }}" == "push" ] || [[ "${{ github.event_name }}" == "pull_request" ]]; then
106
+ echo "CHECKSUM=1" >> $GITHUB_ENV
107
+ else
108
+ echo "CHECKSUM=0" >> $GITHUB_ENV
109
+ fi
110
+ fi
111
+
11
112
- uses : actions/checkout@v4
12
113
with :
114
+ submodules : recursive
115
+ lfs : true
13
116
fetch-depth : 0
117
+ tags : true
118
+
119
+ - name : Setup go
120
+ uses : actions/setup-go@v5
121
+ with :
122
+ go-version : 1.23
14
123
15
- - run : make binaries
124
+ - name : Go module setup
125
+ run : go mod download
126
+
127
+ - name : Go generate
128
+ run : go generate ./...
129
+
130
+ - name : Get build info
131
+ id : info
132
+ run : |
133
+ VERSION="$(cat internal/core/VERSION)"
134
+
135
+ echo "version=${VERSION}" | tee -a $GITHUB_OUTPUT
136
+ echo "archive_name=${{ env.BINARY_NAME }}_${VERSION}_${{ matrix.archive_suffix}}" | tee -a $GITHUB_OUTPUT
137
+
138
+ - name : Go build
139
+ run : go build -o "build/${{ env.BINARY_NAME }}${{ matrix.binary_extension }}" .
16
140
env :
17
- CHECKSUM : ' 1'
141
+ GOOS : ${{ matrix.goos }}
142
+ GOARCH : ${{ matrix.goarch }}
143
+ GOARM : ${{ matrix.goarm }}
144
+
145
+ - name : Archive binary
146
+ run : |
147
+ mkdir -p build
148
+ cp mediamtx.yml LICENSE build/
149
+ cd build
150
+
151
+ if [[ "${{ matrix.archive_suffix }}" == *.tar.gz ]]; then
152
+ tar -czvf "${{ steps.info.outputs.archive_name }}" --owner=0 --group=0 *
153
+ else
154
+ zip "${{ steps.info.outputs.archive_name }}" *
155
+ fi
156
+
157
+ if [ "${{ env.CHECKSUM }}" == "1" ]; then
158
+ sha256sum "${{ steps.info.outputs.archive_name }}" > "${{ steps.info.outputs.archive_name }}.sha256sum"
159
+ fi
18
160
19
161
- uses : actions/upload-artifact@v4
20
162
with :
21
- name : binaries
163
+ name : ${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }}
164
+ if-no-files-found : error
165
+ path : |
166
+ build/${{ steps.info.outputs.archive_name }}
167
+ build/${{ steps.info.outputs.archive_name }}.sha256sum
168
+
169
+ combine :
170
+ runs-on : ubuntu-latest
171
+ if : inputs.combine == true
172
+ needs : build
173
+
174
+ steps :
175
+ - uses : actions/download-artifact@v4
176
+ with :
22
177
path : binaries
178
+
179
+ - name : Flatten directory structure
180
+ run : |
181
+ mkdir -p flat_binaries
182
+ find binaries -type f -exec mv {} flat_binaries/ \;
183
+
184
+ - uses : actions/upload-artifact@v4
185
+ with :
186
+ name : binaries
187
+ path : flat_binaries/*
0 commit comments