-
-
Notifications
You must be signed in to change notification settings - Fork 0
231 lines (198 loc) · 7.01 KB
/
main.yaml
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: main
env:
LANG: C.UTF-8
GH_TOKEN: ${{ github.token }}
on:
push:
branches: main
pull_request:
branches: main
permissions:
contents: write
packages: write
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build on ${{ matrix.os }} using GHC ${{ matrix.ghc-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# os: [ubuntu-24.04, macos-15, windows-2022]
os: [ubuntu-24.04]
ghc-version: ['9.6.6']
cabal-version: ['3.12.1.0']
env:
platform: ${{ startsWith(matrix.os, 'ubuntu') && 'x86_64-linux' ||
startsWith(matrix.os, 'macos') && 'arm64-macos' ||
startsWith(matrix.os, 'windows') && 'x86_64-windows' }}
outputs:
new-version: ${{ steps.version-bump.outputs.new-version }}
steps:
- uses: actions/checkout@v4
- name: Set up GHC ${{ matrix.ghc-version }} (MacOS and Windows only)
if: ${{ env.platform != 'x86_64-linux' }}
uses: haskell-actions/setup@v2
id: setup
with:
ghc-version: ${{ matrix.ghc-version }}
cabal-version: ${{ matrix.cabal-version }}
cabal-update: false
- name: Install make (Windows only)
if: ${{ env.platform == 'x86_64-windows' }}
run: choco install make
# Use Alpine container to get static binaries on Linux.
- name: Login to GitHub Container Registry (Linux only)
if: ${{ env.platform == 'x86_64-linux' }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Pull image (Linux only)
if: ${{ env.platform == 'x86_64-linux' }}
run: make pull-image
- name: Build image (Linux only)
if: ${{ env.platform == 'x86_64-linux' }}
env:
GITHUB_EVENT_BEFORE: ${{ github.event.before }}
GITHUB_EVENT_AFTER: ${{ github.event.after }}
run: make build-image
- name: Push image (Linux only)
# Don't push on PRs.
if: ${{ env.platform == 'x86_64-linux' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/main' }}
run: make push-image
- name: Configure and create build plan
run: make dist-newstyle/cache/plan.json
# XXX: Use a separate step to create the path, using >> GITHUB_ENV
# if the caches are not all in the same directories on all OSes...
# '/home/runner/.cache/cabal/packages\n /home/runner/.cabal/store\n dist-newstyle' ||
- name: Restore cached dependencies
uses: actions/cache/restore@v4
id: cache
env:
key: ${{ runner.os }}-ghc-${{ matrix.ghc-version }}-cabal-${{ matrix.cabal-version }}
with:
path: ${{ env.platform == 'x86_64-linux' &&
'/home/runner/.cabal/store' ||
steps.setup.outputs.cabal-store }}
key: ${{ env.key }}-plan-${{ hashFiles('dist-newstyle/cache/plan.json') }}
restore-keys: ${{ env.key }}-plan-
- name: Build dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: make build-deps
- name: Debug .cabal cache
shell: bash
#if: ${{ env.platform != 'x86_64-windows' }}
run: |
ls -Rlh ${HOME}/.cabal || true
- name: Debug .cabal/store cache
shell: bash
#if: ${{ env.platform != 'x86_64-windows' }}
run: |
echo ${{ steps.setup.outputs.cabal-store }}
ls -Rlh ${{ steps.setup.outputs.cabal-store }} || true
echo "==="
ls -Rlh ${HOME}/.cabal/store || true
- name: Debug dist-newstyle cache
shell: bash
#if: ${{ env.platform != 'x86_64-windows' }}
run: |
ls -Rlh dist-newstyle || true
# Cache dependencies already here, so that we do not have to rebuild them
# should the subsequent steps fail.
- name: Save cached dependencies
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v4
with:
path: ${{ env.platform == 'x86_64-linux' &&
'/home/runner/.cabal/store' ||
steps.setup.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}
- name: Build
env:
SPEX_GIT_COMMIT: ${{ github.sha }}
run: make build
- name: Test
run: make test
- name: Check for version bump
id: version-bump
run: make bump
- name: Install binaries
# Only if there's a version bump and we are merging to main, i.e
# exclude PRs.
if: ${{ steps.version-bump.outputs.new-version != '' &&
github.event_name == 'push' &&
github.ref == 'refs/heads/main' }}
id: install
run: make install
- name: Install upx (Windows only)
if: ${{ env.platform == 'x86_64-windows' &&
steps.install.outcome == 'success' }}
run: choco install upx
# upx: CantPackException: macOS is currently not supported
# - name: Install upx (MacOS only)
# if: ${{ env.platform == 'arm64-macos' }}
# run: brew install upx
- name: Compress binaries (Linux and Windows only)
if: ${{ env.platform != 'arm64-macos' &&
steps.install.outcome == 'success' }}
run: make compress
- name: Upload binary artifacts
if: steps.install.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: ${{ env.platform }}
path: dist-newstyle/bin/*
if-no-files-found: error
release:
name: Create release
runs-on: ubuntu-latest
needs: build
# Exclude PRs.
if: ${{ needs.build.outputs.new-version &&
github.event_name == 'push' &&
github.ref == 'refs/heads/main' }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
spex.cabal
cabal.project
Makefile
CHANGELOG.md
sparse-checkout-cone-mode: false
- name: Download binary artifacts
uses: actions/download-artifact@v4
with:
path: dist-newstyle/bin/
- name: Create release
env:
NEW_VERSION: ${{ needs.build.outputs.new-version }}
run: make release
smoke-test:
name: Smoke test on ${{ matrix.os }}
needs: release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-24.04, macos-15, windows-2022]
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
spex.cabal
cabal.project
Makefile
sparse-checkout-cone-mode: false
- name: Download and run spexup
env:
GH_TOKEN: ${{ github.token }}
run: make spexup
- name: Smoke test `spex --version`
run: make smoke