Skip to content

Build and test

Build and test #8

Workflow file for this run

name: Build and test
on:
workflow_call:
inputs:
openfoam-version:
type: string
default: ''
required: false
app-version:
type: string
default: ''
required: false
app-name:
type: string
default: ''
required: false
openfoam-git-branch:
type: string
default: ''
required: false
deps-kind:
type: string
default: ''
required: false
build-os:
type: string
default: ''
required: false
use-cached:
type: boolean
default: true
required: false
cache-build:
type: boolean
default: true
required: false
release:
type: boolean
default: false
required: false
workflow_dispatch:
inputs:
build-os:
type: string
required: true
description: Build using this macOS image
openfoam-version:
type: string
default: ''
required: false
description: Build this OpenFOAM version
app-name:
type: string
default: ''
required: false
description: Override app name
openfoam-git-branch:
type: string
default: ''
required: false
description: Build this OpenFOAM Git branch
deps-kind:
type: choice
required: false
description: Bundle dependencies in this manner
options:
- ''
- standalone
- bundled
- homebrew
use-cached:
type: boolean
default: true
required: false
description: Reuse cached build artifacts if available
cache-build:
type: boolean
default: true
required: false
description: Cache build artifacts for later reuse
env:
MAKE_VARS: >
${{ inputs.openfoam-version != '' && format('OPENFOAM_VERSION={0}', inputs.openfoam-version) || '' }}
${{ inputs.app-version != '' && format('APP_VERSION={0}', inputs.app-version) || '' }}
${{ inputs.app-name != '' && format('APP_NAME={0}', inputs.app-name) || '' }}
${{ inputs.openfoam-git-branch != '' && format('OPENFOAM_GIT_BRANCH={0}', inputs.openfoam-git-branch) || '' }}
${{ inputs.deps-kind != '' && format('DEPS_KIND={0}', inputs.deps-kind) || '' }}
OPENFOAM: ${{ inputs.openfoam-version || inputs.openfoam-git-branch }}
jobs:
deps:
runs-on: ${{ inputs.build-os }}
outputs:
deps-restore-key: ${{ steps.caching.outputs.DEPS_RESTORE_KEY }}
build-restore-key: ${{ steps.caching.outputs.BUILD_RESTORE_KEY }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get Make recipes for caching
run: |
make deps --dry-run ${{ env.MAKE_VARS }} > make_deps.txt
make build --dry-run ${{ env.MAKE_VARS }} > make_build.txt
- name: Generate cache restore keys
id: caching
run: |
DEPS_RESTORE_KEY="build-${{ env.OPENFOAM }}-${{ inputs.build-os }}-${{ inputs.deps-kind }}-${{ hashFiles('make_deps.txt', 'Brewfile', 'scripts/bundle_deps.py') }}"
BUILD_RESTORE_KEY="$DEPS_RESTORE_KEY-${{ hashFiles('make_build.txt', 'scripts/configure.sh', 'scripts/relativize_install_names.py') }}"
echo "DEPS_RESTORE_KEY=$DEPS_RESTORE_KEY" >> "$GITHUB_OUTPUT"
echo "BUILD_RESTORE_KEY=$BUILD_RESTORE_KEY" >> "$GITHUB_OUTPUT"
- name: Look up cached deps
id: cache_deps
if: inputs.use-cached
uses: actions/cache/restore@v4
with:
path: build/*.sparsebundle
key: ignore
restore-keys: |
${{ steps.caching.outputs.DEPS_RESTORE_KEY }}
lookup-only: true
- name: Make deps
if: steps.cache_deps.outputs.cache-matched-key == ''
run: |
make deps ${{ env.MAKE_VARS }}
- name: Save deps to cache
if: steps.cache_deps.outputs.cache-matched-key == ''
uses: actions/cache/save@v4
with:
path: build/*.sparsebundle
key: ${{ steps.caching.outputs.DEPS_RESTORE_KEY }}-${{ github.run_id }}
build:
needs: deps
runs-on: ${{ inputs.build-os }}
outputs:
arch: ${{ runner.arch }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore cached build if available
if: inputs.use-cached
id: cache_build
uses: actions/cache/restore@v4
with:
path: build/*.sparsebundle
key: ignore
restore-keys: |
${{ needs.deps.outputs.build-restore-key }}
- name: Restore cached deps
if: steps.cache_build.outputs.cache-matched-key == ''
id: cache_deps
uses: actions/cache/restore@v4
with:
path: build/*.sparsebundle
key: ignore
restore-keys: |
${{ needs.deps.outputs.deps-restore-key }}
fail-on-cache-miss: true
- name: Build
if: steps.cache_build.outputs.cache-matched-key == ''
run: |
hdiutil attach build/*.sparsebundle
make --touch deps ${{ env.MAKE_VARS }}
make build ${{ env.MAKE_VARS }}
- name: Save build to cache
if: steps.cache_build.outputs.cache-matched-key == '' && inputs.cache-build
uses: actions/cache/save@v4
with:
path: build/*.sparsebundle
key: ${{ needs.deps.outputs.build-restore-key }}-${{ github.run_id }}
- name: Make app
run: |
hdiutil attach build/*.sparsebundle
make --touch build ${{ env.MAKE_VARS }}
make zip ${{ env.MAKE_VARS }}
- name: Upload app artifact
uses: actions/upload-artifact@v4
with:
name: app-${{ env.OPENFOAM }}-${{ runner.arch }}
path: build/*-app-*.zip
if-no-files-found: error
test:
needs: build
strategy:
matrix:
os: [macos-12, macos-13, macos-14]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Homebrew dependencies
if: inputs.deps-kind == 'homebrew'
run: |
brew bundle
- name: Download app artifact
uses: actions/download-artifact@v4
with:
name: app-${{ env.OPENFOAM }}-${{ needs.build.outputs.arch }}
path: build
- name: Unzip app
run: |
unzip *-app-*.zip
working-directory: build
- name: Test
if: needs.build.outputs.arch == runner.arch
run: |
make test ${{ env.MAKE_VARS }}
release:
needs: test
if: inputs.release
runs-on: ubuntu-latest
steps:
- name: Download app artifact
uses: actions/download-artifact@v4
with:
name: app-${{ env.OPENFOAM }}
- name: Upload app to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: '*-app-*.zip'
tag: ${{ github.ref }}
file_glob: true
overwrite: false