-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (162 loc) Β· 5.84 KB
/
build.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
name: build
on:
push:
branches:
- ci
- "dev/build-yml"
- "!main"
permissions:
contents: write
jobs:
get-version:
name: get-version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Grab the version from Cargo.toml
shell: bash
run: |
cargo_version="v$(head -n5 Cargo.toml | grep -oE "version = \"[0-9\.]+\"" | cut -d'"' -f2)"
echo "VERSION=$cargo_version" >> $GITHUB_ENV
outputs:
version: ${{ env.VERSION }}
smoke-test:
name: smoke-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install rust
shell: bash
run: |
RUST_VERSION="$(grep -oP 'channel = "\K[^"]+' rust-toolchain.toml)"
rustup toolchain install $RUST_VERSION --profile minimal
- uses: extractions/setup-just@v2
- name: Cache sccache
id: cache_sccache
uses: actions/cache@v4
with:
path: /home/runner/.cache/sccache
key: test-sccache-v0-${{ hashFiles('Cargo.lock') }}
- name: Prep sccache
shell: bash
run: |
curl --fail --location "https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}/sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" --output /tmp/sccache.tar.gz
tar --directory "/usr/local/bin" -xzvf "/tmp/sccache.tar.gz" --strip-components 1 --wildcards "*/sccache"
rm /tmp/sccache.tar.gz
sudo mkdir -p /home/runner/.cache/sccache
sudo chown -R $(id -u) /home/runner/.cache/sccache
sudo chmod -R u+rwX /home/runner/.cache/sccache
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
echo "SCCACHE_DIR=/home/runner/.cache/sccache" >> $GITHUB_ENV
env:
CARGO_UDEPS_VERSION: "v0.1.50"
SCCACHE_VERSION: "v0.8.1"
- name: Run the CI tests
run: |
just ci
sccache -s
build-binaries:
name: build-binaries
needs: [ "get-version", "smoke-test" ]
runs-on: ubuntu-latest
env:
CARGO: cross
TARGET_FLAGS:
TARGET_DIR: ./target
CROSS_VERSION: v0.2.5
RUST_BACKTRACE: 1
strategy:
fail-fast: false
matrix:
include:
- build: stable-x86_64
target: x86_64-unknown-linux-musl
- build: stable-x86
target: i686-unknown-linux-musl
- build: stable-aarch64
target: aarch64-unknown-linux-musl
- build: stable-armv7
target: armv7-unknown-linux-musleabi
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache sccache
id: cache_sccache
uses: actions/cache@v4
with:
path: /home/runner/.cache/sccache
key: ${{ matrix.target }}-sccache-${{ hashFiles('Cargo.lock') }}
- name: Fix cache permissions
shell: bash
run: |
sudo mkdir -p /home/runner/.cache/sccache
sudo chown -R $(id -u) /home/runner/.cache/sccache
sudo chmod -R u+rwX /home/runner/.cache/sccache
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Prepare Cross
shell: bash
run: |
dir="$RUNNER_TEMP/cross-download"
mkdir "$dir"
echo "$dir" >> $GITHUB_PATH
cd "$dir"
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
tar xf cross-x86_64-unknown-linux-musl.tar.gz
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- name: Show command used for Cargo
shell: bash
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
echo "target dir is: ${{ env.TARGET_DIR }}"
- name: Build release binary
shell: bash
run: |
export CROSS_CONTAINER_OPTS="-v /home/runner/.cache/sccache:/sccache:rw -e SCCACHE_DIR=/sccache"
${{ env.CARGO }} build --release ${{ env.TARGET_FLAGS }}
- name: Determine archive name
shell: bash
run: |
version="${{ needs.get-version.outputs.version }}"
echo "ARCHIVE=loglux-$version-${{ matrix.target }}" >> $GITHUB_ENV
- name: Creating directory for archive
shell: bash
run: |
mkdir -p "$ARCHIVE"
cp "target/${{ matrix.target }}/release/loglux" "$ARCHIVE"/
cp {README.md,UNLICENSE} "$ARCHIVE"/
- name: Build archive (Unix)
shell: bash
run: |
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> $GITHUB_ENV
- name: Upload release archive
if: "github.ref == 'refs/heads/ci' && !contains(github.event.head_commit.message, '[cron]')"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
version="${{ needs.get-version.outputs.version }}"
gh release upload "$version" ${{ env.ASSET }} ${{ env.ASSET_SUM }}
promote-release:
if: "github.ref == 'refs/heads/ci' && !contains(github.event.head_commit.message, '[cron]')"
name: promote-release
needs: [ "build-binaries", "get-version" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Promote release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
version="${{ needs.get-version.outputs.version }}"
gh release edit "$version" --draft=false --latest