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: 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: Cache LLVM | |
id: cache-llvm | |
if: matrix.os == 'windows-latest' | |
uses: actions/cache@v3 | |
with: | |
path: llvm-install | |
key: ${{ runner.os }}-llvm-17.0.4 # Adjust version as needed TODO: Automate this later.. | |
restore-keys: | | |
${{ runner.os }}-llvm- | |
- name: Download and Install LLVM | |
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'windows-latest' | |
run: | | |
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/LLVM-17.0.4-win64.exe" | |
$output = "llvm-installer.exe" | |
Invoke-WebRequest -Uri $url -OutFile $output | |
Start-Process $output -ArgumentList "/S" -NoNewWindow -Wait | |
shell: powershell | |
- name: Set LIBCLANG_PATH | |
if: matrix.os == 'windows-latest' | |
run: | | |
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 | |
shell: powershell | |
- 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: Cache LLVM | |
id: cache-llvm | |
if: matrix.os == 'windows-latest' | |
uses: actions/cache@v3 | |
with: | |
path: llvm-install | |
key: ${{ runner.os }}-llvm-17.0.4 # Adjust version as needed TODO: Automate this later.. | |
restore-keys: | | |
${{ runner.os }}-llvm- | |
- name: Download and Install LLVM | |
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'windows-latest' | |
run: | | |
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/LLVM-17.0.4-win64.exe" | |
$output = "llvm-installer.exe" | |
Invoke-WebRequest -Uri $url -OutFile $output | |
Start-Process $output -ArgumentList "/S" -NoNewWindow -Wait | |
shell: powershell | |
- name: Set LIBCLANG_PATH | |
if: matrix.os == 'windows-latest' | |
run: | | |
echo "LIBCLANG_PATH=C:\Program Files\LLVM\bin" | Out-File -Append -FilePath $env:GITHUB_ENV -Encoding utf8 | |
shell: powershell | |
- 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 }}" |