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: Cache LLVM
id: cache-llvm
if: matrix.os == 'windows-latest'
uses: actions/cache@v3
with:
path: |
C:\Program Files\LLVM
key: ${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4 # Adjust version as needed
restore-keys: |
${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4
- name: Download and Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
run: |
$arch = if ($env:ARCH -eq 'x86_64') { "win64" } else { "woa64" }
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/LLVM-17.0.4-$arch.exe"
echo "Downloading LLVM from $url" # Debugging line
$output = "llvm-installer.exe"
Invoke-WebRequest -Uri $url -OutFile $output
$process = Start-Process $output -ArgumentList "/S" -NoNewWindow -PassThru
$process.WaitForExit()
shell: powershell
env:
ARCH: ${{ matrix.arch }}
- 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
# Debug: Print the LIBCLANG_PATH environment variable
echo "LIBCLANG_PATH: $env:LIBCLANG_PATH"
# Debug: Check if libclang.dll is present
Test-Path "C:\Program Files\LLVM\bin\libclang.dll"
shell: powershell
- name: Run pre-build scripts and test
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh && cargo test
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci && cargo test
else
cargo test
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
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: |
C:\Program Files\LLVM
key: ${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4 # Adjust version as needed
restore-keys: |
${{ matrix.os }}-${{ matrix.arch }}-llvm-17.0.4
- name: Download and Install LLVM
if: steps.cache-llvm.outputs.cache-hit != 'true' && matrix.os == 'windows-latest'
run: |
$arch = if ($env:ARCH -eq 'x86_64') { "win64" } else { "woa64" }
$url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.4/LLVM-17.0.4-$arch.exe"
$output = "llvm-installer.exe"
Invoke-WebRequest -Uri $url -OutFile $output
$process = Start-Process $output -ArgumentList "/S" -NoNewWindow -PassThru
$process.WaitForExit()
shell: powershell
env:
ARCH: ${{ matrix.arch }}
- 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 and build release
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
# Execute Linux pre-build script
bash ./pre-build-linux.sh && cargo build --release
elif [[ "${{ runner.os }}" == "Windows" ]]; then
# Execute Windows pre-build script
powershell -File ./pre-build-win.ps1 --ci && cargo build --release
else
cargo build --release
fi
env:
# Build environment variables
GITHUB_ENV: ${{ github.workspace }}/.env
- 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 }}"