-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (90 loc) · 3.11 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
name: build
on:
workflow_dispatch:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
jobs:
build-release:
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
name: ${{ matrix.target }}
env:
SHELL_COMPLETIONS_DIR: completions
steps:
- uses: actions/checkout@v2
- name: Extract crate information
id: info
shell: bash
run: |
PKG_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
echo ::set-output name=PKG_VERSION::${PKG_VERSION}
- name: Check Cargo.toml version against tag
shell: bash
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_VERSION="${GITHUB_REF#refs/tags/}"
CARGO_VERSION="${{ steps.info.outputs.PKG_VERSION }}"
if [[ ${TAG_VERSION} != "${CARGO_VERSION}" ]]; then
echo "Cargo.toml version differs from the current tag!"
echo "Cargo.toml: ${CARGO_VERSION}"
echo "tag: ${TAG_VERSION}"
exit 1
fi
- name: Install prerequisites
shell: bash
run: |
sudo apt-get -y update
sudo apt-get install -y libheif-dev libheif1
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
- name: Show version information
shell: bash
run: |
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
- name: Create completions dir
run: mkdir -p "${SHELL_COMPLETIONS_DIR}"
- name: Build the binary
uses: actions-rs/cargo@v1
with:
command: build
args: --release --locked --target=${{ matrix.target }}
- name: Strip the binary
run: strip "target/${{ matrix.target }}/release/timewall"
- name: Build the archive artifact
id: build
shell: bash
run: |
PKG_NAME="timewall-${{ steps.info.outputs.PKG_VERSION }}-${{ matrix.target }}"
PKG_STAGING="${PWD}/${PKG_NAME}"
mkdir -p "${PKG_STAGING}"
cp "target/${{ matrix.target }}/release/timewall" "${PKG_STAGING}"
cp -r "${SHELL_COMPLETIONS_DIR}" "${PKG_STAGING}"
cp {README.md,LICENSE,timewall.service} "${PKG_STAGING}"
PKG_ARTIFACT_NAME="${PKG_NAME}.tar.gz"
PKG_ARTIFACT_PATH="${PWD}/${PKG_ARTIFACT_NAME}"
cd "${PKG_STAGING}"
tar -czf "${PKG_ARTIFACT_PATH}" *
echo ::set-output name=PKG_ARTIFACT_NAME::${PKG_ARTIFACT_NAME}
echo ::set-output name=PKG_ARTIFACT_PATH::${PKG_ARTIFACT_PATH}
- name: Upload the artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.build.outputs.PKG_ARTIFACT_NAME }}
path: ${{ steps.build.outputs.PKG_ARTIFACT_PATH }}
- name: Release the artifact
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
files: ${{ steps.build.outputs.PKG_ARTIFACT_PATH }}