Skip to content

Replace outdated unified build example with a devcontainer which demonstrates a unified build #14

Replace outdated unified build example with a devcontainer which demonstrates a unified build

Replace outdated unified build example with a devcontainer which demonstrates a unified build #14

name: Validate devcontainer
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
jobs:
validate-devcontainer:
name: Validate devcontainer
runs-on: ubuntu-latest
strategy:
matrix:
devcontainer-name: ["default"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Make devcontainer '${{ matrix.devcontainer-name }}' singular
run: .devcontainer/devcontainer-helper --make-singular ${{ matrix.devcontainer-name }}
- name: Initialize devcontainer
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
echo "Done."
# Even though devcontainers/ci should support $GITHUB_OUTPUT, it doesn't seem to work, so instead we write everything to a file that we later write to $GITHUB_OUTPUT in a non-devcontainer step.
- name: Get cache key parts
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
git config --global --add safe.directory $PWD
rm -f .temporary-github-output
echo "llvm-hash=$(git rev-parse @:./llvm)" >> .temporary-github-output
echo "circt-hash=$(git rev-parse HEAD)" >> .temporary-github-output
echo "cache-key-prefix=\"ccache-devcontainer-${{ matrix.devcontainer-name }}-${DISTRIB_ID}_${DISTRIB_RELEASE}" >> .temporary-github-output
- name: Export cache key parts
id: cache-key-parts
run: |
cat .temporary-github-output
cat .temporary-github-output >> $GITHUB_OUTPUT
rm .temporary-github-output
- name: Restore ccache database
uses: actions/cache/restore@v3
with:
path: ccache
key: ${{ steps.cache-key-parts.outputs.cache-key-prefix }}-llvm_${{ steps.cache-key-parts.outputs.llvm-hash }}-circt_${{ steps.cache-key-parts.outputs.circt-hash }}
restore-keys: |
${{ steps.cache-key-parts.outputs.cache-key-prefix }}-llvm_${{ steps.cache-key-parts.outputs.llvm-hash }}-circt_
${{ steps.cache-key-parts.outputs.cache-key-prefix }}-llvm_
- name: Initialize ccache
uses: devcontainers/[email protected]
with:
# We configure ccache to not evict anything during compilation, and we perform a cleanup after compilation completes
push: never
runCmd: |
date +%s > .workflow-start-seconds
export CCACHE_DIR=$PWD/ccache
ccache -M 1600GB
ccache -sv
ccache -z
- name: Configure CMake Project
id: configure-cmake-project
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
export CCACHE_DIR=$PWD/ccache
git config --global --add safe.directory $PWD
./.devcontainer/cmake-helper configure
# We run the build, once to check the targets and once to log the errors without any progress logs cluttering the output (since it is a trivial incremental build). Please take care to make sure the following two steps stay in sync.
- name: Build Firtool
id: build-cmake-project
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
export CCACHE_DIR=$PWD/ccache
git config --global --add safe.directory $PWD
./.devcontainer/cmake-helper build firtool
- name: Log errors in a separate task
if: ${{ failure() && steps.build-cmake-project.outcome == 'failure' }}
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
export CCACHE_DIR=$PWD/ccache
git config --global --add safe.directory $PWD
./.devcontainer/cmake-helper build firtool
- name: Clean up ccache
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
export CCACHE_DIR=$PWD/ccache
ccache -sv
ccache -M 1GB
ccache --cleanup
ccache -sv
# Save the cache prior to pruning it
- name: Save ccache database
uses: actions/cache/save@v3
if: ${{ always() && steps.configure-cmake-project.outcome == 'success' }}
with:
path: ccache
key: ${{ steps.cache-key-parts.outputs.cache-key-prefix }}-llvm_${{ steps.cache-key-parts.outputs.llvm-hash }}-circt_${{ steps.cache-key-parts.outputs.circt-hash }}
# If evicting everything that wasn't used this workflow does not reduce the cache past its maximum, it may benefit performance to increase the cache size.
- name: Log ccache estimated usage
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
export CCACHE_DIR=$PWD/ccache
ccache --evict-older-than $(($(date +%s) - $(cat .workflow-start-seconds)))s
ccache -sv
rm .workflow-start-seconds
- name: Check that repository is clean
uses: devcontainers/[email protected]
with:
push: never
runCmd: |
git config --global --add safe.directory $PWD
.devcontainer/devcontainer-helper --clean
git diff --exit-code