Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions .github/actions/build-rust-binary/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# SPDX-License-Identifier: Apache-2.0

name: Build Rust Binary
description: Build, verify, package, and upload an auditable Rust binary

inputs:
package:
description: Cargo package that owns the binary
required: true
binary:
description: Cargo binary name
required: true
triple:
description: Rust target triple
required: true
cargo-version:
description: Cargo package version embedded in the binary
required: true
run-check:
description: Run the binary to check its name; false for a binary cross-built for another architecture
required: false
default: "true"
artifact-name:
description: GitHub artifact name
required: false
default: ""
extra-cargo-flags:
description: Additional flags passed to cargo build
required: false
default: ""
entitlements-file:
description: Path to an entitlements plist for macOS ad-hoc codesigning (skipped when empty or not on macOS)
required: false
default: ""
runs:
using: composite
steps:
# Per-binary caches are large and other branches can restore main's, so
# saving them elsewhere mostly evicts main's from the shared quota.
- uses: ./.github/actions/setup-rust
with:
cache-key: binaries-v2-${{ inputs.binary }}-${{ inputs.triple }}
save-cache: ${{ github.ref == 'refs/heads/main' }}

- name: Set version
shell: nix develop -c bash -euo pipefail {0}
env:
INPUTS_CARGO_VERSION: ${{ inputs.cargo-version }}
run: sed -i "s/^version = \"0\\.0\\.0\"$/version = \"${INPUTS_CARGO_VERSION}\"/" Cargo.toml

- name: Build ${{ inputs.binary }}
shell: nix develop -c bash -euo pipefail {0}
env:
GIT_DIR: /nonexistent
INPUTS_PACKAGE: ${{ inputs.package }}
INPUTS_BINARY: ${{ inputs.binary }}
INPUTS_TRIPLE: ${{ inputs.triple }}
INPUTS_EXTRA_CARGO_FLAGS: ${{ inputs.extra-cargo-flags }}
run: cargo auditable build --release --target "${INPUTS_TRIPLE}" --package "${INPUTS_PACKAGE}" --bin "${INPUTS_BINARY}" ${INPUTS_EXTRA_CARGO_FLAGS}

- name: Verify ${{ inputs.binary }}
shell: nix develop -c bash -euo pipefail {0}
env:
INPUTS_BINARY: ${{ inputs.binary }}
INPUTS_TRIPLE: ${{ inputs.triple }}
INPUTS_RUN_CHECK: ${{ inputs.run-check }}
run: |
binary="target/${INPUTS_TRIPLE}/release/${INPUTS_BINARY}"
# Confirm the binary runs and reports the expected name.
if [ "${INPUTS_RUN_CHECK}" = "true" ]; then
"$binary" --version | grep -q "^${INPUTS_BINARY} "
fi
# Confirm Syft can decode the embedded cargo-auditable metadata.
SYFT_CHECK_FOR_APP_UPDATE=false syft "file:${binary}" -o cyclonedx-json | grep 'pkg:cargo/' > /dev/null

- name: Codesign with entitlements
if: inputs.entitlements-file != '' && runner.os == 'macOS'
shell: bash
env:
INPUTS_ENTITLEMENTS: ${{ inputs.entitlements-file }}
INPUTS_TRIPLE: ${{ inputs.triple }}
INPUTS_BINARY: ${{ inputs.binary }}
run: /usr/bin/codesign --entitlements "${INPUTS_ENTITLEMENTS}" --force -s - "target/${INPUTS_TRIPLE}/release/${INPUTS_BINARY}"

