build multiple #442
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
# Allows to build multiple projects in a matrix. | |
# - found out which projects to build | |
# - if any, build them in a matrix | |
# This runs on: | |
# - workflow_call: this is used by pr_flow.yml to build multiple projects (PUSHING the results to a branch) | |
# - workflow_dispatch: to manually trigger builds (NOT pushing the results to any branch), | |
# optionally listing the projects targeted | |
# - schedule: once a month for all of them (NOT pushing the results to any branch) | |
name: build multiple | |
on: | |
workflow_call: | |
inputs: | |
projects: | |
description: JSON-like list of projects | |
type: string | |
required: false | |
type: | |
description: hack | |
type: string | |
required: true | |
branch: | |
description: Branch suffix to push the evaluated projects to | |
type: string | |
required: true | |
default: '' | |
# To be used by pr_flow and passed down to the workflow | |
# that builds the docs. | |
outputs: | |
projects: | |
description: "Projects to build" | |
value: ${{ jobs.infer_matrix.outputs.projects }} | |
# Can be run from GH UI | |
workflow_dispatch: | |
inputs: | |
all: | |
description: all the projects | |
type: boolean | |
default: false | |
required: true | |
projects: | |
description: comma-separated list | |
type: string | |
required: false | |
schedule: | |
# 3rd day of the month at 12 (avoiding 1st day that may have more load) | |
- cron: '0 12 3 * *' | |
jobs: | |
# TODO: same as test.yml, share them? | |
inferprojects: | |
runs-on: 'ubuntu-latest' | |
timeout-minutes: 10 | |
defaults: | |
run: | |
shell: bash -l {0} | |
outputs: | |
projects: ${{ steps.set-projects.outputs.projects }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
- name: install deps | |
# Minimal required deps to run the following script | |
run: pip install doit pyyaml | |
- name: infer project list | |
id: set-projects | |
run: | | |
EVENTNAME="${{ github.event_name }}" | |
ALL="${{ inputs.all }}" | |
# IMPORTANT: the single quote here matters to preserve the JSON structure of the data | |
INPUTS='${{ inputs.projects }}' | |
echo $INPUTS | |
if [ "${{ inputs.type }}" == "workflow_call" ]; then | |
# IMPORTANT: same comment as above. | |
PROJECTS=$INPUTS | |
elif [ "$EVENTNAME" == "workflow_dispatch" ]; then | |
if [ "$ALL" == "true" ]; then | |
PROJECTS=$(doit util_list_project_dir_names | tail -n -1) | |
else | |
echo "$INPUTS" > .projects | |
PROJECTS=$(doit util_list_comma_separated_projects | tail -n -1) | |
rm .projects | |
fi | |
elif [ "$EVENTNAME" == "schedule" ]; then | |
PROJECTS=$(doit util_list_project_dir_names | tail -n -1) | |
fi | |
echo "Projects: $PROJECTS" | |
echo "PROJECTS=$PROJECTS" >> $GITHUB_OUTPUT | |
build_sequential: | |
needs: inferprojects | |
if: inputs.type == 'workflow_call' && needs.inferprojects.outputs.projects != '[]' | |
name: Build ${{ matrix.project }} | |
strategy: | |
# Sequential builds to avoid race conditions when pushing to the tmp dev branch | |
fail-fast: true | |
max-parallel: 1 | |
matrix: | |
project: ${{ fromJson(needs.inferprojects.outputs.projects) }} | |
uses: ./.github/workflows/build_one.yml | |
with: | |
project: ${{ matrix.project }} | |
type: ${{ inputs.type }} | |
branch: ${{ inputs.branch }} | |
build_matrix: | |
needs: inferprojects | |
if: ( inputs.type == 'workflow_dispatch' || github.event_name == 'schedule' ) && needs.inferprojects.outputs.projects != '[]' | |
name: Build ${{ matrix.project }} | |
strategy: | |
fail-fast: false | |
matrix: | |
project: ${{ fromJson(needs.inferprojects.outputs.projects) }} | |
uses: ./.github/workflows/build_one.yml | |
with: | |
project: ${{ matrix.project }} | |
type: ${{ inputs.type }} |