Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
alisomay committed Nov 3, 2023
1 parent b4c76c7 commit 73336c2
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 9 deletions.
146 changes: 146 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
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 }}"
68 changes: 59 additions & 9 deletions pre-build-win.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
param (
[switch]$ci
)

Write-Output "============================================================================="
Write-Output "Pre build script for cpal asio feature."
Write-Output "Make sure that you have sourced this script instead of directly executing it."
Write-Output "============================================================================="

function Write-Env {
<#
.SYNOPSIS
Sets an environment variable either in the current process or in the GITHUB_ENV file.
.DESCRIPTION
This function sets an environment variable. If the --ci switch is specified when
running the script, it writes the environment variable to the GITHUB_ENV file
so it is available to subsequent steps in a GitHub Actions workflow. Otherwise,
it sets the environment variable in the current process.
.PARAMETER name
The name of the environment variable to set.
.PARAMETER value
The value to set the environment variable to.
.EXAMPLE
Write-Env "MY_VARIABLE" "Some Value"
This example sets the MY_VARIABLE environment variable to "Some Value" in the current process.
.EXAMPLE
.\pre-build-win.ps1 --ci
Write-Env "MY_VARIABLE" "Some Value"
This example, when run within the script with the --ci switch, writes the MY_VARIABLE
environment variable to the GITHUB_ENV file with a value of "Some Value".
#>
param (
[string]$name,
[string]$value
)
if ($ci) {
Write-Output "$name=$value" | Out-File -FilePath $env:GITHUB_ENV -Append
}
else {
[System.Environment]::SetEnvironmentVariable($name, $value, "Process")
}
}

function Invoke-VcVars {
<#
.SYNOPSIS
Expand All @@ -18,11 +63,12 @@ function Invoke-VcVars {
Write-Output "Determining system architecture..."
$arch = if ([Environment]::Is64BitOperatingSystem) {
switch -Wildcard ((Get-CimInstance -ClassName Win32_Processor).Description) {
"*ARM64*"{ "arm64" }
"*ARM*"{ "arm" }
"*ARM64*" { "arm64" }
"*ARM*" { "arm" }
default { "amd64" }
}
} else {
}
else {
"x86"
}

Expand All @@ -31,7 +77,8 @@ function Invoke-VcVars {
# Define search paths based on architecture
$paths = if ($arch -eq 'amd64') {
@('C:\Program Files (x86)\Microsoft Visual Studio\', 'C:\Program Files\Microsoft Visual Studio\')
} else {
}
else {
@('C:\Program Files\Microsoft Visual Studio\')
}

Expand All @@ -46,7 +93,7 @@ function Invoke-VcVars {
if ($line -match "^(.*?)=(.*)$") {
$varName = $matches[1]
$varValue = $matches[2]
[System.Environment]::SetEnvironmentVariable($varName, $varValue, "Process")
Write-Env $varName $varValue
}
}
return
Expand Down Expand Up @@ -86,25 +133,28 @@ if ($env:OS -match "Windows") {
# Move the contents of the inner directory (like asiosdk_2.3.3_2019-06-14) to $asio_dir
$innerDir = Get-ChildItem -Path $out_dir -Directory | Where-Object { $_.Name -match 'asio.*' } | Select-Object -First 1
Move-Item -Path "$($innerDir.FullName)\*" -Destination $asio_dir -Force
} else {
}
else {
Write-Output "ASIO SDK already exists. Skipping download."
}

# Set the CPAL_ASIO_DIR environment variable
Write-Output "Setting CPAL_ASIO_DIR environment variable..."
$env:CPAL_ASIO_DIR = $asio_dir
Write-Env "CPAL_ASIO_DIR" $asio_dir

# Check if LIBCLANG_PATH is set
if (-not $env:LIBCLANG_PATH) {
Write-Error "Error: LIBCLANG_PATH is not set!"
Write-Output "Please ensure LLVM is installed and set the LIBCLANG_PATH environment variable."
exit 1
} else {
}
else {
Write-Output "LIBCLANG_PATH is set to $env:LIBCLANG_PATH."
}

# Run the vcvars function
Invoke-VcVars
} else {
}
else {
Write-Output "This setup script is intended for Windows only."
}

0 comments on commit 73336c2

Please sign in to comment.