-
Notifications
You must be signed in to change notification settings - Fork 1
198 lines (188 loc) · 6.79 KB
/
release.yml
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: release
# run only when pushing v-prefixed SemVer tags (e.g. v1.0.0, v2.0.1, and etc.)
on:
push:
tags:
- "v*"
env:
app-name: chibisnes
app-arch: x86_64
jobs:
# run app build for each OS in parallel
build:
name: Build
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
release-dir: _release
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ^1.18
- name: Get Linux dev libraries and tools
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get -qq update
sudo apt-get -qq install -y make pkg-config
sudo apt-get -qq install -y libx11-dev xorg-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev
sudo apt-get -qq install -y libglfw3 libglfw3-dev
sudo apt-get -qq install -y libsdl2-dev
- name: Get MacOS dev libraries and tools
if: matrix.os == 'macos-latest'
run: |
brew install pkg-config glfw sdl2
- name: Get Windows dev libraries and tools
if: matrix.os == 'windows-latest'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
path-type: inherit
release: false
install: >
mingw-w64-x86_64-gcc
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-glfw
mingw-w64-x86_64-SDL2
- name: Build Linux app
if: matrix.os == 'ubuntu-latest'
run: |
CGO_ENABLED=1 go build -o _release/chibisnes cmd/chibisnes/main.go
- name: Build macOS app
if: matrix.os == 'macos-latest'
run: |
mkdir -p build/macosx/ChibiSNES.app/Contents/MacOS/
CGO_ENABLED=1 go build -o build/macosx/ChibiSNES.app/Contents/MacOS/chibisnes cmd/chibisnes/main.go
cp /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib build/macosx/ChibiSNES.app/Contents/MacOS/
install_name_tool -change /usr/local/opt/sdl2/lib/libSDL2-2.0.0.dylib @executable_path/libSDL2-2.0.0.dylib build/macosx/ChibiSNES.app/Contents/MacOS/chibisnes
mkdir _release
cp -r build/macosx/ChibiSNES.app _release/ChibiSNES.app
chmod +x _release/ChibiSNES.app/Contents/MacOS/chibisnes
- name: Build Windows app
if: matrix.os == 'windows-latest'
shell: msys2 {0}
run: |
CGO_ENABLED=1 go build -o _release/chibisnes.exe cmd/chibisnes/main.go
cp /mingw64/bin/glfw3.dll _release/
cp /mingw64/bin/libatomic-1.dll _release/
cp /mingw64/bin/libgcc_s_seh-1.dll _release/
cp /mingw64/bin/libgmp-10.dll _release/
cp /mingw64/bin/libgmpxx-4.dll _release/
cp /mingw64/bin/libgomp-1.dll _release/
cp /mingw64/bin/libquadmath-0.dll _release/
cp /mingw64/bin/libssp-0.dll _release/
cp /mingw64/bin/libstdc++-6.dll _release/
cp /mingw64/bin/libwinpthread-1.dll _release/
cp /mingw64/bin/SDL2.dll _release/
- name: Save built app for upload
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}
path: ${{ env.release-dir }}
release:
name: Create or find Github release
needs: build
runs-on: ubuntu-latest
steps:
- name: Trying to find existing release
uses: actions/[email protected]
id: release_search
with:
github-token: ${{secrets.GITHUB_TOKEN}}
result-encoding: string
script: |
try {
const release = await github.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.ref.replace('refs/tags/', '')
});
return release.data.upload_url;
} catch (ignored) {}
return '';
- name: Create new release maybe?
id: create_release
if: steps.release_search.outputs.result == ''
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
# pass assets upload url of existing or new release
# between jobs (VMs) through txt files
- name: Get release upload URL
run: |
echo '${{ steps.create_release.outputs.upload_url }}${{ steps.release_search.outputs.result }}' > upload_url
- name: Save release upload URL
uses: actions/upload-artifact@v3
with:
name: upload_url
path: ./
publish:
name: Publish
needs: release
strategy:
matrix:
# should be same as runner.os
target-os: [Linux, macOS, Windows]
include:
- target-os: Linux
compress: tar -zcf
archive-ext: tar.gz
archive-mime: tar
- target-os: macOS
compress: tar -zcf
archive-ext: tar.gz
archive-mime: tar
- target-os: Windows
compress: zip -qq -r
archive-ext: zip
archive-mime: zip
runs-on: ubuntu-latest
steps:
- name: Get version tag
id: get_version
run: |
echo ::set-output name=version::${GITHUB_REF#refs/tags/}
- name: Get release upload url
uses: actions/download-artifact@v3
with:
name: upload_url
- name: Read release upload url
id: upload_url
run: |
ls
value=`cat upload_url`
echo "::set-output name=url::$value"
- name: Get the build
uses: actions/download-artifact@v3
with:
name: ${{ matrix.target-os }}
- name: Add permission for MacOS
if: matrix.target-os == 'macOS'
run: |
chmod +x ChibiSNES.app/Contents/MacOS/chibisnes
- name: Compress the build
id: compress
# compress all the files without a parent dir
# (cd into arch dir -> make archive in its parent -> go back)
run: |
rm upload_url
archive='${{ env.app-name }}-${{ steps.get_version.outputs.version }}-${{ matrix.target-os }}-${{ env.app-arch }}'
compress='${{ matrix.compress }} ./${archive,,}.${{ matrix.archive-ext }} *'
eval $compress
echo ::set-output name=archive_name::${archive,,}.${{ matrix.archive-ext }}
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.upload_url.outputs.url }}
asset_path: ./${{ steps.compress.outputs.archive_name }}
asset_name: ${{ steps.compress.outputs.archive_name }}
asset_content_type: application/${{ matrix.archive-mime }}