-
Notifications
You must be signed in to change notification settings - Fork 1
179 lines (157 loc) · 5.36 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch: {}
jobs:
build:
name: Build binaries
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
target:
- aarch64-unknown-linux-gnu
- aarch64-unknown-linux-musl
- armv7-unknown-linux-gnueabihf
- armv7-unknown-linux-musleabihf
- x86_64-unknown-linux-musl
os: [ubuntu-latest]
include:
# Use an older Ubuntu version for glibc compatibility with Debian v11 Buster
- target: x86_64-unknown-linux-gnu
os: ubuntu-20.04
env:
RELEASE: ${{ startsWith(github.ref, 'refs/tags/v') }}
PROFILE: ${{ startsWith(github.ref, 'refs/tags/v') && 'release' || 'debug' }}
USE_CROSS: "${{ !startsWith(matrix.target, 'x86_64-unknown-linux-') }}"
MUSL: ${{ contains(matrix.target, '-unknown-linux-musl') }}
CARGO: cargo
runs-on: ${{ matrix.os }}
steps:
- name: Setup | Checkout
uses: actions/[email protected]
- name: Setup | Rust
uses: dtolnay/rust-toolchain@315e265cd78dad1e1dcf3a5074f6d6c47029d5aa
with:
toolchain: stable
- name: Setup | Cache
uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2.7.5
with:
shared-key: ${{ matrix.target }}-${{ matrix.os }}-${{ env.PROFILE }}-build
- name: Setup | Cross
if: env.USE_CROSS == 'true'
run: |
cargo install --bins cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Setup | Install build dependencies
if: env.USE_CROSS == 'false'
run: |
rustup target add ${{ matrix.target }}
if [[ "$MUSL" == 'true' ]]; then
sudo apt-get update
sudo apt-get install --assume-yes musl-tools
fi
- name: Setup | Log in to the Container registry
if: env.USE_CROSS == 'true'
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup | Set build options
if: env.RELEASE == 'true'
run: |
echo 'RELEASE_FLAG=--release' >> $GITHUB_ENV
- name: Build
run: ${{ env.CARGO }} build --verbose ${{ env.RELEASE_FLAG }} --target ${{ matrix.target }}
- name: Prepare artifact
run: |
mkdir -p 'binaries/${{ matrix.target }}'
cp target/${{ matrix.target }}/${{ ENV.PROFILE }}/ruuvi2mqtt binaries/${{ matrix.target }}/
- name: Upload artifact
uses: actions/[email protected]
with:
name: binaries-${{ matrix.target }}
path: binaries
if-no-files-found: error
compression-level: 3
docker:
name: Build and push Docker images
needs: build
permissions:
contents: read
packages: write
env:
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/[email protected]
- name: Setup | Download artifacts
uses: actions/[email protected]
with:
pattern: binaries-*
path: binaries
merge-multiple: true
- name: Setup | Prepare binaries
run: |
chmod 0755 binaries/*/ruuvi2mqtt
mkdir -p binaries/{${{ env.PLATFORMS }}}
ln -s ../../aarch64-unknown-linux-musl/ruuvi2mqtt binaries/linux/arm64/
ln -s ../../../armv7-unknown-linux-musleabihf/ruuvi2mqtt binaries/linux/arm/v7/
ln -s ../../x86_64-unknown-linux-musl/ruuvi2mqtt binaries/linux/amd64/
- name: Setup | Log in to the Container registry
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup | Docker QEMU
uses: docker/[email protected]
- name: Setup | Docker Buildx
uses: docker/[email protected]
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
gh-release:
name: Make a GitHub release
if: startsWith(github.ref, 'refs/tags/v')
needs: build
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Setup | Download artifacts
uses: actions/[email protected]
with:
pattern: binaries-*
path: binaries
merge-multiple: true
- name: Create tarballs
run: |
mkdir -p tarballs
for target in binaries/*; do
tar -czf tarballs/$(basename $target).tar.gz -C $target .
done
- name: Create a Release
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0
with:
draft: true
artifacts: tarballs/*
artifactErrorsFailBuild: true