Skip to content

Workflow file for this run

name: CI/CD Workflow
on:
push:
branches:
- main
pull_request:
branches:
- "*"
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: "${{ matrix.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
- name: Run pre-build scripts
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
- name: Run tests
run: cargo test
build:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: test
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
runs-on: "${{ matrix.os }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: "${{ matrix.os }}-${{ matrix.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}"
- name: Run pre-build scripts
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
- name: Build Release
run: cargo build --release
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-binary"
path: target/release/smrec
release:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
arch: [aarch64, x86_64]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-binary"
- name: Get version from Cargo.toml
id: get_version
run: echo "::set-output name=version::$(grep '^version =' Cargo.toml | awk -F\" '{print $2}')"
- name: Prepare asset
run: |
mkdir -p ./release
mv ./${{ matrix.os }}-${{ matrix.arch }}-binary ./release/smrec
cd release
zip -r ../smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip .
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.version }}
release_name: smrec v${{ steps.get_version.outputs.version }} - ${{ matrix.os }} ${{ matrix.arch }}
body: "Automatic changelog generation will be applied in the future. This is an auto generated release note."
draft: false
prerelease: false
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_name: smrec_${{ steps.get_version.outputs.version }}_${{ matrix.os }}_${{ matrix.arch }}.zip
asset_content_type: application/zip
- name: Error Handling
if: failure()
run: echo "An error has occurred during the release process"
publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Publish to Crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: "--token ${{ secrets.CRATES_IO_TOKEN }}"