Files
alchemist/.github/workflows/build.yml

515 lines
14 KiB
YAML

name: Build
on:
workflow_call:
inputs:
version_suffix:
description: >
Suffix appended to the VERSION file content.
Empty string for stable releases.
For nightly: "-nightly+abc1234"
type: string
required: false
default: ""
push_docker:
description: Whether to push the Docker image
type: boolean
required: false
default: false
docker_tags:
description: Newline-separated list of Docker tags to push
type: string
required: false
default: ""
prerelease:
description: Whether to mark the GitHub release as prerelease
type: boolean
required: false
default: false
make_latest:
description: Whether to mark as latest release
type: boolean
required: false
default: false
release_tag:
description: The git tag to use for the GitHub release
type: string
required: false
default: ""
release_name:
description: The display name of the GitHub release
type: string
required: false
default: ""
publish_release:
description: Whether to publish a GitHub release
type: boolean
required: false
default: false
env:
IMAGE_NAME: ghcr.io/bybrooklyn/alchemist
jobs:
build-docs:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: package-lock.json
- name: Install docs dependencies
run: npm ci
- name: Read VERSION
id: ver
shell: bash
run: |
base=$(tr -d '\n\r' < VERSION)
echo "version=${base}${{ inputs.version_suffix }}" >> "$GITHUB_OUTPUT"
- name: Build docs site
run: npm run build
- name: Package docs site
shell: bash
run: |
set -euo pipefail
ARCHIVE="alchemist-website-${{ steps.ver.outputs.version }}.zip"
cd build
zip -r "../${ARCHIVE}" .
cd ..
sha256sum "${ARCHIVE}" > "${ARCHIVE}.sha256"
- name: Upload docs artifact
uses: actions/upload-artifact@v4
with:
name: alchemist-website
path: |
alchemist-website-${{ steps.ver.outputs.version }}.zip
alchemist-website-${{ steps.ver.outputs.version }}.zip.sha256
build-frontend:
runs-on: ubuntu-latest
timeout-minutes: 20
defaults:
run:
working-directory: web
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Restore Bun dependency cache
uses: actions/cache@v4
with:
path: |
web/node_modules
~/.bun/install/cache
key: bun-web-${{ runner.os }}-${{ hashFiles('web/bun.lock') }}
restore-keys: |
bun-web-${{ runner.os }}-
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Typecheck
run: bun run typecheck
- name: Astro diagnostics
run: bun run check
- name: Build
run: bun run build
- name: Upload frontend artifact
uses: actions/upload-artifact@v4
with:
name: web-dist-${{ github.run_id }}
path: web/dist
retention-days: 1
build-linux:
needs: [build-frontend]
runs-on: ubuntu-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
artifact_name: alchemist-linux-x86_64
- target: aarch64-unknown-linux-gnu
artifact_name: alchemist-linux-aarch64
env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
SCCACHE_CACHE_SIZE: 2G
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: web-dist-${{ github.run_id }}
path: web/dist
- name: Read VERSION
id: ver
shell: bash
run: |
base=$(tr -d '\n\r' < VERSION)
echo "version=${base}${{ inputs.version_suffix }}" >> "$GITHUB_OUTPUT"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.9
- name: Restore Rust cache
uses: Swatinem/rust-cache@v2
with:
key: build-linux-${{ matrix.target }}
- name: Install aarch64 cross-compiler
if: matrix.target == 'aarch64-unknown-linux-gnu'
shell: bash
run: |
set -euo pipefail
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> "$GITHUB_ENV"
- name: Build
env:
ALCHEMIST_VERSION: ${{ steps.ver.outputs.version }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
set -euo pipefail
BINARY="target/${{ matrix.target }}/release/alchemist"
ARCHIVE="${{ matrix.artifact_name }}.tar.gz"
tar -czf "$ARCHIVE" -C "$(dirname "$BINARY")" "$(basename "$BINARY")"
sha256sum "$ARCHIVE" > "$ARCHIVE.sha256"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: |
${{ matrix.artifact_name }}.tar.gz
${{ matrix.artifact_name }}.tar.gz.sha256
build-windows:
needs: [build-frontend]
runs-on: windows-latest
timeout-minutes: 45
env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
SCCACHE_CACHE_SIZE: 2G
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: web-dist-${{ github.run_id }}
path: web/dist
- name: Read VERSION
id: ver
shell: bash
run: |
base=$(tr -d '\n\r' < VERSION)
echo "version=${base}${{ inputs.version_suffix }}" >> "$GITHUB_OUTPUT"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.9
- name: Restore Rust cache
uses: Swatinem/rust-cache@v2
with:
key: build-windows-x86_64
- name: Build
env:
ALCHEMIST_VERSION: ${{ steps.ver.outputs.version }}
run: cargo build --release --target x86_64-pc-windows-msvc
- name: Package
shell: bash
run: |
set -euo pipefail
cp "target/x86_64-pc-windows-msvc/release/alchemist.exe" \
"alchemist-windows-x86_64.exe"
sha256sum "alchemist-windows-x86_64.exe" \
> "alchemist-windows-x86_64.exe.sha256"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: alchemist-windows-x86_64
path: |
alchemist-windows-x86_64.exe
alchemist-windows-x86_64.exe.sha256
build-macos:
needs: [build-frontend]
runs-on: macos-latest
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-apple-darwin
artifact_name: alchemist-macos-x86_64
- target: aarch64-apple-darwin
artifact_name: alchemist-macos-arm64
env:
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
SCCACHE_CACHE_SIZE: 2G
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: web-dist-${{ github.run_id }}
path: web/dist
- name: Read VERSION
id: ver
shell: bash
run: |
base=$(tr -d '\n\r' < VERSION)
echo "version=${base}${{ inputs.version_suffix }}" >> "$GITHUB_OUTPUT"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install sccache
uses: mozilla-actions/sccache-action@v0.0.9
- name: Restore Rust cache
uses: Swatinem/rust-cache@v2
with:
key: build-macos-${{ matrix.target }}
- name: Build
env:
ALCHEMIST_VERSION: ${{ steps.ver.outputs.version }}
run: cargo build --release --target ${{ matrix.target }}
- name: Package
shell: bash
run: |
set -euo pipefail
BINARY="target/${{ matrix.target }}/release/alchemist"
ARCHIVE="${{ matrix.artifact_name }}.tar.gz"
tar -czf "$ARCHIVE" -C "$(dirname "$BINARY")" "$(basename "$BINARY")"
shasum -a 256 "$ARCHIVE" > "$ARCHIVE.sha256"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: |
${{ matrix.artifact_name }}.tar.gz
${{ matrix.artifact_name }}.tar.gz.sha256
build-docker-image:
needs: [build-linux]
runs-on: ubuntu-latest
timeout-minutes: 45
if: inputs.push_docker
strategy:
fail-fast: false
matrix:
include:
- arch: amd64
artifact_name: alchemist-linux-x86_64
cache_scope: docker-amd64
cache_ref: ghcr.io/bybrooklyn/alchemist:buildcache-amd64
- arch: arm64
artifact_name: alchemist-linux-aarch64
cache_scope: docker-arm64
cache_ref: ghcr.io/bybrooklyn/alchemist:buildcache-arm64
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Download Linux artifact
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: artifacts/${{ matrix.arch }}
- name: Prepare runtime context
shell: bash
run: |
set -euo pipefail
CONTEXT_DIR="runtime-context/${{ matrix.arch }}"
mkdir -p "${CONTEXT_DIR}"
tar -xzf "artifacts/${{ matrix.arch }}/${{ matrix.artifact_name }}.tar.gz" \
-C "${CONTEXT_DIR}"
cp Dockerfile.runtime "${CONTEXT_DIR}/Dockerfile"
chmod +x "${CONTEXT_DIR}/alchemist"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
with:
context: runtime-context/${{ matrix.arch }}
file: runtime-context/${{ matrix.arch }}/Dockerfile
platforms: linux/${{ matrix.arch }}
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
cache-from: |
type=gha,scope=${{ matrix.cache_scope }}
type=registry,ref=${{ matrix.cache_ref }}
cache-to: |
type=gha,scope=${{ matrix.cache_scope }},mode=max
type=registry,ref=${{ matrix.cache_ref }},mode=max,image-manifest=true,oci-mediatypes=true
provenance: false
sbom: false
- name: Export digest
shell: bash
run: |
set -euo pipefail
mkdir -p digests
digest="${{ steps.build.outputs.digest }}"
touch "digests/${digest#sha256:}"
- name: Upload digest artifact
uses: actions/upload-artifact@v4
with:
name: docker-digests-${{ matrix.arch }}
path: digests/*
retention-days: 1
publish-docker-manifest:
needs: [build-docker-image]
runs-on: ubuntu-latest
timeout-minutes: 20
if: inputs.push_docker
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
pattern: docker-digests-*
merge-multiple: true
path: digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Create and inspect manifests
env:
DOCKER_TAGS: ${{ inputs.docker_tags }}
shell: bash
run: |
set -euo pipefail
mapfile -t refs < <(find digests -type f -printf "${IMAGE_NAME}@sha256:%f\n" | sort)
if [ "${#refs[@]}" -eq 0 ]; then
echo "No image digests were downloaded" >&2
exit 1
fi
while IFS= read -r tag; do
[ -n "${tag}" ] || continue
docker buildx imagetools create -t "${tag}" "${refs[@]}"
docker buildx imagetools inspect "${tag}"
done <<< "${DOCKER_TAGS}"
publish-release:
needs:
[build-docs, build-linux, build-windows, build-macos, publish-docker-manifest]
runs-on: ubuntu-latest
timeout-minutes: 20
if: inputs.publish_release
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: alchemist-*
merge-multiple: true
path: release-assets
- name: Publish release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release_tag }}
name: ${{ inputs.release_name }}
prerelease: ${{ inputs.prerelease }}
make_latest: ${{ inputs.make_latest }}
overwrite_files: true
generate_release_notes: false
files: release-assets/*
env:
GITHUB_TOKEN: ${{ github.token }}