- name: Upload ${{ inputs.binary }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: ${{ inputs.artifact-name || format('{0}-{1}', inputs.binary, inputs.triple) }}
path: target/${{ inputs.triple }}/release/${{ inputs.binary }}
compression-level: 0
retention-days: 5
if-no-files-found: error
43 changes: 43 additions & 0 deletions .github/actions/pull-test-inputs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: Apache-2.0

name: Pull OpenShell test inputs
description: >-
Pull OpenShell's published test-inputs bundle (ghcr.io/ai-openshell/openshell/test-inputs:<sha>)
with ORAS and verify its SHA256SUMS. Nothing from OpenShell is built here. The bundle is a
package of ai-openshell/openshell: the token needs read:packages, or the package must grant this
repository access.

inputs:
test-inputs:
description: ai-openshell/openshell commit whose published bundle to pull
required: true
token:
description: Token that can read the package
required: true
directory:
description: Directory to pull the bundle into (recreated)
required: true

runs:
using: composite
steps:
- name: Install ORAS
uses: oras-project/setup-oras@1d808f7d7f6995cc68b7bf507bfe5c5446e1dc9d # v2.0.0

- name: Pull and verify the bundle
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
TEST_INPUTS: ${{ inputs.test-inputs }}
BUNDLE: ${{ inputs.directory }}
run: |
set -euo pipefail
ref="ghcr.io/ai-openshell/openshell/test-inputs:${TEST_INPUTS}"
echo "${GH_TOKEN}" | oras login ghcr.io -u "${GITHUB_ACTOR}" --password-stdin
rm -rf "$BUNDLE"
mkdir -p "$BUNDLE"
oras pull "$ref" --output "$BUNDLE" || {
echo "::error::Could not pull ${ref}. Is there a Release Dev or Branch E2E run of that commit, and can the token read the package?"
exit 1
}
(cd "$BUNDLE" && sha256sum --quiet -c SHA256SUMS)
51 changes: 51 additions & 0 deletions .github/actions/setup-nix/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# SPDX-License-Identifier: Apache-2.0

name: Setup Nix
description: Install Determinate Nix, configure Cachix, and optionally prepare the development shell

inputs:
cachix-auth-token:
description: Token used to write build outputs to Cachix
required: false
default: ""

prepare-shell:
description: Prepare the development shell, retrying once on failure
required: false
default: "false"
shell-installable:
description: Development shell to prepare
required: false
default: "."

runs:
using: composite
steps:
- uses: DeterminateSystems/determinate-nix-action@e847f25223456b3058e12f7fc9d777b6a6f25060 # v3.23.2
with:
github-token: ${{ github.token }}
summarize: false
# One failed HTTP/2 connection fails every NAR multiplexed on it, and
# Nix fails completed NARs it then resumes at EOF with HTTP 416
# (NixOS/nix#16722). Separate HTTP/1.1 connections limit the damage.
extra-conf: |
http2 = false

- uses: cachix/cachix-action@5f2d7c5294214f71b873db4b969586b980625e71 # v17
with:
name: openshell
authToken: ${{ inputs.cachix-auth-token }}
skipPush: ${{ inputs.cachix-auth-token == '' }}

- name: Prepare Nix development shell
if: inputs.prepare-shell == 'true'
shell: bash
env:
NIX_SHELL_INSTALLABLE: ${{ inputs.shell-installable }}
run: |
# HTTP 416 is not retried by Nix; a fresh invocation restarts downloads.
if nix develop "$NIX_SHELL_INSTALLABLE" -c true; then
exit 0
fi
echo "::warning::Nix shell preparation failed; retrying once."
nix develop "$NIX_SHELL_INSTALLABLE" -c true
38 changes: 38 additions & 0 deletions .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: Apache-2.0

name: Setup Rust
description: Configure Rust caches after setup-nix has prepared the development shell

inputs:
cache-key:
description: Rust target cache namespace
required: true
save-cache:
description: Whether this job writes the Rust target cache
required: false
default: "false"

outputs:
cache-hit:
description: "true when the cache key matched exactly"
value: ${{ steps.cache.outputs.cache-hit }}

runs:
using: composite
steps:
- name: Hash Nix development shell
id: dev-shell
shell: bash
run: |
shell_drv=$(nix eval --raw --impure .#devShells --apply 'shells: shells.${builtins.currentSystem}.default.drvPath')
echo "hash=$(nix hash file --type sha256 --base16 "$shell_drv")" >> "$GITHUB_OUTPUT"

- name: Cache Rust target and registry
id: cache
uses: Swatinem/rust-cache@6a7bc3ebce750e0a16a430dd57485acfdb38b05f
with:
shared-key: ${{ inputs.cache-key }}-${{ steps.dev-shell.outputs.hash }}
save-if: ${{ inputs.save-cache }}
cache-on-failure: ${{ inputs.save-cache }}
cache-bin: "false"
cmd-format: nix develop -c {0}
67 changes: 67 additions & 0 deletions .github/workflows/build-binaries-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-License-Identifier: Apache-2.0

# Builds the Linux binaries of this repository the way OpenShell's build-binaries-linux.yml builds
# its release binaries: release profile, cargo-auditable, in the flake's development shell with the
# cross toolchains. The drivers are built natively for x86_64 and aarch64.

name: Build Linux Binaries

on:
workflow_call:
inputs:
cargo-version:
required: false
type: string
default: "0.0.0"
checkout-ref:
required: false
type: string
default: ""
secrets:
CACHIX_AUTH_TOKEN:
required: false

permissions:
contents: read

jobs:
# The external drivers, linked for the guest like OpenShell's other external drivers (gnu).
drivers:
name: ${{ matrix.binary }} (${{ matrix.triple }})
strategy:
fail-fast: false
matrix:
include:
- package: openshell-driver-docker
binary: openshell-driver-docker
triple: x86_64-unknown-linux-gnu
runner: ubuntu-24.04
- package: openshell-driver-docker
binary: openshell-driver-docker
triple: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
- package: openshell-driver-podman
binary: openshell-driver-podman
triple: x86_64-unknown-linux-gnu
runner: ubuntu-24.04
- package: openshell-driver-podman
binary: openshell-driver-podman
triple: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ inputs.checkout-ref || github.sha }}
- uses: ./.github/actions/setup-nix
with:
prepare-shell: "true"
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- uses: ./.github/actions/build-rust-binary
with:
package: ${{ matrix.package }}
binary: ${{ matrix.binary }}
triple: ${{ matrix.triple }}
cargo-version: ${{ inputs.cargo-version }}
56 changes: 56 additions & 0 deletions .github/workflows/build-binaries-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SPDX-License-Identifier: Apache-2.0

# Builds the macOS binaries of this repository the way OpenShell's build-binaries-macos.yml builds
# its release binaries: release profile, cargo-auditable, in the flake's development shell. Only the
# drivers that run on a macOS host are built; the VM driver has its own workflow.

name: Build macOS Binaries

on:
workflow_call:
inputs:
cargo-version:
required: false
type: string
default: "0.0.0"
checkout-ref:
required: false
type: string
default: ""
secrets:
CACHIX_AUTH_TOKEN:
required: false

permissions:
contents: read

jobs:
build:
name: ${{ matrix.binary }} (${{ matrix.triple }})
strategy:
fail-fast: false
matrix:
include:
- package: openshell-driver-docker
binary: openshell-driver-docker
triple: aarch64-apple-darwin
- package: openshell-driver-podman
binary: openshell-driver-podman
triple: aarch64-apple-darwin
runs-on: macos-15
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ inputs.checkout-ref || github.sha }}
- uses: ./.github/actions/setup-nix
with:
prepare-shell: "true"
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- uses: ./.github/actions/build-rust-binary
with:
package: ${{ matrix.package }}
binary: ${{ matrix.binary }}
triple: ${{ matrix.triple }}
cargo-version: ${{ inputs.cargo-version }}
Loading
Loading