Build and test #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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: | |
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 | |
build-os: | |
type: string | |
default: '' | |
required: false | |
description: Build using this macOS image | |
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) || '' }} | |
OPENFOAM: ${{ inputs.openfoam-version || inputs.openfoam-git-branch }} | |
jobs: | |
deps: | |
runs-on: ${{ inputs.build-os || 'macos-11' }} | |
env: | |
BUILD_OS: ${{ inputs.build-os || 'macos-11' }} | |
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@v3 | |
- 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="deps-${{ env.OPENFOAM }}-${{ env.BUILD_OS }}-${{ hashFiles('make_deps.txt', 'Brewfile') }}-" | |
BUILD_RESTORE_KEY="build-${{ env.OPENFOAM }}-${{ env.BUILD_OS }}-${{ hashFiles('make_build.txt', 'Brewfile', format('OpenFOAM-v${0}.tgz.sha256', inputs.openfoam-version), 'configure.sh') }}-" | |
echo "DEPS_RESTORE_KEY=$DEPS_RESTORE_KEY" >> "$GITHUB_OUTPUT" | |
echo "BUILD_RESTORE_KEY=$BUILD_RESTORE_KEY" >> "$GITHUB_OUTPUT" | |
- name: Look up cached build | |
if: inputs.use-cached | |
id: cache_build | |
uses: actions/cache/restore@v3 | |
with: | |
path: build/*-build.sparsebundle | |
key: ignore | |
restore-keys: | |
${{ steps.caching.outputs.BUILD_RESTORE_KEY }} | |
lookup-only: true | |
- name: Look up cached deps | |
if: inputs.use-cached && steps.cache_build.outputs.cache-matched-key == '' | |
id: cache_deps | |
uses: actions/cache/restore@v3 | |
with: | |
path: build/*-deps.sparsebundle | |
key: ignore | |
restore-keys: | |
${{ steps.caching.outputs.DEPS_RESTORE_KEY }} | |
lookup-only: true | |
- name: Make deps | |
if: steps.cache_build.outputs.cache-matched-key == '' && steps.cache_deps.outputs.cache-matched-key == '' | |
run: | | |
make deps ${{ env.MAKE_VARS }} | |
- name: Save deps to cache | |
if: steps.cache_build.outputs.cache-matched-key == '' && steps.cache_deps.outputs.cache-matched-key == '' | |
uses: actions/cache/save@v3 | |
with: | |
path: build/*-deps.sparsebundle | |
key: ${{ steps.caching.outputs.DEPS_RESTORE_KEY }}${{ github.run_id }} | |
build: | |
needs: deps | |
runs-on: ${{ inputs.build-os || 'macos-11' }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Restore cached build if available | |
if: inputs.use-cached | |
id: cache_build | |
uses: actions/cache/restore@v3 | |
with: | |
path: build/*-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@v3 | |
with: | |
path: build/*-deps.sparsebundle | |
key: ignore | |
restore-keys: | |
${{ needs.deps.outputs.deps-restore-key }} | |
fail-on-cache-miss: true | |
- name: Reuse cached build or deps | |
run: | | |
touch -c build/*-deps.sparsebundle | |
touch -c build/*-build.sparsebundle | |
- name: Build | |
if: steps.cache_build.outputs.cache-matched-key == '' | |
run: | | |
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@v3 | |
with: | |
path: build/*-build.sparsebundle | |
key: ${{ needs.deps.outputs.build-restore-key }}${{ github.run_id }} | |
- name: Make app | |
run: | | |
make zip ${{ env.MAKE_VARS }} | |
- name: Upload app artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: app-${{ env.OPENFOAM }} | |
path: build/*-app-*.zip | |
if-no-files-found: error | |
test: | |
needs: build | |
strategy: | |
matrix: | |
os: [macos-11, macos-12, macos-13] | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download app artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: app-${{ env.OPENFOAM }} | |
path: build | |
- name: Unzip app | |
run: | | |
unzip *-app-*.zip | |
working-directory: build | |
- name: Test | |
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@v3 | |
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 |