Skip to content

fix(ci): better build matrix, concretize, no build #901

fix(ci): better build matrix, concretize, no build

fix(ci): better build matrix, concretize, no build #901

Workflow file for this run

name: Build Packages
on:
push:
branches:
- main
tags:
- '*'
pull_request:
jobs:
generate-matrix:
name: Generate matrix for build
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
empty: ${{ steps.set-matrix.outputs.empty }}
steps:
- run: echo "FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
- uses: actions/checkout@v3
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
- id: set-matrix
run: |
echo "github.sha=${{ github.sha }}"
echo "github.event.pull_request.head.sha=${{ github.event.pull_request.head.sha }}"
echo "github.event.pull_request.base.sha=${{ github.event.pull_request.base.sha }}"
git diff-tree --no-commit-id --name-only -r ${{ github.event.pull_request.head.sha || github.sha }} ${{ github.event.pull_request.base.sha }}
CHANGED_PACKAGES=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.pull_request.head.sha }} ${{ github.event.pull_request.base.sha }} | sed 's|^packages/||' | xargs -I {} dirname {} | uniq)
EMPTY=true
JSON="{\"include\":["
for pkg in ${CHANGED_PACKAGES} ; do
if [ ! -d packages/$pkg ] ; then continue ; fi
if [ ! -f packages/$pkg/package.py ] ; then continue ; fi
# Add build to the matrix only if it is not already included
JSONline="{\"pkg\": \"$pkg\"},"
if [[ "$JSON" != *"$JSONline"* ]]; then
JSON="$JSON$JSONline"
EMPTY=false
fi
done
# Remove last "," and add closing brackets
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]}"
echo $JSON
# Set output
echo "matrix=$( echo "$JSON" )" >> $GITHUB_OUTPUT
echo "empty=$EMPTY" >> $GITHUB_OUTPUT
concretize:
name: Build ${{ matrix.pkg }}
needs: generate-matrix
if: needs.generate-matrix.outputs.empty == 'false'
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
runs-on: ubuntu-latest
container: ghcr.io/spack/ubuntu-jammy:${{ github.event.pull_request.base.ref || github.ref }}
steps:
- uses: actions/checkout@v3
- name: Setup eic-spack repository
run: |
. /opt/spack/share/spack/setup-env.sh
spack repo add $PWD
spack repo list
- name: Concretize package ${{ matrix.pkg }}
run: |
. /opt/spack/share/spack/setup-env.sh
spack spec -I ${{ matrix.pkg }}