-
Notifications
You must be signed in to change notification settings - Fork 8
142 lines (128 loc) · 5.22 KB
/
ci.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
# https://github.com/actions-rs/example/blob/23ffb1bf0016f41999902ba7542b4f1bb1a89c48/.github/workflows/quickstart.yml#L4
name: CI
on:
push:
branches:
- main
# See:
# https://stackoverflow.com/questions/62968897/is-it-possible-to-not-run-github-action-for-readme-updates
# and
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-excluding-paths
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Run cargo check
run: cargo check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Run cargo test with backtrace
run: cargo test -- --nocapture
env:
RUST_BACKTRACE: 1
lints:
name: Lints
runs-on: ubuntu-latest
env:
RUSTFLAGS: "-Dwarnings"
steps:
- name: Checkout sources
uses: actions/checkout@v2
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Run cargo clippy
run: cargo clippy --all-targets --all-features
release:
runs-on: macos-latest
needs:
- test
- lints
- check
outputs:
new_version: ${{ steps.check_for_version_changes.outputs.new_version }}
changed: ${{ steps.check_for_version_changes.outputs.changed }}
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
with:
# https://stackoverflow.com/questions/65944700/how-to-run-git-diff-in-github-actions
# TLDR – By default this action fetches no history.
# We need a bit of history to be able to check if we've recently updated the version in Cargo.toml
fetch-depth: 2
- name: Toolchain info
run: |
cargo --version --verbose
rustc --version
cargo clippy --version
- name: Build
run: cargo build --release --target aarch64-apple-darwin --target x86_64-apple-darwin
- name: Check for version changes in Cargo.toml
id: check_for_version_changes
run: |
# When there are no changes, VERSION_CHANGES will be empty
# Without the echo, this command would exit with a 1, causing the GitHub Action to fail
# Instead, we want it to succeed, but just evaluate `changed=false` in the other branch of the conditional
VERSION_CHANGES=$(git diff HEAD~1 HEAD Cargo.toml | grep "\+version" || echo "")
if [[ -n $VERSION_CHANGES ]]; then
NEW_VERSION=$(echo $VERSION_CHANGES | awk -F'"' '{print $2}')
echo "changed=true" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: cargo publish and create GitHub Release if current commit has updated the version in Cargo.toml
if: steps.check_for_version_changes.outputs.changed == 'true'
run: |
# This combines the intel and m1 binaries into a single binary
lipo -create -output target/packs target/aarch64-apple-darwin/release/packs target/x86_64-apple-darwin/release/packs
# Creates artifact for homebrew. -C means run from `target` directory
tar -czf target/packs-mac.tar.gz -C target packs
gh release create v${{steps.check_for_version_changes.outputs.new_version}} --target "${{ github.sha }}" --generate-notes
# This uploads the raw binary
gh release upload v${{steps.check_for_version_changes.outputs.new_version}} target/packs
# This tarball is a binary that is executable
gh release upload v${{steps.check_for_version_changes.outputs.new_version}} target/packs-mac.tar.gz
cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Skip publishing
if: steps.check_for_version_changes.outputs.changed == 'false'
run: |
echo "No diff to the version found in Cargo.toml. Skipping publishing."
upload-linux-bin:
needs: release
if: github.ref == 'refs/heads/main' && ${{needs.release.outputs.changed}} == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update local toolchain
run: |
cargo install cross
- name: Build linux binaries
run: |
cross build --release --target x86_64-unknown-linux-gnu
cross build --release --target aarch64-unknown-linux-gnu
- name: Upload linux binaries
run: |
tar -czf target/x86_64-unknown-linux-gnu.tar.gz -C target/x86_64-unknown-linux-gnu/release pks packs
tar -czf target/aarch64-unknown-linux-gnu.tar.gz -C target/aarch64-unknown-linux-gnu/release pks packs
gh release upload v$NEW_VERSION target/x86_64-unknown-linux-gnu.tar.gz
gh release upload v$NEW_VERSION target/aarch64-unknown-linux-gnu.tar.gz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_VERSION: ${{ needs.release.outputs.new_version }}