-
Notifications
You must be signed in to change notification settings - Fork 1
196 lines (189 loc) · 6.46 KB
/
build-and-test.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
name: Cargo Build & Test
on:
push:
pull_request:
env:
CARGO_TERM_COLOR: always
jobs:
build-and-test:
name: Build and test on linux
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/lukaj-test:develop
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
strategy:
matrix:
toolchain:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v3
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- if: matrix.toolchain == 'stable'
run: |
rustup component add llvm-tools-preview
echo "RUSTFLAGS=-C instrument-coverage" >> $GITHUB_ENV
echo "LLVM_PROFILE_FILE=target/coverage/%p-%m.profraw" >> $GITHUB_ENV
- run: cargo build --features use-rsvg
- run: cargo test --features use-rsvg
- if: matrix.toolchain == 'stable'
run: |
grcov target/coverage --binary-path target/debug -s . -o target/tmp \
--keep-only "src/*" --keep-only "tests/*" --output-types lcov,markdown,html
cat target/tmp/markdown.md
- uses: actions/upload-artifact@v3
with:
name: artifacts-linux-${{ matrix.toolchain }}
path: target/tmp/*
retention-days: 7
if-no-files-found: error
- if: matrix.toolchain == 'stable' && github.ref == 'refs/heads/master'
uses: coverallsapp/github-action@v2
with:
files: target/tmp/lcov
format: lcov
github-token: ${{ secrets.GITHUB_TOKEN }}
build-and-test-win:
name: Build and test on windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: msys2/setup-msys2@v2
with:
location: D:\
update: true
install : >-
mingw-w64-x86_64-gtk4
mingw-w64-x86_64-gettext
mingw-w64-x86_64-libxml2
mingw-w64-x86_64-pkgconf
mingw-w64-x86_64-gcc
mingw-w64-x86_64-SDL2
- run: rustup update stable-gnu && rustup default stable-gnu
- shell: bash
run: echo "D:/msys64/mingw64/bin" >> $GITHUB_PATH
- run: cargo build --features use-rsvg
- run: cargo test --features use-rsvg
- uses: actions/upload-artifact@v3
with:
name: artifacts-windows-gnu
path: target/tmp/*
retention-days: 7
if-no-files-found: error
# slightly modified version of ripgrep's 'create-release' workflow:
create-release:
name: create-release
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
steps:
- uses: actions/checkout@v4
- name: Get the release version from the tag
if: env.VERSION == ''
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Show the version
run: |
echo "version is: $VERSION"
- name: Check that tag version and Cargo.toml version are the same
shell: bash
run: |
cargo_version=$(awk -F\" '/^version/ { print $2 }' Cargo.toml)
if ! [ "$VERSION" = "v$cargo_version" ]; then
echo "version does not match Cargo.toml" >&2
exit 1
fi
- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release create $VERSION --draft --verify-tag --title $VERSION
build-executables:
name: Build executables
runs-on: ${{ matrix.os }}
# note that we are not building with `user-rsvg` support here
# so using lukaj-test docker image with pre-installed dependencies
# is not required
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v3
- run: rustup update stable && rustup default stable
- name: Install dependencies
shell: bash
run: |
cargo install cargo-vcpkg
cargo vcpkg build
- name: Prepare environment variables
shell: bash
run: |
triplet=$(rustc -vV | awk '/^host/ { print $2 }')
version=$(awk -F\" '/^version/ { print $2 }' Cargo.toml)
name=lukaj-${version}-${triplet}
echo "NAME=$name" >> $GITHUB_ENV
echo "VERSION=$version" >> $GITHUB_ENV
- name: Build release binary
shell: bash
run: |
cargo build --verbose --features static-link --release
- name: Package release (Unix)
shell: bash
if: matrix.os != 'windows-latest'
run: |
asset=$NAME.tar.gz
tar -czvf $asset -C target/release lukaj
shasum -a 256 $asset > $asset.sha256
echo "ASSET=$asset" >> $GITHUB_ENV
- name: Package release (Windows)
shell: bash
if: matrix.os == 'windows-latest'
run: |
asset=$NAME.zip
cd target/release
7z a -tzip $asset lukaj.exe
cp $asset ../..
cd ../..
certutil -hashfile $asset SHA256 > $asset.sha256
echo "ASSET=$asset" >> $GITHUB_ENV
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
name: Upload release archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh release upload v${{ env.VERSION }} ${{ env.ASSET }} ${{ env.ASSET }}.sha256
- uses: actions/upload-artifact@v3
with:
name: executables-${{ matrix.os }}
path: ${{ env.ASSET }}
retention-days: 7
if-no-files-found: error
publish:
name: Publish release
needs:
- create-release
- build-and-test
- build-and-test-win
- build-executables
runs-on: ubuntu-latest
container:
image: ghcr.io/${{ github.repository_owner }}/lukaj-test:latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
steps:
- uses: actions/checkout@v3
- run: rustup update stable && rustup default stable
- run: cargo vcpkg build
- run: cargo publish --all-features --dry-run
- if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
name: Push to crates.io
run: cargo publish --all-features
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}