Skip to content

Commit 1076d47

Browse files
committed
ci: add dependabot config and CI workflow
Signed-off-by: Gaëtan Lehmann <[email protected]>
1 parent f803cd9 commit 1076d47

File tree

3 files changed

+215
-0
lines changed

3 files changed

+215
-0
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
workflow_dispatch:
9+
schedule:
10+
- cron: '20 7 * * *'
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
test:
20+
name: test
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
# rust channels
27+
- build: stable
28+
os: ubuntu-24.04
29+
rust: stable
30+
target: x86_64-unknown-linux-gnu
31+
- build: beta
32+
os: ubuntu-24.04
33+
rust: beta
34+
target: x86_64-unknown-linux-gnu
35+
- build: nightly
36+
os: ubuntu-24.04
37+
rust: nightly
38+
target: x86_64-unknown-linux-gnu
39+
40+
# release platforms
41+
- build: linux-amd64
42+
os: ubuntu-24.04
43+
rust: stable
44+
target: x86_64-unknown-linux-musl
45+
# - build: linux-arm64
46+
# os: ubuntu-24.04-arm
47+
# rust: stable
48+
# target: aarch64-unknown-linux-musl
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
persist-credentials: false
53+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
54+
with:
55+
toolchain: ${{ matrix.rust }}
56+
target: ${{ matrix.target }}
57+
- run: cargo build --workspace --target ${{ matrix.target }} --release
58+
- run: cargo run --target ${{ matrix.target }} --release -- --help
59+
- run: cargo test --workspace --target ${{ matrix.target }} --release
60+
env:
61+
NO_COLOR: "true"
62+
63+
rustfmt:
64+
runs-on: ubuntu-24.04
65+
steps:
66+
- uses: actions/checkout@v4
67+
with:
68+
persist-credentials: false
69+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
70+
with:
71+
toolchain: stable
72+
components: rustfmt
73+
- run: cargo fmt --all --check
74+
75+
clippy:
76+
runs-on: ubuntu-24.04
77+
steps:
78+
- uses: actions/checkout@v4
79+
with:
80+
persist-credentials: false
81+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
82+
with:
83+
toolchain: stable
84+
components: clippy
85+
- run: cargo clippy --all-targets -- -D warnings
86+
87+
dependabot-auto-merge:
88+
needs:
89+
- test
90+
- rustfmt
91+
- clippy
92+
permissions:
93+
contents: write
94+
pull-requests: write
95+
runs-on: ubuntu-24.04
96+
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' && github.event_name == 'pull_request' }}
97+
steps:
98+
- run: gh pr merge --auto --rebase "$PR_URL"
99+
env:
100+
PR_URL: ${{github.event.pull_request.html_url}}
101+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/release.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: release
2+
3+
# Only do the release on x.y.z tags.
4+
on:
5+
push:
6+
tags:
7+
- "[0-9]+.[0-9]+.[0-9]+"
8+
9+
permissions: {}
10+
11+
jobs:
12+
# The create-release job runs purely to initialize the GitHub release itself,
13+
# and names the release after the `x.y.z` tag that was pushed. It's separate
14+
# from building the release so that we only create the release once.
15+
create-release:
16+
name: create-release
17+
runs-on: ubuntu-latest
18+
# We need this to be able to create releases.
19+
permissions:
20+
contents: write
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
persist-credentials: false
25+
- name: Get the release version from the tag
26+
if: env.VERSION == ''
27+
run: echo "VERSION=$REFNAME" >> $GITHUB_ENV
28+
env:
29+
REFNAME: ${{ github.ref_name }}
30+
- name: Check that tag version and Cargo.toml version are the same
31+
shell: bash
32+
run: |
33+
if ! grep -q "version = \"$VERSION\"" Cargo.toml; then
34+
echo "version does not match Cargo.toml" >&2
35+
exit 1
36+
fi
37+
- name: Create GitHub release
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
run: gh release create $VERSION --draft --verify-tag --title $VERSION
41+
outputs:
42+
version: ${{ env.VERSION }}
43+
44+
build-release:
45+
name: build-release
46+
needs: ['create-release']
47+
runs-on: ${{ matrix.os }}
48+
# We need this to upload the artifacts
49+
permissions:
50+
contents: write
51+
strategy:
52+
fail-fast: false
53+
matrix:
54+
include:
55+
- build: linux-amd64
56+
os: ubuntu-latest
57+
rust: stable
58+
target: x86_64-unknown-linux-musl
59+
# - build: linux-arm64
60+
# os: ubuntu-latest
61+
# rust: stable
62+
# target: aarch64-unknown-linux-musl
63+
steps:
64+
- uses: actions/checkout@v4
65+
with:
66+
persist-credentials: false
67+
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
68+
with:
69+
toolchain: ${{ matrix.rust }}
70+
target: ${{ matrix.target }}
71+
72+
- name: Build release binary
73+
shell: bash
74+
run: |
75+
cargo build --workspace --target ${{ matrix.target }} --release
76+
echo "BIN=$PWD/target/${{ matrix.target }}/release/randstream" >> $GITHUB_ENV
77+
78+
- name: Get the release version from the tag
79+
run: echo "VERSION=$VERSION" >> $GITHUB_ENV
80+
env:
81+
VERSION: ${{ needs.create-release.outputs.version }}
82+
83+
- name: Determine archive name
84+
shell: bash
85+
run: |
86+
echo "VERSION=$VERSION" >> $GITHUB_ENV
87+
echo "ARCHIVE=randstream-$VERSION-${{ matrix.target }}" >> $GITHUB_ENV
88+
env:
89+
VERSION: ${{ needs.create-release.outputs.version }}
90+
91+
- name: Build archive
92+
shell: bash
93+
run: |
94+
mkdir archive
95+
cd archive
96+
cp $BIN .
97+
cp ../README.md ../LICENSE .
98+
tar czf "../$ARCHIVE.tar.gz" .
99+
cd ..
100+
shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
101+
echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV
102+
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> $GITHUB_ENV
103+
104+
- name: Upload release archive
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
shell: bash
108+
run: gh release upload "$VERSION" $ASSET $ASSET_SUM

0 commit comments

Comments
 (0)