-
Notifications
You must be signed in to change notification settings - Fork 6
100 lines (95 loc) · 3.7 KB
/
build_packages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Build Packages
on:
push:
branches:
- main
tags:
- '*'
pull_request:
jobs:
generate-matrix:
name: Generate matrix for build
runs-on: ubuntu-latest
outputs:
has-matrix: ${{ steps.set-matrix.outputs.has-matrix }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
has-tag: ${{ steps.set-tag.outputs.has-tag }}
tag: ${{ steps.set-tag.outputs.tag }}
steps:
- name: Determine fetch depth
run: echo "FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
- uses: actions/checkout@v4
with:
path: eic-spack
fetch-depth: ${{ env.FETCH_DEPTH }}
- name: Set spack container tag
id: set-tag
run: |
base_ref=${{ github.event.pull_request.base.ref || github.ref }}
if [[ $base_ref =~ ^develop$ ]] ; then
TAG=latest
fi
if [[ $base_ref =~ ^releases/(v[0-9].[0-9]+)$ ]] ; then
TAG=${BASH_REMATCH[1]}.0
fi
if [ -n "$TAG" ] ; then
HAS_TAG=true
fi
echo "tag=${TAG:-}" | tee -a $GITHUB_OUTPUT
echo "has-tag=${HAS_TAG:-false}" | tee -a $GITHUB_OUTPUT
- name: Set modified package matrix
id: set-matrix
run: |
cd eic-spack
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)
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"
HAS_MATRIX=true
fi
done
# Remove last "," and add closing brackets
if [[ $JSON == *, ]]; then
JSON="${JSON%?}"
fi
JSON="$JSON]}"
echo $JSON
# Set output
echo "matrix=$( echo "$JSON" )" | tee -a $GITHUB_OUTPUT
echo "has-matrix=${HAS_MATRIX:-false}" | tee -a $GITHUB_OUTPUT
concretize:
name: Build ${{ matrix.pkg }}
needs: generate-matrix
if: needs.generate-matrix.outputs.has-matrix == 'true' && needs.generate-matrix.outputs.has-tag == 'true'
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
runs-on: ubuntu-latest
container: ghcr.io/spack/ubuntu-jammy:${{needs.generate-matrix.outputs.tag}}
steps:
- uses: actions/checkout@v4
with:
path: key4hep-spack
repository: key4hep/key4hep-spack
- uses: actions/checkout@v4
with:
path: eic-spack
- name: Setup key4hep-spack and eic-spack repositories
run: |
. /opt/spack/share/spack/setup-env.sh
spack repo add ${GITHUB_WORKSPACE}/key4hep-spack
spack repo add ${GITHUB_WORKSPACE}/eic-spack
spack repo list
- name: Concretize package ${{ matrix.pkg }}
run: |
. /opt/spack/share/spack/setup-env.sh
spack spec -I ${{ matrix.pkg }}