-
Notifications
You must be signed in to change notification settings - Fork 55
197 lines (169 loc) · 6.53 KB
/
snap.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
name: Pebble snap
on:
pull_request:
branches: [master]
push:
branches: [master]
release:
types: [published]
# We don't want this workflow to have multiple runs in parallel because
# what could happen is that a slow-running and older execution will upload
# an older snap to `edge`, after the newer and latest snap has already been released.
concurrency: ${{ github.workflow }}
env:
SNAP_NAME: pebble
DEFAULT_TRACK: latest
DEFAULT_RISK: edge
jobs:
local-build:
runs-on: ubuntu-latest
# PRS usually come from forks, which are not allowed to access repo secrets.
# So this job builds the snap locally, and not via LP.
if: github.event_name == 'pull_request'
steps:
- name: Checkout Pebble repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
# Generate the version for the local snap build.
- run: go generate ./cmd
- name: Build ${{ env.SNAP_NAME }} Snap
id: build-snap
uses: snapcore/[email protected]
- uses: actions/upload-artifact@v3
if: failure()
with:
name: snapcraft-logs
path: |
~/.cache/snapcraft/log/
~/.local/state/snapcraft/log/
${{ env.SNAP_NAME }}_*.txt
- name: Attach ${{ steps.build-snap.outputs.snap }} to GH workflow execution
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build-snap.outputs.snap }}
path: ${{ steps.build-snap.outputs.snap }}
remote-build:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
strategy:
fail-fast: true
matrix:
arch: ["amd64", "arm64", "ppc64el", "armhf", "s390x"]
steps:
- name: Checkout Pebble repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set LP credentials for remote build
run: |
lp_creds_path="$HOME/.local/share/snapcraft/"
mkdir -p $lp_creds_path
echo '${{ secrets.LP_CREDENTIALS }}' > ${lp_creds_path}/launchpad-credentials
git config --global user.email "${{ secrets.PEBBLE_DEV_MAILING_LIST}}"
git config --global user.name "pebble-dev"
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
# Ensure Snapcraft will ship the generated version files to LP.
- run: |
go generate ./cmd
git add -f ./cmd/VERSION ./cmd/version_generated.go
- name: Build ${{ env.SNAP_NAME }} Snap for ${{ matrix.arch }}
id: build-snap
uses: snapcore/[email protected]
with:
snapcraft-args: remote-build --build-for=${{ matrix.arch }} --launchpad-accept-public-upload
- uses: actions/upload-artifact@v3
if: failure()
with:
name: snapcraft-logs
path: |
~/.cache/snapcraft/log/
~/.local/state/snapcraft/log/
${{ env.SNAP_NAME }}_*.txt
- name: Attach ${{ steps.build-snap.outputs.snap }} to GH workflow execution
uses: actions/upload-artifact@v3
if: steps.build-snap.outcome == 'success'
with:
name: ${{ steps.build-snap.outputs.snap }}
path: ${{ steps.build-snap.outputs.snap }}
test:
runs-on: ubuntu-latest
needs: [local-build, remote-build]
env:
# Testing is only enabled on amd64. We can add arm64 once we have such runners.
TEST_ON: amd64
if: |
always() &&
(needs.local-build.result == 'success' || needs.local-build.result == 'skipped') &&
(needs.remote-build.result == 'success' || needs.remote-build.result == 'skipped')
steps:
- uses: actions/download-artifact@v3
- id: get-snap
run: echo "filename=$(find ${{ env.SNAP_NAME }}*${{ env.TEST_ON }}*snap/*)" >> $GITHUB_OUTPUT
- name: Install and test ${{ steps.get-snap.outputs.filename }}
run: |
set -ex
sudo snap install --dangerous --classic ${{ steps.get-snap.outputs.filename }}
# Make sure it is installed
pebble version --client
# Run smoke test
pebble enter --create-dirs exec echo Hello | grep Hello
release:
runs-on: ubuntu-latest
needs: [test]
if: github.event_name != 'pull_request' && needs.test.result == 'success' && always()
strategy:
fail-fast: false
matrix:
arch: ["amd64", "arm64", "ppc64el", "armhf", "s390x"]
steps:
- uses: actions/download-artifact@v3
- id: get-snap
run: echo "filename=$(find ${{ env.SNAP_NAME }}*${{ matrix.arch }}*snap/*)" >> $GITHUB_OUTPUT
- name: Release ${{ steps.get-snap.outputs.filename }} to ${{ env.DEFAULT_TRACK }}/${{ env.DEFAULT_RISK }}
uses: snapcore/action-publish@v1
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
with:
snap: ${{ steps.get-snap.outputs.filename }}
release: ${{ env.DEFAULT_TRACK }}/${{ env.DEFAULT_RISK }}
promote:
runs-on: ubuntu-latest
needs: [release]
if: github.event_name == 'release' && needs.release.result == 'success' && always()
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64, ppc64el, armhf, s390x]
env:
TO_TRACK: latest
TO_RISK: candidate
steps:
- name: Install Snapcraft
run: sudo snap install snapcraft --classic
- name: Get current ${{ matrix.arch }} ${{ env.SNAP_NAME }} snap in ${{ env.TO_TRACK }}/${{ env.TO_RISK }}
id: get-snap
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
run: |
revision="$(snapcraft status ${{ env.SNAP_NAME }} \
--track ${{ env.DEFAULT_TRACK }} --arch ${{ matrix.arch }} \
| grep "${{ env.DEFAULT_RISK }}" | awk -F' ' '{print $3}')"
echo "revision=$revision" >> $GITHUB_OUTPUT
# It would be easier to use `snapcraft promote`, but there's an error when trying
# to avoid the prompt with the "--yes" option:
# > 'latest/edge' is not a valid set value for --from-channel when using --yes.
- name: Promote ${{ env.SNAP_NAME }} snap rev${{ steps.get-snap.outputs.revision }} to ${{ env.TO_TRACK }}/${{ env.TO_RISK }}
env:
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
run: |
snapcraft release ${{ env.SNAP_NAME }} \
${{ steps.get-snap.outputs.revision }} \
${{ env.TO_TRACK }}/${{ env.TO_RISK }}