1
+ name : Cross Platform build
2
+
3
+ on : [push, pull_request]
4
+
5
+ jobs :
6
+ build_linux :
7
+ runs-on : ubuntu-18.04
8
+ strategy :
9
+ matrix :
10
+ version : ['linux-armhf', 'linux-arm64', 'linux-i386', 'linux-amd64']
11
+ include :
12
+ # add the GO naming convention for OS ($GOOS) and architecture ($GOARCH)
13
+ # instead of using Linux' naming convention (version items).
14
+ - version : linux-armhf
15
+ OS : linux
16
+ ARCH : arm
17
+ - version : linux-arm64
18
+ OS : linux
19
+ ARCH : arm64
20
+ - version : linux-i386
21
+ OS : linux
22
+ ARCH : ' 386'
23
+ - version : linux-amd64
24
+ OS : linux
25
+ ARCH : amd64
26
+ steps :
27
+ - uses : actions/checkout@v1
28
+ with :
29
+ submodules : true
30
+ - name : Build binary for ${{ matrix.version }}
31
+ run : |
32
+ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp dh1tw/remoteaudio-xcompile:${{ matrix.version }} /bin/sh -c 'make dist'
33
+ - name : Prepare build artifact for stashing
34
+ run : |
35
+ mkdir release
36
+ mv ./remoteAudio ./release
37
+ # The build artifact can be identified by the trailing sha of the git commit
38
+ - name : Stash the build artifact
39
+ uses : actions/upload-artifact@v1
40
+ with :
41
+ name : remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}
42
+ path : ./release
43
+
44
+ build_macos :
45
+ runs-on : macos-latest
46
+ steps :
47
+ - uses : actions/checkout@v1
48
+ with :
49
+ submodules : true
50
+ - name : Install dependencies
51
+ run : |
52
+ brew install pkg-config
53
+ brew install opus
54
+ brew install opusfile
55
+ brew install portaudio
56
+ brew install protobuf
57
+ brew install libsamplerate
58
+ brew install upx
59
+ - name : Install code generators
60
+ run : make install-deps
61
+ - name : Build binary for macOS
62
+ run : |
63
+ export PATH=/System/Volumes/Data/Users/runner/go/bin:$PATH
64
+ make dist
65
+ - name : Prepare build artifact for stashing
66
+ run : |
67
+ mkdir release
68
+ mv ./remoteAudio ./release
69
+ # The build artifact can be identified by the trailing sha of the git commit
70
+ - name : Stash the build artifact
71
+ uses : actions/upload-artifact@v1
72
+ with :
73
+ name : remoteAudio-darwin-amd64-${{ github.sha }}
74
+ path : ./release
75
+
76
+ build_windows :
77
+ runs-on : ubuntu-18.04
78
+ strategy :
79
+ matrix :
80
+ version : ['windows-amd64', 'windows-i386']
81
+ include :
82
+ # add the GO naming convention for OS ($GOOS) and architecture ($GOARCH)
83
+ # instead of using Linux' naming convention (version items).
84
+ - version : windows-amd64
85
+ OS : windows
86
+ ARCH : amd64
87
+ - version : windows-i386
88
+ OS : windows
89
+ ARCH : ' 386'
90
+ steps :
91
+ - uses : actions/checkout@v1
92
+ with :
93
+ submodules : true
94
+ - name : Build binary for ${{ matrix.version }}
95
+ run : |
96
+ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp dh1tw/remoteaudio-xcompile:${{ matrix.version }} /bin/sh -c 'make dist && /scripts/getlibs.sh .'
97
+ - name : Prepare build artifacts for stashing
98
+ run : |
99
+ mkdir release
100
+ mv ./remoteAudio.exe ./release
101
+ mv ./*.dll ./release
102
+ # The build artifact can be identified by the trailing sha of the git commit
103
+ - name : Stash the build artifact
104
+ uses : actions/upload-artifact@v1
105
+ with :
106
+ name : remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}
107
+ path : ./release
108
+
109
+ # A Github release is created whenever the git reference contains a tag, starting with 'v*' (e.g. v0.4.2)
110
+ # And the previous build jobs have been successful
111
+ create_release :
112
+ runs-on : ubuntu-18.04
113
+ needs : [build_linux, build_macos, build_windows]
114
+ if : startsWith(github.ref, 'refs/tags/v')
115
+ steps :
116
+ - name : Create Release
117
+ id : create_release
118
+ uses : actions/create-release@v1.0.0
119
+ env :
120
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
121
+ with :
122
+ tag_name : ${{ github.ref }}
123
+ release_name : Release ${{ github.ref }}
124
+ draft : true
125
+ prerelease : false
126
+ # since jobs can not share any variables we have to copy the URL of the created Github release
127
+ # into a file and stash it as an artifact
128
+ - name : Copy release URL into file
129
+ run : |
130
+ mkdir release
131
+ printf "%s" "${{ steps.create_release.outputs.upload_url }}" > release/url.txt
132
+ - name : Stash file containing the release URL as an artifact
133
+ uses : actions/upload-artifact@v1
134
+ with :
135
+ name : release-url
136
+ path : ./release
137
+
138
+ # In this job we upload the release artifacts to the corresponding release
139
+ upload :
140
+ runs-on : ubuntu-18.04
141
+ needs : create_release # release must be created before this job can start
142
+ strategy :
143
+ matrix :
144
+ version : ['linux-armhf', 'linux-arm64', 'linux-i386', 'linux-amd64', 'darwin-amd64', 'windows-amd64', 'windows-i386']
145
+ # add the GO naming convention for OS ($GOOS) and architecture ($GOARCH)
146
+ # instead of using Linux' naming convention (version items).
147
+ include :
148
+ - version : linux-armhf
149
+ OS : linux
150
+ ARCH : arm
151
+ - version : linux-arm64
152
+ OS : linux
153
+ ARCH : arm64
154
+ - version : linux-i386
155
+ OS : linux
156
+ ARCH : ' 386'
157
+ - version : linux-amd64
158
+ OS : linux
159
+ ARCH : amd64
160
+ - version : darwin-amd64
161
+ OS : darwin
162
+ ARCH : amd64
163
+ - version : windows-amd64
164
+ OS : windows
165
+ ARCH : amd64
166
+ - version : windows-i386
167
+ OS : windows
168
+ ARCH : ' 386'
169
+ steps :
170
+ # Since Github actions (currently) doesn't provide a slugged version of the git tag we have to
171
+ # create it by ourselves. It is then made available to other steps in this job as a step.outputs
172
+ # variable
173
+ - name : Get the version (git tag)
174
+ id : get_version
175
+ run : |
176
+ echo ${GITHUB_REF/refs\/tags\//}
177
+ echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
178
+ - name : Retrieve stashed intermediary build artifact
179
+ uses : actions/download-artifact@v1
180
+ with :
181
+ name : remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}
182
+ # rename the retrieved intermediary artifact and prepare zip file
183
+ - name : Prepare release artifact
184
+ env :
185
+ VERSION : ${{ steps.get_version.outputs.VERSION }}
186
+ run : |
187
+ mv ./remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}/* .
188
+ test -f ./remoteAudio && chmod +x ./remoteAudio #only on linux & darwin needed
189
+ zip -j remoteAudio-$VERSION-${{ matrix.OS }}-${{ matrix.ARCH }}.zip ./*
190
+ # Download the previously uploaded artifact which contains the release URL
191
+ - name : Retrieve stashed release URL
192
+ uses : actions/download-artifact@v1
193
+ with :
194
+ name : release-url
195
+ # Write content of downloaded file (a string which contains the release URL) into a step.outputs variable
196
+ - name : Read release URL
197
+ id : get_release_url
198
+ run : echo ::set-output name=URL::$(cat release-url/url.txt)
199
+ # This step is only needed because the upload-release-asset currently doesn't support
200
+ # environment variables. Therefore they must be written and referenced through step.outputs
201
+ - name : Prepare artifact metadata
202
+ id : prepare_artifact_metadata
203
+ env :
204
+ VERSION : ${{ steps.get_version.outputs.VERSION }}
205
+ run : |
206
+ echo ::set-output name=ARTIFACT_PATH::./remoteAudio-$VERSION-${{ matrix.OS }}-${{ matrix.ARCH }}.zip
207
+ echo ::set-output name=ARTIFACT_NAME::remoteAudio-$VERSION-${{ matrix.OS }}-${{ matrix.ARCH }}.zip
208
+ # Finally upload the artifact to the corresponding release
209
+ - name : Upload Release Artifact ${{ matrix.version }}
210
+ uses : actions/upload-release-asset@v1.0.1
211
+ env :
212
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
213
+ with :
214
+ upload_url : ${{ steps.get_release_url.outputs.URL }}
215
+ asset_path : ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_PATH }}
216
+ asset_name : ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_NAME }}
217
+ asset_content_type : application/gzip
0 commit comments