Skip to content

Commit d4aad87

Browse files
committed
Create CI scripts
1 parent 48c2eb3 commit d4aad87

2 files changed

Lines changed: 306 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: ci
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
name: test
15+
env:
16+
CARGO: cargo
17+
TARGET_FLAGS:
18+
TARGET_DIR: ./target
19+
CROSS_VERSION: v0.2.5
20+
RUST_BACKTRACE: 1
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
include:
26+
- build: stable
27+
os: ubuntu-latest
28+
rust: stable
29+
- build: beta
30+
os: ubuntu-latest
31+
rust: beta
32+
- build: nightly
33+
os: ubuntu-latest
34+
rust: nightly
35+
- build: stable-musl
36+
os: ubuntu-latest
37+
rust: stable
38+
target: x86_64-unknown-linux-musl
39+
- build: stable-aarch64
40+
os: ubuntu-latest
41+
rust: stable
42+
target: aarch64-unknown-linux-gnu
43+
- build: macos
44+
os: macos-latest
45+
rust: stable
46+
- build: win-msvc
47+
os: windows-latest
48+
rust: stable
49+
- build: win-gnu
50+
os: windows-latest
51+
rust: stable-x86_64-gnu
52+
steps:
53+
- name: Checkout repository
54+
uses: actions/checkout@v4
55+
56+
- name: Install Rust
57+
uses: dtolnay/rust-toolchain@master
58+
with:
59+
toolchain: ${{ matrix.rust }}
60+
61+
- name: Use Cross
62+
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
63+
run: |
64+
dir="$RUNNER_TEMP/cross-download"
65+
mkdir "$dir"
66+
echo "$dir" >> $GITHUB_PATH
67+
cd "$dir"
68+
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
69+
tar xf cross-x86_64-unknown-linux-musl.tar.gz
70+
echo "CARGO=cross" >> $GITHUB_ENV
71+
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
72+
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
73+
74+
- name: Show command used for Cargo
75+
run: |
76+
echo "cargo command is: ${{ env.CARGO }}"
77+
echo "target flag is: ${{ env.TARGET_FLAGS }}"
78+
echo "target dir is: ${{ env.TARGET_DIR }}"
79+
80+
- name: Build
81+
run: ${{ env.CARGO }} build --verbose --workspace ${{ env.TARGET_FLAGS }}
82+
83+
- name: Run tests
84+
run: ${{ env.CARGO }} test --verbose --workspace ${{ env.TARGET_FLAGS }}
85+
86+
rustfmt:
87+
runs-on: ubuntu-latest
88+
steps:
89+
- name: Checkout repository
90+
uses: actions/checkout@v4
91+
- name: Install Rust
92+
uses: dtolnay/rust-toolchain@master
93+
with:
94+
toolchain: stable
95+
components: rustfmt
96+
- name: Check formatting
97+
run: cargo fmt --all --check
98+
99+
clippy:
100+
runs-on: ubuntu-latest
101+
steps:
102+
- name: Checkout repository
103+
uses: actions/checkout@v4
104+
- name: Install Rust
105+
uses: dtolnay/rust-toolchain@master
106+
with:
107+
toolchain: stable
108+
components: clippy
109+
- name: Run clippy
110+
run: cargo clippy --all-targets --all-features -- -D warnings
111+
112+
docs:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- name: Checkout repository
116+
uses: actions/checkout@v4
117+
- name: Install Rust
118+
uses: dtolnay/rust-toolchain@master
119+
with:
120+
toolchain: stable
121+
- name: Check documentation
122+
env:
123+
RUSTDOCFLAGS: -D warnings
124+
run: cargo doc --no-deps --document-private-items --workspace

