CI and Release Build #10
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
name: Rust | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "**.md" | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- "**.md" | |
workflow_dispatch: | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
features: | |
- "" | |
- "zip" | |
name: Build and Test on ${{ matrix.os }} with features '${{ matrix.features }}' | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
key: ${{ runner.os }}-cargo-${{ matrix.features }}-${{ hashFiles('**/Cargo.lock') }} | |
- uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Install zip (Linux) | |
if: runner.os == 'Linux' | |
run: sudo apt-get install -y zip | |
- name: Install zip (macOS) | |
if: runner.os == 'macOS' | |
run: brew install zip | |
- name: Check | |
run: cargo check --features "${{ matrix.features }}" | |
- name: Test | |
run: cargo test --features "${{ matrix.features }}" | |
- name: Lint | |
run: cargo clippy --all-targets --features "${{ matrix.features }}" -- -D warnings | |
- name: Format | |
run: cargo fmt --all -- --check | |
- name: Build | |
run: cargo build --release --features "${{ matrix.features }}" | |
- name: Set Target Triple (Linux and macOS) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
if [ "${{ runner.os }}" == "Linux" ]; then | |
echo "TARGET_TRIPLE=x86_64-unknown-linux-gnu" >> $GITHUB_ENV | |
elif [ "${{ runner.os }}" == "macOS" ]; then | |
echo "TARGET_TRIPLE=x86_64-apple-darwin" >> $GITHUB_ENV | |
fi | |
- name: Set Target Triple (Windows) | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
echo "TARGET_TRIPLE=x86_64-pc-windows-msvc" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
- name: Set Artifact Name (Linux and macOS) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
if [ "${{ matrix.features }}" != "" ]; then | |
if [ "${{ matrix.features }}" == "zip" ]; then | |
FEATURE_NAME="full" | |
else | |
FEATURE_NAME="${{ matrix.features }}" | |
fi | |
ARTIFACT_NAME="your_project_name-${{ env.TARGET_TRIPLE }}.${FEATURE_NAME}" | |
else | |
ARTIFACT_NAME="your_project_name-${{ env.TARGET_TRIPLE }}" | |
fi | |
echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV | |
- name: Set Artifact Name (Windows) | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
if ($Env:matrix_features -ne "") { | |
if ($Env:matrix_features -eq "zip") { | |
$FEATURE_NAME = "full" | |
} else { | |
$FEATURE_NAME = $Env:matrix_features | |
} | |
$ARTIFACT_NAME = "your_project_name-$Env:TARGET_TRIPLE.$FEATURE_NAME" | |
} else { | |
$ARTIFACT_NAME = "your_project_name-$Env:TARGET_TRIPLE" | |
} | |
echo "ARTIFACT_NAME=$ARTIFACT_NAME" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
- name: Create Zip Archive (Linux and macOS) | |
if: runner.os != 'Windows' | |
shell: bash | |
run: | | |
mkdir -p artifacts | |
zip -j "artifacts/${{ env.ARTIFACT_NAME }}.zip" "target/release/your_executable_name" | |
- name: Create Zip Archive (Windows) | |
if: runner.os == 'Windows' | |
shell: pwsh | |
run: | | |
New-Item -ItemType Directory -Path artifacts | |
Compress-Archive -Path "target\release\your_executable_name.exe" -DestinationPath "artifacts\$($Env:ARTIFACT_NAME).zip" | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }}.zip | |
path: artifacts/${{ env.ARTIFACT_NAME }}.zip |