Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(GitHub): Refactor build/test workflow #904

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
144 changes: 118 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,82 @@ on:
env:
CARGO_TERM_COLOR: always
jobs:
build:
lint-rust:
name: Lint Rust
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- name: Install latest Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true
components: clippy, rustfmt

- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-lint-${{ hashFiles('./Cargo.lock') }}"

- name: Cargo Format
run:
BUILD_SPIN_EXAMPLES=0 cargo fmt --all -- --check

- name: Cargo Clippy
run:
BUILD_SPIN_EXAMPLES=0 cargo clippy --workspace --all-targets --all-features -- -D warnings

build-rust:
name: Build Spin
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- {
os: "ubuntu-latest",
extension: "",
# We have this enabled for releases, so we should test it.
extraArgs: "--features openssl/vendored",
}
- {
os: "macos-latest",
extension: "",
extraArgs: "",
}
- {
os: "windows-latest",
extension: ".exe",
extraArgs: "",
}
steps:
- uses: actions/checkout@v2

- name: Install latest Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
default: true

- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasi

- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-full-${{ hashFiles('./Cargo.lock') }}"

- name: Cargo Build
run: cargo build --workspace --all-targets --all-features ${{ matrix.config.extraArgs }}

- name: "Archive executable artifact"
uses: actions/upload-artifact@v3
with:
name: spin-${{ matrix.config.os }}
path: target/debug/spin${{ matrix.config.extension }}


test-rust:
name: Test Spin SDK - Rust
runs-on: ${{ matrix.config.os }}
needs: build-rust
strategy:
matrix:
config:
Expand Down Expand Up @@ -69,7 +142,6 @@ jobs:
with:
toolchain: stable
default: true
components: clippy, rustfmt

- name: "Install Wasm Rust target"
run: rustup target add wasm32-wasi
Expand Down Expand Up @@ -107,54 +179,74 @@ jobs:
echo "$((Get-Item .\hippo-server-output).FullName)\win-x64" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append;

- uses: Swatinem/rust-cache@v2
with:
shared-key: "${{ runner.os }}-full-${{ hashFiles('./Cargo.lock') }}"

- name: Cargo Format
if: ${{ matrix.config.platformAgnosticChecks }}
run:
cargo fmt --all -- --check

- name: Cargo Clippy
if: ${{ matrix.config.platformAgnosticChecks }}
run:
cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: Cargo Build
run: cargo build --workspace --all-targets --all-features ${{ matrix.config.extraArgs }}

- name: Cargo Test
- name: Cargo Unit Tests
run: |
make test-unit

- name: Cargo E2E Tests
run: |
make test-e2e
env:
RUST_LOG: spin=trace

test-go:
name: Test Spin SDK - Go
runs-on: ${{ matrix.config.os }}
needs: build-rust
strategy:
matrix:
config:
- {
os: "ubuntu-latest",
bindleUrl: "https://bindle.blob.core.windows.net/releases/bindle-v0.8.0-linux-amd64.tar.gz",
bindleBinary: "bindle-server",
pathInBindleArchive: "bindle-server",
wasmtimeUrl: "https://github.com/bytecodealliance/wasmtime/releases/download/v0.36.0/wasmtime-v0.36.0-x86_64-linux.tar.xz",
wasmtimeBinary: "wasmtime",
pathInWasmtimeArchive: "wasmtime-v0.36.0-x86_64-linux/wasmtime",
}
steps:
- uses: actions/checkout@v2

- name: Retrieve saved Spin Binary
uses: actions/download-artifact@v3
with:
name: spin-ubuntu-latest
path: target/debug/

- name: Fix Spin Binary permissions
run: |
ls -lah target/
ls -lah target/debug
chmod +x target/debug/spin

- name: Install bindle
uses: engineerd/configurator@v0.0.8
with:
name: ${{ matrix.config.bindleBinary }}
url: ${{ matrix.config.bindleUrl }}
pathInArchive: ${{ matrix.config.pathInBindleArchive }}

- name: "Install Go"
if: ${{ matrix.config.platformAgnosticChecks }}
uses: actions/setup-go@v3
with:
go-version: '1.17'

- name: "Install TinyGo"
if: ${{ matrix.config.platformAgnosticChecks }}
run: |
wget https://github.com/tinygo-org/tinygo/releases/download/v0.22.0/tinygo_0.22.0_amd64.deb
sudo dpkg -i tinygo_0.22.0_amd64.deb
tinygo env

- name: "Install Wasmtime"
uses: engineerd/configurator@v0.0.8
if: ${{ matrix.config.platformAgnosticChecks }}
with:
name: ${{ matrix.config.wasmtimeBinary }}
url: ${{ matrix.config.wasmtimeUrl }}
pathInArchive: ${{ matrix.config.pathInWasmtimeArchive }}

- name: "Test Go SDK"
if: ${{ matrix.config.platformAgnosticChecks }}
run: make test-sdk-go

- name: "Archive executable artifact"
uses: actions/upload-artifact@v3
with:
name: spin-${{ matrix.config.os }}
path: target/debug/spin${{ matrix.config.extension }}
20 changes: 15 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::HashMap,
env,
path::Path,
process::{self, Command},
};
Expand All @@ -12,6 +13,20 @@ const RUST_HTTP_VAULT_CONFIG_TEST: &str = "tests/http/vault-config-test";
const RUST_OUTBOUND_REDIS_INTEGRATION_TEST: &str = "tests/outbound-redis/http-rust-outbound-redis";

fn main() {
let mut config = vergen::Config::default();
*config.git_mut().sha_kind_mut() = vergen::ShaKind::Short;
*config.git_mut().commit_timestamp_kind_mut() = vergen::TimestampKind::DateOnly;
vergen::vergen(config).expect("failed to extract build information");

let build_spin_tests = env::var("BUILD_SPIN_EXAMPLES")
.map(|v| v == "1")
.unwrap_or(true);

if !build_spin_tests {
println!("cargo:rerun-if-env-changed=BUILD_SPIN_EXAMPLES");
return;
}

println!("cargo:rerun-if-changed=build.rs");

if !has_wasm32_wasi_target() {
Expand Down Expand Up @@ -57,11 +72,6 @@ error: the `wasm32-wasi` target is not installed
cargo_build(RUST_HTTP_INTEGRATION_ENV_TEST);
cargo_build(RUST_HTTP_VAULT_CONFIG_TEST);
cargo_build(RUST_OUTBOUND_REDIS_INTEGRATION_TEST);

let mut config = vergen::Config::default();
*config.git_mut().sha_kind_mut() = vergen::ShaKind::Short;
*config.git_mut().commit_timestamp_kind_mut() = vergen::TimestampKind::DateOnly;
vergen::vergen(config).expect("failed to extract build information");
}

fn build_wasm_test_program(name: &'static str, root: &'static str) {
Expand Down