Skip to content

Removed ref to old singularity env #2

Removed ref to old singularity env

Removed ref to old singularity env #2

---
name: Build and push container images
on:
push:
pull_request:
workflow_dispatch:
repository_dispatch:
types: [dispatch-build]
jobs:
build-image-list:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.image-list.outputs.json }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: image-list
run: |
ORG_DIR=htc
# Get the list of files changed based on the type of event
# kicking off the GHA:
# 1. For the main branch, diff the previous state of main vs
# the current commit
# 2. For other branches (i.e., on someone's fork), diff main
# vs the current commit
# 3. For PRs, diff the base ref vs the current commit
# 4. For everything else (e.g., dispatches), build all images
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]] ||
[[ $GITHUB_EVENT_NAME == 'push' ]]; then
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then
BASE=$(git merge-base origin/$GITHUB_BASE_REF HEAD)
elif [[ $GITHUB_REF == 'refs/heads/main' ]]; then
BASE=${{github.event.before}}
else
BASE=origin/main
fi
# List image root dirs where files have changed and the
# root dir exists. Example value:
# "opensciencegrid/vo-frontend opensciencegrid/ospool-cm"
images=$(git diff --name-only \
"$BASE" \
"$GITHUB_SHA" |
egrep "^$ORG_DIR/" |
cut -d/ -f -2 |
sort |
uniq |
xargs -I {} find . -type d \
-wholename ./{} \
-printf "%P\n")
else
# List all image root dirs. Example value:
# "opensciencegrid/vo-frontend opensciencegrid/ospool-cm"
images=$(find $ORG_DIR -mindepth 1 \
-maxdepth 1 \
-type d \
-printf "$ORG_DIR/%P\n")
fi
# Ensure that the generated JSON array has a member,
# otherwise GHA will throw an error about an empty matrix
# vector in subsequent steps
image_json=$(echo -n "${images:-dummy}" | jq -Rcs '.|split("\n")')
echo "json=$image_json" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: build-image-list
if: needs.build-image-list.outputs.images != '["dummy"]'
# Prevent a single build failure from killing the workflow.
# This is safe since subsequent pushes should fail on cache load
continue-on-error: true
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.build-image-list.outputs.images) }}
steps:
- name: Build ${{ matrix.image }}
uses: opensciencegrid/[email protected]
with:
context: ${{ matrix.image }}
push:
runs-on: ubuntu-latest
if: >-
github.ref == 'refs/heads/main' &&
github.event_name != 'pull_request' &&
github.repository_owner == 'htc' &&
needs.build-image-list.outputs.images != '["dummy"]'
needs: [build-image-list, build]
strategy:
fail-fast: false
matrix:
image: ${{ fromJson(needs.build-image-list.outputs.images) }}
steps:
- name: Push to Harbor
if: always()
uses: opensciencegrid/[email protected]
with:
context: ${{ matrix.image }}
registry_url: hub.opensciencegrid.org
registry_user: ${{ secrets.OSG_HARBOR_ROBOT_USER }}
registry_pass: ${{ secrets.OSG_HARBOR_ROBOT_PASSWORD }}