-
Notifications
You must be signed in to change notification settings - Fork 55
218 lines (195 loc) · 7.16 KB
/
build-workflow.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: build-workflow
on:
push:
branches: [ main ]
tags:
- "*"
workflow_dispatch:
inputs:
disable_cache:
description: Disable rust caching
type: boolean
required: false
default: false
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -D warnings
jobs:
build:
name: Build ${{ matrix.job.target }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
job:
- { target: x86_64-unknown-linux-musl, cache: true }
- { target: aarch64-unknown-linux-musl, cache: true }
- { target: arm-unknown-linux-musleabihf, cache: true }
- { target: armv7-unknown-linux-musleabihf, cache: true }
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Retrieve MSRV from workspace Cargo.toml
id: rust_version
uses: SebRollen/[email protected]
with:
file: Cargo.toml
field: "workspace.package.rust-version"
- name: Enable toolchain via github action
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ steps.rust_version.outputs.value }}
targets: ${{ matrix.job.target }}
- name: Enable cache
if: ${{ matrix.job.cache && !inputs.disable_cache }}
# https://github.com/marketplace/actions/rust-cache
uses: Swatinem/rust-cache@v2
# Install nfpm used to for linux packaging
- uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
- uses: extractions/setup-just@v1
- name: Build for ${{ matrix.job.target }}
run: just release ${{ matrix.job.target }}
- name: Upload packages as zip
# https://github.com/marketplace/actions/upload-a-build-artifact
uses: actions/upload-artifact@v4
with:
name: packages-${{ matrix.job.target }}
path: target/${{ matrix.job.target }}/packages/*.*
publish:
name: Publish ${{ matrix.job.target }}
runs-on: ubuntu-20.04
needs: [build]
strategy:
fail-fast: false
matrix:
job:
- { target: x86_64-unknown-linux-musl, repo: tedge-main, component: main }
- { target: aarch64-unknown-linux-musl, repo: tedge-main, component: main }
# Keep arm-unknown-linux-musleabihf in separate repo due to armhf conflict between raspbian and debian
- { target: arm-unknown-linux-musleabihf, repo: tedge-main-armv6, component: main }
- { target: armv7-unknown-linux-musleabihf, repo: tedge-main, component: main }
steps:
- name: Checkout
uses: actions/checkout@v4
# Setup python required by cloudsmith cli
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Download release artifacts
uses: actions/download-artifact@v4
# https://github.com/marketplace/actions/download-a-build-artifact
with:
name: packages-${{ matrix.job.target }}
path: target/${{ matrix.job.target }}/packages/
- uses: extractions/setup-just@v1
- name: Publish packages
env:
PUBLISH_OWNER: ${{ secrets.PUBLISH_OWNER }}
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: |
just publish-linux-target "${{ matrix.job.target }}" \
--repo "${{ matrix.job.repo }}" \
--component "${{ matrix.job.component }}"
# Wait until all other publishing jobs are finished
# before publishing the virtual packages (which are architecture agnostic)
publish-containers:
name: Publish Containers
runs-on: ubuntu-20.04
needs: [build]
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: extractions/setup-just@v1
- id: tedge
name: Get Version
run: |
version=$(just version container)
echo "Detected version: $version"
echo "version=$version" >> "$GITHUB_OUTPUT"
# Download artifacts for all targets
# The docker build step will select the correct target for the
# given container target platform
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: containers/tedge/packages/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/thin-edge/tedge,enable=${{ startsWith(github.ref, 'refs/tags/') }}
name=ghcr.io/thin-edge/tedge-main,enable=true
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value=${{ steps.tedge.outputs.version }},enable=${{ !startsWith(github.ref, 'refs/tags/') }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: containers/tedge
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
# Wait until all other publishing jobs are finished
# before publishing the virtual packages (which are architecture agnostic)
publish-virtual-packages:
name: Publish Virtual Packages
runs-on: ubuntu-20.04
needs: [publish]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Setup python required by cloudsmith cli
- uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
# Install nfpm used to for linux packaging
- uses: actions/setup-go@v5
with:
go-version: 'stable'
cache: false
- run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
- uses: extractions/setup-just@v1
- name: Build virtual packages
run: just release-linux-virtual
- name: Publish packages
env:
PUBLISH_OWNER: ${{ secrets.PUBLISH_OWNER }}
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
run: |
just publish-linux-virtual --repo tedge-main
just publish-linux-virtual --repo tedge-main-armv6