|
| 1 | +# Copyright (c) 2024 Intel Corporation |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Apptainer CI |
| 16 | +on: |
| 17 | + pull_request: |
| 18 | + paths: |
| 19 | + - 'apptainer/**' |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 23 | + cancel-in-progress: true |
| 24 | + |
| 25 | +permissions: read-all |
| 26 | + |
| 27 | +jobs: |
| 28 | + group-diff: |
| 29 | + runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }} |
| 30 | + outputs: |
| 31 | + groups: ${{ steps.group-list.outputs.FOLDERS }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + - name: Output Modified Group Directories |
| 37 | + id: group-list |
| 38 | + run: | |
| 39 | + # Get diff array filtered by specific filetypes |
| 40 | + DIFF=$(git diff --diff-filter=d \ |
| 41 | + --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }} \ |
| 42 | + -- '*.yaml' '*.yml' '*.def' | \ |
| 43 | + jq -R '.' | jq -sc '.' \ |
| 44 | + ) |
| 45 | + # Search for compose files in each file to determine the container groups |
| 46 | + DOCKER_COMPOSE_PATHS=() |
| 47 | + for path in $(echo $DIFF | jq -r '.[]'); do |
| 48 | + while [[ "$path" != "." ]]; do |
| 49 | + DIR_PATH=$(dirname "$path") |
| 50 | + if [ -n "$(find "$DIR_PATH" -maxdepth 1 -name 'apptainer.def' -print -quit)" ] && [ "$DIR_PATH" != "." ]; then |
| 51 | + DOCKER_COMPOSE_PATHS+=$(echo $"$DIR_PATH" | cut -d'/' -f 2) |
| 52 | + path="." |
| 53 | + else |
| 54 | + path="$DIR_PATH" |
| 55 | + fi |
| 56 | + done |
| 57 | + done |
| 58 | + # Convert the array to a JSON array |
| 59 | + DOCKER_COMPOSE_PATHS_JSON=$(printf '%s\n' "${DOCKER_COMPOSE_PATHS[@]}" | jq -R '.' | jq -sc 'unique_by(.)') |
| 60 | + echo "FOLDERS=$DOCKER_COMPOSE_PATHS_JSON" >> $GITHUB_OUTPUT |
| 61 | +
|
| 62 | + setup-build: |
| 63 | + needs: [group-diff] |
| 64 | + runs-on: ${{ github.repository_owner == 'intel' && 'intel-ubuntu-latest' || 'ubuntu-latest' }} |
| 65 | + if: needs.group-diff.outputs.groups != '[""]' |
| 66 | + strategy: |
| 67 | + matrix: |
| 68 | + group: ${{ fromJson(needs.group-diff.outputs.groups) }} |
| 69 | + experimental: [true] |
| 70 | + fail-fast: false |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + - uses: eWaterCycle/setup-apptainer@v2.0.0 |
| 74 | + with: |
| 75 | + apptainer-version: 1.3.3 |
| 76 | + - name: Apptainer login to registry |
| 77 | + env: |
| 78 | + APPTAINER_DOCKER_USERNAME: ${{ secrets.REGISTRY_USER }} |
| 79 | + APPTAINER_DOCKER_PASSWORD: ${{ secrets.REGISTRY_TOKEN }} |
| 80 | + run: apptainer registry login -u ${{ secrets.REGISTRY_USER }} -p ${{ secrets.REGISTRY_TOKEN }} docker://${{ secrets.REGISTRY }} |
| 81 | + - uses: intel/ai-containers/apptainer@main |
| 82 | + with: |
| 83 | + registry: oras://${{ secrets.REGISTRY }} |
| 84 | + repo: ${{ secrets.REPO }}-apptainer |
| 85 | + group_dir: ${{ matrix.group }} |
0 commit comments