-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GHA workflow for test and release added (#1)
- Loading branch information
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
|
||
permissions: | ||
contents: write | ||
|
||
# Automatically cancel any previous runs of this workflow | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: "clippy, rustfmt" | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Checking formatting | ||
run: cargo fmt -- --check --color always | ||
- name: Running clippy | ||
run: cargo clippy --all-targets --all-features -- -D warnings | ||
|
||
test: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-22.04, macos-12, windows-2022] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Test | ||
run: cargo test --all-targets --all-features && cargo test --doc | ||
|
||
pre-release: | ||
needs: [lint, test] | ||
if: startsWith(github.ref, 'refs/tags/') | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Test | ||
run: cargo publish --locked --dry-run | ||
|
||
release: | ||
needs: pre-release | ||
strategy: | ||
matrix: | ||
include: | ||
- os: ubuntu-22.04 | ||
target: x86_64-unknown-linux-gnu | ||
- os: macos-12 | ||
target: x86_64-apple-darwin | ||
- os: macos-12 | ||
target: aarch64-apple-darwin | ||
- os: windows-2022 | ||
target: x86_64-pc-windows-msvc | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
with: | ||
target: ${{ matrix.target }} | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Build | ||
run: cargo install --locked --target ${{ matrix.target }} --root release --path . | ||
- name: Package | ||
shell: bash | ||
run: | | ||
name=cargo-export | ||
tag=$(git describe --tags --abbrev=0) | ||
release_name="$name-$tag-${{ matrix.target }}" | ||
release_tar="${release_name}.tar.gz" | ||
rm -f "release/.*" | ||
cp README.md LICENSE release/ | ||
mv release/ $release_name/ | ||
tar czvf "$release_tar" "$release_name" | ||
if [ "${{ matrix.target }}" == "x86_64-pc-windows-msvc" ]; then | ||
echo "(Get-FileHash \"${release_tar}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_tar}.sha256\"" | pwsh -c - | ||
else | ||
echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256" | ||
fi | ||
- name: Publish | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
draft: true | ||
files: "cargo-export-*.tar.gz*" |