.github/workflows/release.yml

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- "[0-9]+.[0-9]+.[0-9]+"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
create-release:
13+
name: create-release
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Get the release version from the tag
18+
if: env.VERSION == ''
19+
run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
20+
- name: Show the version
21+
run: |
22+
echo "version is: $VERSION"
23+
- name: Check that tag version and Cargo.toml version are the same
24+
shell: bash
25+
run: |
26+
if ! grep -q "version = \"$VERSION\"" Cargo.toml; then
27+
echo "version does not match Cargo.toml" >&2
28+
exit 1
29+
fi
30+
- name: Create GitHub release
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
run: gh release create $VERSION --draft --verify-tag --title $VERSION
34+
outputs:
35+
version: ${{ env.VERSION }}
36+
37+
build-release:
38+
name: build-release
39+
needs: ['create-release']
40+
runs-on: ${{ matrix.os }}
41+
env:
42+
CARGO: cargo
43+
TARGET_FLAGS:
44+
TARGET_DIR: ./target
45+
CROSS_VERSION: v0.2.5
46+
RUST_BACKTRACE: 1
47+
strategy:
48+
fail-fast: false
49+
matrix:
50+
include:
51+
- build: linux-x86_64
52+
os: ubuntu-latest
53+
rust: stable
54+
target: x86_64-unknown-linux-musl
55+
strip: x86_64-linux-musl-strip
56+
- build: linux-aarch64
57+
os: ubuntu-latest
58+
rust: stable
59+
target: aarch64-unknown-linux-gnu
60+
strip: aarch64-linux-gnu-strip
61+
- build: linux-arm
62+
os: ubuntu-latest
63+
rust: stable
64+
target: armv7-unknown-linux-gnueabihf
65+
strip: arm-linux-gnueabihf-strip
66+
- build: macos-x86_64
67+
os: macos-latest
68+
rust: stable
69+
target: x86_64-apple-darwin
70+
- build: macos-aarch64
71+
os: macos-latest
72+
rust: stable
73+
target: aarch64-apple-darwin
74+
- build: windows-x86_64
75+
os: windows-latest
76+
rust: stable
77+
target: x86_64-pc-windows-msvc
78+
- build: windows-i686
79+
os: windows-latest
80+
rust: stable
81+
target: i686-pc-windows-msvc
82+
83+
steps:
84+
- name: Checkout repository
85+
uses: actions/checkout@v4
86+
87+
- name: Install Rust
88+
uses: dtolnay/rust-toolchain@master
89+
with:
90+
toolchain: ${{ matrix.rust }}
91+
target: ${{ matrix.target }}
92+
93+
- name: Use Cross
94+
if: matrix.os == 'ubuntu-latest' && matrix.target != ''
95+
shell: bash
96+
run: |
97+
dir="$RUNNER_TEMP/cross-download"
98+
mkdir "$dir"
99+
echo "$dir" >> $GITHUB_PATH
100+
cd "$dir"
101+
curl -LO "https://github.com/cross-rs/cross/releases/download/$CROSS_VERSION/cross-x86_64-unknown-linux-musl.tar.gz"
102+
tar xf cross-x86_64-unknown-linux-musl.tar.gz
103+
echo "CARGO=cross" >> $GITHUB_ENV
104+
105+
- name: Set target variables
106+
shell: bash
107+
run: |
108+
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
109+
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
110+
111+
- name: Show command used for Cargo
112+
shell: bash
113+
run: |
114+
echo "cargo command is: ${{ env.CARGO }}"
115+
echo "target flag is: ${{ env.TARGET_FLAGS }}"
116+
echo "target dir is: ${{ env.TARGET_DIR }}"
117+
118+
- name: Build release binary
119+
shell: bash
120+
run: |
121+
${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }}
122+
if [[ "${{ matrix.os }}" == windows-* ]]; then
123+
bin="target/${{ matrix.target }}/release/mbase.exe"
124+
else
125+
bin="target/${{ matrix.target }}/release/mbase"
126+
fi
127+
echo "BIN=$bin" >> $GITHUB_ENV
128+
129+
- name: Strip release binary (macos)
130+
if: matrix.os == 'macos-latest'
131+
shell: bash
132+
run: strip "$BIN"
133+
134+
- name: Strip release binary (cross)
135+
if: env.CARGO == 'cross'
136+
shell: bash
137+
run: |
138+
docker run --rm -v \
139+
"$PWD/target:/target:Z" \
140+
"ghcr.io/cross-rs/${{ matrix.target }}:main" \
141+
"${{ matrix.strip }}" \
142+
"/$BIN"
143+
144+
- name: Determine archive name
145+
shell: bash
146+
run: |
147+
version="${{ needs.create-release.outputs.version }}"
148+
echo "ARCHIVE=mbase-$version-${{ matrix.target }}" >> $GITHUB_ENV
149+
150+
- name: Creating directory for archive
151+
shell: bash
152+
run: |
153+
mkdir -p "$ARCHIVE"
154+
cp "$BIN" "$ARCHIVE"/
155+
cp README.md "$ARCHIVE"/
156+
cp CONTRIBUTING.md "$ARCHIVE"/
157+
158+
- name: Build archive (Windows)
159+
shell: bash
160+
if: startsWith(matrix.os, 'windows')
161+
run: |
162+
7z a "$ARCHIVE.zip" "$ARCHIVE"
163+
certutil -hashfile "$ARCHIVE.zip" SHA256 > "$ARCHIVE.zip.sha256"
164+
echo "ASSET=$ARCHIVE.zip" >> $GITHUB_ENV
165+
echo "ASSET_SUM=$ARCHIVE.zip.sha256" >> $GITHUB_ENV
166+
167+
- name: Build archive (Unix)
168+
shell: bash
169+
if: ${{ !startsWith(matrix.os, 'windows') }}
170+
run: |
171+
tar czf "$ARCHIVE.tar.gz" "$ARCHIVE"
172+
shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256"
173+
echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV
174+
echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> $GITHUB_ENV
175+
176+
- name: Upload release archive
177+
env:
178+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179+
shell: bash
180+
run: |
181+
version="${{ needs.create-release.outputs.version }}"
182+
gh release upload "$version" ${{ env.ASSET }} ${{ env.ASSET_SUM }}

0 commit comments

Comments
 (0)