Skip to content

Commit d7fca8e

Browse files
authored
Replace GH workflow (#30)
* Replace GH workflow Duplicates config from [rubyatscale/pks](https://github.com/rubyatscale/pks) and removes existing workflow. * Add `rust-toolchain` to enable builds in CI * Update `actions/checkout` Remove deprecation warnings
1 parent 5cd08a0 commit d7fca8e

File tree

5 files changed

+220
-65
lines changed

5 files changed

+220
-65
lines changed

.github/workflows/audit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Security audit
2+
3+
on:
4+
schedule:
5+
- cron: 0 0 * * 1
6+
push:
7+
paths:
8+
- '**/Cargo.toml'
9+
- '**/Cargo.lock'
10+
pull_request:
11+
12+
jobs:
13+
audit:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions-rs/audit-check@v1
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# https://github.com/actions-rs/example/blob/23ffb1bf0016f41999902ba7542b4f1bb1a89c48/.github/workflows/quickstart.yml#L4
2+
name: CI
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# See:
8+
# https://stackoverflow.com/questions/62968897/is-it-possible-to-not-run-github-action-for-readme-updates
9+
# and
10+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-excluding-paths
11+
paths-ignore:
12+
- '**.md'
13+
pull_request:
14+
paths-ignore:
15+
- '**.md'
16+
17+
env:
18+
CARGO_TERM_COLOR: always
19+
20+
jobs:
21+
check:
22+
name: Check
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout sources
26+
uses: actions/checkout@v4
27+
28+
- name: Run cargo check
29+
run: cargo check
30+
test:
31+
name: Test Suite
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout sources
35+
uses: actions/checkout@v4
36+
37+
- name: Run cargo test with backtrace
38+
run: cargo test -- --nocapture
39+
env:
40+
RUST_BACKTRACE: 1
41+
lints:
42+
name: Lints
43+
runs-on: ubuntu-latest
44+
env:
45+
RUSTFLAGS: "-Dwarnings"
46+
steps:
47+
- name: Checkout sources
48+
uses: actions/checkout@v4
49+
50+
- name: Run cargo fmt
51+
run: cargo fmt --all -- --check
52+
53+
- name: Run cargo clippy
54+
run: cargo clippy --all-targets --all-features
55+
56+
release:
57+
runs-on: macos-latest
58+
needs:
59+
- test
60+
- lints
61+
- check
62+
outputs:
63+
new_version: ${{ steps.check_for_version_changes.outputs.new_version }}
64+
changed: ${{ steps.check_for_version_changes.outputs.changed }}
65+
if: github.ref == 'refs/heads/main'
66+
steps:
67+
- uses: actions/checkout@v4
68+
with:
69+
# https://stackoverflow.com/questions/65944700/how-to-run-git-diff-in-github-actions
70+
# TLDR – By default this action fetches no history.
71+
# We need a bit of history to be able to check if we've recently updated the version in Cargo.toml
72+
fetch-depth: 2
73+
- name: Toolchain info
74+
run: |
75+
cargo --version --verbose
76+
rustc --version
77+
cargo clippy --version
78+
- name: Build
79+
run: cargo build --release --target aarch64-apple-darwin --target x86_64-apple-darwin
80+
- name: Check for version changes in Cargo.toml
81+
id: check_for_version_changes
82+
run: |
83+
# When there are no changes, VERSION_CHANGES will be empty
84+
# Without the echo, this command would exit with a 1, causing the GitHub Action to fail
85+
# Instead, we want it to succeed, but just evaluate `changed=false` in the other branch of the conditional
86+
VERSION_CHANGES=$(git diff HEAD~1 HEAD Cargo.toml | grep "\+version" || echo "")
87+
if [[ -n $VERSION_CHANGES ]]; then
88+
NEW_VERSION=$(echo $VERSION_CHANGES | awk -F'"' '{print $2}')
89+
echo "changed=true" >> $GITHUB_OUTPUT
90+
echo "new_version=v$NEW_VERSION" >> $GITHUB_OUTPUT
91+
else
92+
echo "changed=false" >> $GITHUB_OUTPUT
93+
fi
94+
95+
- name: Create GitHub Release if current commit has updated the version in Cargo.toml
96+
if: steps.check_for_version_changes.outputs.changed == 'true'
97+
run: |
98+
gh release create ${{steps.check_for_version_changes.outputs.new_version}} --target "${{ github.sha }}" --generate-notes
99+
env:
100+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
upload-mac-universal-bin:
102+
needs: release
103+
runs-on: macos-latest
104+
if: ${{needs.release.outputs.new_version}}
105+
steps:
106+
- uses: actions/checkout@v4
107+
- name: Build
108+
run: cargo build --release --target aarch64-apple-darwin --target x86_64-apple-darwin
109+
110+
- name: Upload mac universal binary
111+
run: |
112+
# This combines the intel and m1 binaries into a single binary
113+
lipo -create -output target/codeowners target/aarch64-apple-darwin/release/codeowners target/x86_64-apple-darwin/release/codeowners
114+
115+
# Creates artifact for homebrew. -C means run from `target` directory
116+
tar -czf target/codeowners-mac.tar.gz -C target codeowners
117+
118+
# This tarball is a binary that is executable
119+
gh release upload $NEW_VERSION target/codeowners-mac.tar.gz
120+
121+
env:
122+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
NEW_VERSION: ${{ needs.release.outputs.new_version }}
124+
125+
upload-linux-bin:
126+
needs: release
127+
if: ${{needs.release.outputs.new_version}}
128+
runs-on: ubuntu-latest
129+
steps:
130+
- uses: actions/checkout@v4
131+
- name: Update local toolchain
132+
run: |
133+
cargo install cross
134+
- name: Build linux binaries
135+
run: |
136+
cross build --release --target x86_64-unknown-linux-gnu
137+
cross build --release --target aarch64-unknown-linux-gnu
138+
- name: Upload linux binaries
139+
run: |
140+
tar -czf target/x86_64-unknown-linux-gnu.tar.gz -C target/x86_64-unknown-linux-gnu/release codeowners
141+
tar -czf target/aarch64-unknown-linux-gnu.tar.gz -C target/aarch64-unknown-linux-gnu/release codeowners
142+
gh release upload $NEW_VERSION target/x86_64-unknown-linux-gnu.tar.gz
143+
gh release upload $NEW_VERSION target/aarch64-unknown-linux-gnu.tar.gz
144+
env:
145+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
146+
NEW_VERSION: ${{ needs.release.outputs.new_version }}
147+
148+
generate-dotslash-files:
149+
name: Generating and uploading DotSlash files
150+
needs:
151+
- release
152+
- upload-linux-bin
153+
- upload-mac-universal-bin
154+
if: success() && ${{needs.release.outputs.new_version}}
155+
runs-on: ubuntu-latest
156+
157+
steps:
158+
- uses: facebook/dotslash-publish-release@v1
159+
# This is necessary because the action uses
160+
# `gh release upload` to publish the generated DotSlash file(s)
161+
# as part of the release.
162+
env:
163+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+
with:
165+
# Additional file that lives in your repo that defines
166+
# how your DotSlash file(s) should be generated.
167+
config: .github/workflows/dotslash-config.json
168+
# Tag for the release to target.
169+
tag: ${{ needs.release.outputs.new_version }}

.github/workflows/codeowners.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"outputs": {
3+
"codeowners": {
4+
"platforms": {
5+
"macos-x86_64": {
6+
"regex": "^codeowners-mac",
7+
"path": "codeowners",
8+
"format": "tar.gz"
9+
},
10+
"macos-aarch64": {
11+
"regex": "^codeowners-mac",
12+
"path": "codeowners",
13+
"format": "tar.gz"
14+
},
15+
"linux-x86_64": {
16+
"regex": "^x86_64-unknown-linux",
17+
"path": "codeowners",
18+
"format": "tar.gz"
19+
},
20+
"linux-aarch64": {
21+
"regex": "^aarch64-unknown-linux",
22+
"path": "codeowners",
23+
"format": "tar.gz"
24+
}
25+
}
26+
}
27+
}
28+
}

rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
channel = "1.82.0"
3+
components = ["clippy", "rustfmt"]
4+
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-unknown-linux-gnu"]

0 commit comments

Comments
 (0)