-
Notifications
You must be signed in to change notification settings - Fork 3
230 lines (204 loc) · 8.73 KB
/
build.yml
File metadata and controls
230 lines (204 loc) · 8.73 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
# SOURCE: https://github.com/sharkdp/fd/blob/master/.github/workflows/CICD.yml
name: build
env:
CARGO_TERM_COLOR: always
MSRV: 1.54.0
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
on:
pull_request:
paths-ignore:
- "scripts/**"
- "LICENSE"
- "Makefile"
- "README.md"
- "CHANGELOG.md"
branches:
- master
push:
tags:
- "*"
jobs:
build:
name: Release
strategy:
matrix:
job:
- {
os: ubuntu-latest,
target: aarch64-unknown-linux-gnu,
use_cross: true,
}
- {
os: ubuntu-latest,
target: armv7-unknown-linux-gnueabihf,
use_cross: true,
}
- {
os: ubuntu-latest,
target: x86_64-unknown-linux-gnu,
use_cross: false,
}
- {
os: windows-latest,
target: x86_64-pc-windows-msvc,
use_cross: false,
}
- {
os: macos-latest,
target: x86_64-apple-darwin,
use_cross: false,
}
runs-on: ${{ matrix.job.os }}
timeout-minutes: 20
steps:
- name: "Git Checkout"
uses: actions/checkout@v2
- name: "Extract crate information"
shell: bash
run: |
REF_TAG=v$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
case ${GITHUB_REF} in
refs/tags/*) REF_TAG=${GITHUB_REF#refs/tags/} ;;
esac;
echo "PROJECT_VERSION=${REF_TAG}" >> $GITHUB_ENV
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_DESC=$(sed -n 's/^description = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_MAINTAINERS=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
- name: "Install Rust toolchain - (${{ env.MSRV }})"
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.MSRV }}
target: ${{ matrix.job.target }}
override: true
profile: minimal
components: clippy
- name: "Clippy"
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features
- name: "Test"
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use_cross }}
command: test
args: --target=${{ matrix.job.target }}
- name: "Build"
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use_cross }}
command: build
args: --release --target=${{ matrix.job.target }}
- name: "Package"
shell: bash
id: package
run: |
# Build binary details
EXE_SUFFIX=""
case ${{ matrix.job.target }} in
*-pc-windows-*) EXE_SUFFIX=".exe" ;;
esac;
BIN_NAME="${{ env.PROJECT_NAME }}${EXE_SUFFIX}"
BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}"
# Tarball details
PKG_SUFFIX=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_SUFFIX=".zip" ;; esac;
PKG_BASENAME="${{ env.PROJECT_NAME}}-${{ env.PROJECT_VERSION }}-${{ matrix.job.target }}"
PKG_NAME="${PKG_BASENAME}${PKG_SUFFIX}"
echo ::set-output name=PKG_NAME::${PKG_NAME}
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package"
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/"
mkdir -p "${ARCHIVE_DIR}"
# Binary
cp "${BIN_PATH}" "${ARCHIVE_DIR}"
# base compressed package
pushd "${PKG_STAGING}/" >/dev/null
case ${{ matrix.job.target }} in
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;;
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;;
esac;
popd >/dev/null
# Let subsequent steps know where to find the compressed package
echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}"
- name: "Artifact upload"
uses: actions/upload-artifact@master
with:
name: ${{ steps.package.outputs.PKG_NAME }}
path: ${{ steps.package.outputs.PKG_PATH }}
- name: "Check for release"
id: is-release
shell: bash
run: |
# Find out whether the action is triggered by a release tag or not
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi
echo ::set-output name=IS_RELEASE::${IS_RELEASE}
- name: "Publish archives and packages"
uses: softprops/action-gh-release@v0.1.8
if: steps.is-release.outputs.IS_RELEASE
with:
files: |
${{ steps.package.outputs.PKG_PATH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish_rust_crate:
name: "Publish Rust Crate on crates.io"
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
timeout-minutes: 20
needs: build
steps:
- uses: actions/checkout@v2
- name: "Install Rust toolchain"
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
- name: "Publish"
uses: actions-rs/cargo@v1
with:
command: publish
args: --verbose --token ${{ secrets.CARGO_TOKEN }}
publish_aur_package:
name: "Publish AUR package"
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
timeout-minutes: 20
needs: build
env:
AUTHOR: numToStr
EMAIL: sudo@vikasraj.dev
steps:
- uses: actions/checkout@v2
- name: "Extract crate information"
shell: bash
run: |
# NOTE: version on AUR is not prefixed with `v`
REF_TAG=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
case ${GITHUB_REF} in
refs/tags/*) REF_TAG=${GITHUB_REF#refs/tags/v} ;;
esac;
echo "PROJECT_VERSION=${REF_TAG}" >> $GITHUB_ENV
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_DESC=$(sed -n 's/^description = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV
- name: "Generate PKGBUILD"
id: gen_pkgbuild
shell: bash
run: |
sed -i -e "s%{{AUTHOR}}%${{ env.AUTHOR }}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{EMAIL}}%${{ env.EMAIL }}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{NAME}}%${{ env.PROJECT_NAME }}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{DESC}}%${{ env.PROJECT_DESC }}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{VERSION}}%${{ env.PROJECT_VERSION }}%g;" ./.aur/PKGBUILD
sed -i -e "s%{{URL}}%${{ env.PROJECT_HOMEPAGE }}%g;" ./.aur/PKGBUILD
cat ./.aur/PKGBUILD
- name: "Publish to AUR"
uses: KSXGitHub/github-actions-deploy-aur@v2.2.5
with:
pkgbuild: ./.aur/PKGBUILD
pkgname: ${{ env.PROJECT_NAME }}
commit_username: ${{ env.AUTHOR }}
commit_email: ${{ env.EMAIL }}
commit_message: ${{ env.PROJECT_VERSION }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}