Skip to content

Build

Build #135

Workflow file for this run

# Copyright (C) 2023 Toitware ApS.
#
# Use of this source code is governed by a BSD0-style license that can be
# found in the LICENSE_BSD0 file.
name: Build
on:
workflow_dispatch:
inputs:
toit-version:
description: Toit SDK version to check out
required: true
type: string
branch:
description: Branch to check out (overrides toit-version)
required: false
type: string
default: ""
upload-release:
description: Upload release artifacts
required: true
type: boolean
default: false
variant:
description: Variant to build
required: false
type: string
gist:
description: Link to gist with variant files
required: false
type: string
jobs:
build:
name: "Build for SDK ${{ github.event.inputs.toit-version }}"
runs-on: ubuntu-latest
steps:
- name: Show inputs
run: echo "${{ toJSON(github.event.inputs) }}"
- uses: actions/checkout@v4
- name: Set the git version
run: |
echo "TOIT_GIT_VERSION=${{ github.event.inputs.toit-version }}" >> $GITHUB_ENV
- name: Fetch the Toit repository
run: |
# We allow the workflow dispatch to override the checked out branch.
# Note that we set the TOIT_GIT_VERSION env variable. The checked out branch
# thus doesn't influence the version of the SDK we build.
REF=${{ github.event.inputs.branch }}
if [[ -z "$REF" ]]; then
REF=${{ github.event.inputs.toit-version }}
fi
make TOIT_VERSION=$REF download-toit
- name: Setup build dependencies
uses: ./toit/actions/setup-build
with:
toit-dir: toit
esp32: true
- name: Ccache stats before SDK build
run: |
ccache -s
- name: Increase ccache max size
run: |
echo "CCACHE_MAXSIZE=600M" >> $GITHUB_ENV
- name: Build the host SDK
run: |
make build-host
- name: Ccache stats after SDK build
run: |
ccache -s
- name: Build the envelope tool
run: |
build/host/sdk/bin/toit.pkg install --project-root=tools
build/host/sdk/bin/toit.compile -o build/envelope-tool tools/main.toit
- name: Setting the variants
run: |
VARIANTS=${{ github.event.inputs.variant }}
if [ -z "$VARIANTS" ]; then
if ! [ -z "${{ github.event.inputs.gist }}" ]; then
VARIANTS="gist"
else
VARIANTS=$(build/envelope-tool list)
if [ $? -ne 0 ]; then
echo "Failed to list variants"
exit 1
fi
fi
fi
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "VARIANTS<<$EOF" >> $GITHUB_ENV
echo "$VARIANTS" >> $GITHUB_ENV
echo "$EOF" >> $GITHUB_ENV
echo "VARIANTS_ROOT=variants" >> $GITHUB_ENV
- name: Download Gist
if: ${{ github.event.inputs.gist }}
run: |
GIST=${{ github.event.inputs.gist }}
mkdir -p "gist-variant/$VARIANTS"
build/envelope-tool download-gist -o "gist-variant/$VARIANTS" "$GIST"
echo "VARIANTS_ROOT=gist-variant" >> $GITHUB_ENV
find gist-variant
- name: Synthesize the variants
run: |
build/envelope-tool synthesize \
--ignore-errors \
--toit-root=toit \
--output-root=synthesized \
--sdk-path=build/host/sdk \
--variants-root=$VARIANTS_ROOT \
--build-root=build \
$VARIANTS
- name: Ccache stats before variants build
run: |
ccache -s
- name: Build the variants
run: |
for variant in $VARIANTS; do
mkdir -p build/$variant
if [ -e synthesized/$variant/failed ]; then
echo "Skipping $variant to due failed synthesis."
touch build/$variant/failed
continue
fi
ccache -s
(cd synthesized/$variant && make) || touch build/$variant/failed
done
- name: Ccache stats after variants build
run: |
ccache -s
- name: Prepare envelopes for upload
run: |
mkdir envelopes
for variant in $VARIANTS; do
if [ -e build/$variant/failed ]; then
echo "Skipping $variant"
continue
fi
cp build/$variant/firmware.envelope envelopes/firmware-$variant.envelope
gzip -9 envelopes/firmware-$variant.envelope
done
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
envelopes
- name: Release
if: ${{ github.event.inputs.upload-release == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: |
envelopes/*
body: |
Envelopes for Toit SDK ${{ github.event.inputs.toit-version }}
allowUpdates: true
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.event.inputs.toit-version }}
commit: main
- name: Report failed builds
if: ${{ github.event.inputs.upload-release == 'true' }}
run: |
build_failed=false
for variant in $VARIANTS; do
if [ -e build/$variant/failed ]; then
echo "Build of $variant failed"
build_failed=true
fi
done
if [ "$build_failed" = true ]; then
exit 1
fi