-
Notifications
You must be signed in to change notification settings - Fork 44
198 lines (172 loc) · 6.77 KB
/
main.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: Build the Twine game
permissions:
contents: write
on:
push:
branches:
- main
schedule:
- cron: "0 0 */15 * *"
defaults:
run:
shell: bash
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Set game configuration
env:
APP_NAME: My Twine game
DESCRIPTION: My Twine game description
# This must be of the format "N.N.N", where the N's are all numbers
VERSION: 1.0.0
# By default, the author will be your name on GitHub. You can manually change this.
AUTHOR: ${{ github.repository_owner }}
# If this to 'true', a copy of your game will also be hosted on the web at https://USERNAME.github.io/REPO_NAME
# Delete or comment out this line to disable that
PUBLISH_ON_WEB: true
run: |
echo "APP_NAME=${APP_NAME}" >> $GITHUB_ENV
echo "DESCRIPTION=${DESCRIPTION}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "AUTHOR=${AUTHOR}" >> $GITHUB_ENV
echo "PUBLISH_ON_WEB=${PUBLISH_ON_WEB}" >> $GITHUB_ENV
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Test for presence of Windows codesigning secrets
id: vars
shell: bash
run: |
unset HAS_WINDOWS_CREDS
if [[ -n $CERTIFICATE_WINDOWS_PFX ]]; then HAS_WINDOWS_CREDS='true' ; fi
echo set-output name=HAS_WINDOWS_CREDS::${HAS_WINDOWS_CREDS}
env:
CERTIFICATE_WINDOWS_PFX: ${{ secrets.CERTIFICATE_WINDOWS_PFX }}
- name: Check out Electron app template
uses: actions/checkout@v3
with:
repository: lazerwalker/electron-wrapper-template
ref: v1.1.0
path: app
- name: Set up Electron app environment
working-directory: ./app
run: npm install
- name: move webapp into Electron folder
run: |
cp -r ./src/* ./app/src
mv ./icon.png ./app
- name: Generate icons
working-directory: ./app
run: npm run build-icons
- name: Add MacOS certs
if: matrix.os == 'macos-latest'
shell: bash
run: |
if ! [[ -n $CERTIFICATE_OSX_APPLICATION && -n $CERTIFICATE_PASSWORD ]]; then exit 0 ; fi
KEY_CHAIN=build.keychain
CERTIFICATE_P12=certificate.p12
echo $CERTIFICATE_OSX_APPLICATION | base64 --decode > $CERTIFICATE_P12
security create-keychain -p actions $KEY_CHAIN
security default-keychain -s $KEY_CHAIN
security unlock-keychain -p actions $KEY_CHAIN
security import $CERTIFICATE_P12 -k $KEY_CHAIN -P $CERTIFICATE_PASSWORD -T /usr/bin/codesign;
security set-key-partition-list -S apple-tool:,apple: -s -k actions $KEY_CHAIN
rm -fr *.p12
env:
CERTIFICATE_OSX_APPLICATION: ${{ secrets.CERTIFICATE_OSX_APPLICATION }}
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
- name: Add Windows certificate
if: matrix.os == 'windows-latest' && steps.vars.outputs.HAS_WINDOWS_CREDS
id: write_file
uses: timheuer/base64-to-file@v1
with:
fileName: "win-certificate.pfx"
encodedString: ${{ secrets.CERTIFICATE_WINDOWS_PFX }}
- name: Set description and version number
run: |
node -e "\
const fs = require('fs');\
const pkg=require('./app/package.json');\
pkg.description=process.env.DESCRIPTION;\
pkg.version=process.env.VERSION;\
pkg.author=process.env.AUTHOR;\
fs.writeFileSync('./app/package.json',JSON.stringify(pkg,undefined,'\t'));"
- name: Build the app
working-directory: ./app
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_PROVIDER: ${{ secrets.APPLE_PROVIDER }}
CERTIFICATE_NAME: ${{ secrets.CERTIFICATE_NAME }}
WINDOWS_PFX_FILE: ${{ steps.write_file.outputs.filePath }}
WINDOWS_PFX_PASSWORD: ${{ secrets.WINDOWS_PFX_PASSWORD }}
run: npm run make
- name: Publish to GitHub Pages
if: env.PUBLISH_ON_WEB
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./src
# If there is no passed-in tag, we auto-generate one based on run number
# This makes sure a different process (e.g. a Windows build vs Mac build) hasn't created it
- name: Check if auto-generated tag exists
uses: actions/github-script@v4
id: autogeneratedTagExists
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
const result = await github.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${context.runNumber}.0.0`
})
console.log("Found!")
console.log(result)
return true
} catch(e) {
console.log("Failed", e)
return false
}
# TODO: The previous GH script should just create the tag if needed
- name: Create tag if needed
uses: negz/create-tag@v1
if: ${{ !steps.autogeneratedTagExists.outputs.result && !startsWith(github.ref, 'refs/tags/v') }}
with:
version: ${{ format('{0}.0.0', github.run_number) }}
message: Auto-generated by GitHub Actions
token: ${{ secrets.GITHUB_TOKEN }}
# The next two steps are identical, except for explicitly passing in the tag name in the latter
# I wish I knew how to do this in a more elegant way.
# See also: I'd love to abstract out the startsWith() check and generated tag name into variable
- name: Release on GitHub (Built via Tag)
uses: softprops/action-gh-release@v1
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
app/out/**/*.deb
app/out/**/*.dmg
app/out/**/*Setup.exe
app/out/**/*.rpm
app/out/**/*.zip
- name: Release on GitHub (Automated Tag)
uses: softprops/action-gh-release@v1
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ format('{0}.0.0', github.run_number) }}
files: |
app/out/**/*.deb
app/out/**/*.dmg
app/out/**/*Setup.exe
app/out/**/*.rpm
app/out/**/*.zip