Files
velopack/.github/workflows/build.yml
2024-06-01 23:03:07 +01:00

274 lines
9.1 KiB
YAML

name: Build
on: [ push, pull_request ]
jobs:
test-rust-bins:
strategy:
matrix:
os: [macos-13, macos-14, windows-latest, ubuntu-latest]
include:
- os: windows-latest
rust_flags: "--target i686-pc-windows-msvc --features windows"
- os: ubuntu-latest
rust_flags: "--target x86_64-unknown-linux-gnu"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: Swatinem/rust-cache@v2
with:
key: "rust-test-${{ matrix.os }}"
workspaces: "src/Rust -> target"
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install NBGV
run: dotnet tool install -g nbgv
if: startsWith(matrix.os, 'macos-')
continue-on-error: true
- name: Test Rust
working-directory: src/Rust
run: cargo llvm-cov ${{ matrix.rust_flags }} --cobertura --output-path ../../test/coverage.rust.${{ matrix.os }}.xml
- name: Upload Coverage Artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-rust-${{ matrix.os }}
path: ./test/*.xml
build-rust-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: Swatinem/rust-cache@v2
with:
key: "rust-build-windows"
workspaces: "src/Rust -> target"
- name: Build Rust
working-directory: src/Rust
run: cargo bw86 --release
- name: Upload Rust Build Artifacts
uses: actions/upload-artifact@v4
with:
name: rust-windows-latest
path: |
src/Rust/target/i686-pc-windows-msvc/release/*.exe
src/Rust/target/i686-pc-windows-msvc/release/*.pdb
- name: Cancel workflow if failed
uses: andymckay/cancel-action@0.4
if: ${{ failure() }}
build-rust-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: Swatinem/rust-cache@v2
with:
key: "rust-build-linux"
workspaces: "src/Rust -> target"
- name: Build Rust
working-directory: src/Rust
run: |
cargo build --release --target x86_64-unknown-linux-gnu
cp ./target/x86_64-unknown-linux-gnu/release/update ./target/release/UpdateNix
- name: Upload Rust Build Artifacts
uses: actions/upload-artifact@v4
with:
name: rust-ubuntu-latest
path: src/Rust/target/release/UpdateNix
- name: Cancel workflow if failed
uses: andymckay/cancel-action@0.4
if: ${{ failure() }}
build-rust-macos:
strategy:
matrix:
os: [macos-13, macos-14]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: Swatinem/rust-cache@v2
with:
key: "rust-build-${{ matrix.os }}"
workspaces: "src/Rust -> target"
- name: Install NBGV
run: dotnet tool install -g nbgv
continue-on-error: true
- name: Build Rust
working-directory: src/Rust
run: |
cargo build --release
cp ./target/release/update ./target/release/UpdateMac
- name: Upload Rust Build Artifacts
uses: actions/upload-artifact@v4
with:
name: rust-${{ matrix.os }}
path: src/Rust/target/release/UpdateMac
- name: Cancel workflow if failed
uses: andymckay/cancel-action@0.4
if: ${{ failure() }}
build-mac-universal:
runs-on: macos-latest
needs: [build-rust-macos]
steps:
- name: Download x64
uses: actions/download-artifact@v4
with:
name: rust-macos-13
path: macos-x64
- name: Download arm64
uses: actions/download-artifact@v4
with:
name: rust-macos-14
path: macos-arm64
- name: Create Universal Binary
run: |
mkdir -p macos-universal
lipo -create -output macos-universal/UpdateMac macos-x64/UpdateMac macos-arm64/UpdateMac
file macos-universal/UpdateMac
lipo -archs macos-universal/UpdateMac
- name: Upload Universal Binary
uses: actions/upload-artifact@v4
with:
name: rust-macos-latest
path: macos-universal/UpdateMac
- name: Cancel workflow if failed
uses: andymckay/cancel-action@0.4
if: ${{ failure() }}
test-dotnet:
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
VELOPACK_GITHUB_TEST_TOKEN: ${{ secrets.VELOPACK_GITHUB_TEST_TOKEN }}
VELOPACK_B2_TEST_TOKEN: ${{ secrets.VELOPACK_B2_TEST_TOKEN }}
VELOPACK_AZ_TEST_TOKEN: ${{ secrets.VELOPACK_AZ_TEST_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install NBGV
run: dotnet tool install -g nbgv
if: ${{ matrix.os == 'macos-latest' }}
continue-on-error: true
- name: Install FUSE
run: |
sudo add-apt-repository universe
sudo apt install libfuse2
if: ${{ matrix.os == 'ubuntu-latest' }}
- name: Install dotnet-coverage
run: dotnet tool install -g dotnet-coverage
- name: Build .NET
run: dotnet build -c Release
- name: Wait for artifacts
shell: pwsh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # for gh cli
run: |
# Wait 15 minutes for the artifact to become available
$artifactName = "rust-${{ matrix.os }}"
$maxAttempts = 90
$sleepSeconds = 10
$attempt = 0
$workflowRunId = $env:GITHUB_RUN_ID
Write-Host "Waiting for artifact '$artifactName' to become available in workflow run $workflowRunId..."
while ($attempt -lt $maxAttempts) {
$artifactsJson = gh api repos/$env:GITHUB_REPOSITORY/actions/runs/$workflowRunId/artifacts
$artifacts = $artifactsJson | ConvertFrom-Json
if ($artifacts.artifacts | Where-Object { $_.name -eq $artifactName }) {
Write-Host "Artifact '$artifactName' is available, continuing..."
break
}
Write-Host "Artifact not available yet. Attempt $($attempt + 1)/$maxAttempts"
Start-Sleep -Seconds $sleepSeconds
$attempt++
}
if ($attempt -ge $maxAttempts) {
Write-Host "Error: Artifact '$artifactName' did not become available in time."
exit 1
}
- name: Download Rust Artifacts
uses: actions/download-artifact@v4
with:
name: rust-${{ matrix.os }}
path: src/Rust/target/release
- name: Test .NET
run: dotnet test --no-build -c Release -l "console;verbosity=detailed;consoleLoggerParameters=ErrorsOnly" -l GithubActions -- RunConfiguration.CollectSourceInformation=true
- name: Upload Coverage Artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-dotnet-${{ matrix.os }}
path: ./test/*.xml
package:
runs-on: ubuntu-latest
needs: [build-rust-windows, build-rust-linux, build-mac-universal]
steps:
- name: Print dotnet version
run: dotnet --info
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Rust OSX
uses: actions/download-artifact@v4
with:
name: rust-macos-latest
path: src/Rust/target/release
- name: Download Rust Windows
uses: actions/download-artifact@v4
with:
name: rust-windows-latest
path: src/Rust/target/release
- name: Download Rust Linux
uses: actions/download-artifact@v4
with:
name: rust-ubuntu-latest
path: src/Rust/target/release
- name: Build .NET
run: dotnet build -c Release /p:PackRustAssets=true /p:ContinuousIntegrationBuild=true
- name: Upload Package Artifacts
uses: actions/upload-artifact@v4
with:
name: packages
path: build/Release/*nupkg
upload-coverage:
runs-on: ubuntu-latest
needs: [test-rust-bins, test-dotnet, package]
steps:
- name: Download Coverage Artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: ./test
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
directory: ./test
fail_ci_if_error: true
# - name: Publish to GitHub Packages
# shell: pwsh
# run: dotnet nuget push build/Release/*.nupkg -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate