This repository has been archived by the owner on Jun 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (133 loc) · 5.04 KB
/
build-and-package.yaml
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
---
env:
PACKAGE_NAME: sensor_mqtt
PACKAGE_DESCRIPTION: Script to publish BME280 and BLE sensor metrics over MQTT
PACKAGE_ARCH: armhf
RUST_TARGET: arm-unknown-linux-gnueabi
CARGO_USE_CROSS: true
BINARY_NAME: sensor_mqtt
name: Build, package and upload
"on":
push:
paths-ignore:
- "*.md"
- LICENSE
- rustfmt.toml
- .github/renovate.json
- .gitignore
branches:
- main
pull_request:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1
with:
toolchain: stable
target: ${{ env.RUST_TARGET }}
- name: Rust Cache
uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2
- name: Install cargo tarpaulin
run: cargo install cargo-tarpaulin
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
with:
command: build
use-cross: ${{ env.CARGO_USE_CROSS}}
args: --release --target=${{ env.RUST_TARGET }}
- uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1
name: Generate coverage
with:
command: tarpaulin
args: --out xml
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
if: always()
- name: Upload build artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: target
path: target/**/${{ env.BINARY_NAME }}
build-package:
name: Build Deb Package
runs-on: ubuntu-latest
needs: build
steps:
- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
working-directory: ./packaging
bundler-cache: true
- name: Download build artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3
- name: Set binary as executable
run: |
find target -name ${{ env.BINARY_NAME }} -exec chmod +x {} \;
- name: Package
working-directory: ./packaging
run: |
export DEB_VERSION="$(cat ../Cargo.toml | grep "^version = " | awk '{gsub(/"/, "", $3); print $3}')-$GITHUB_RUN_NUMBER"
bundle exec fpm -f \
-s dir \
--deb-priority optional \
--maintainer [email protected] \
--vendor [email protected] \
--license MIT \
-t deb \
-n $DEB_NAME \
--description "$APP_DESCRIPTION" \
--url $APP_URL \
--deb-changelog ../CHANGELOG.md \
--prefix / \
-a $DEB_ARCH \
-v $DEB_VERSION \
--before-install deb_scripts/before_install.sh \
--before-upgrade deb_scripts/before_upgrade.sh \
--after-remove deb_scripts/after_remove.sh \
--after-install deb_scripts/after_install.sh \
--after-upgrade deb_scripts/after_upgrade.sh \
--deb-systemd sensor_mqtt.service \
--config-files /etc/sensor_mqtt/sensor_mqtt.toml \
sensor_mqtt.toml=/etc/sensor_mqtt/sensor_mqtt.toml \
../target/arm-unknown-linux-gnueabi/release/sensor_mqtt=/usr/bin/sensor_mqtt
env:
DEB_NAME: ${{ env.PACKAGE_NAME }}
APP_DESCRIPTION: ${{ env.PACKAGE_DESCRIPTION }}
APP_URL: https://github.com/${{ github.repository }}
DEB_ARCH: ${{ env.PACKAGE_ARCH }}
- name: Upload build artifact
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3
with:
name: deb-package
path: "packaging/*.deb"
publish:
name: Publish
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
needs: build-package
steps:
- name: Download build artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3
with:
name: deb-package
- name: Upload to Apt repo
env:
APT_CREDENTIALS: ${{ secrets.APT_CREDENTIALS }}
APT_KEY_PASSPHRASE: ${{ secrets.APT_KEY_PASSPHRASE }}
run: |
echo $APT_CREDENTIALS > aptly-auth
find -type f -name "*.deb" -exec curl -f --netrc-file aptly-auth -XPOST -F file=@{} https://apttoo.growse.com/api/files/sensor_mqtt \;
export result=$(curl -f --netrc-file aptly-auth -X POST https://apttoo.growse.com/api/repos/defaultrepo/file/sensor_mqtt)
echo $result
export failed=$(echo $result | jq '.FailedFiles | length')
if [[ "$failed" != "0" ]]; then exit 1; fi
curl -f --netrc-file aptly-auth -X PUT -H"Content-type: application/json" --data '{"Signing":{"Passphrase":"'"$APT_KEY_PASSPHRASE"'","Batch":true}}' https://apttoo.growse.com/api/publish/:./stablish