|
| 1 | +name: Singularity Build (docker) |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | + # # Do the builds on all pull requests (to test them) |
| 9 | + # pull_request: |
| 10 | + |
| 11 | +jobs: |
| 12 | + #changes: |
| 13 | + # name: "Changed Singularity Recipes" |
| 14 | + # runs-on: ubuntu-latest |
| 15 | + # outputs: |
| 16 | + # changed_file: ${{ steps.files.outputs.added_modified }} |
| 17 | + # steps: |
| 18 | + # - id: files |
| 19 | + # uses: jitterbit/get-changed-files@d06c756e3609dd3dd5d302dde8d1339af3f790f2 |
| 20 | + # with: |
| 21 | + # format: 'json' |
| 22 | + gather-metadata: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + tags: ${{ steps.meta.outputs.tags }} |
| 26 | + labels: ${{ steps.meta.outputs.labels }} |
| 27 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 28 | + permissions: |
| 29 | + contents: read |
| 30 | + packages: write |
| 31 | + attestations: write |
| 32 | + id-token: write |
| 33 | + # |
| 34 | + steps: |
| 35 | + - name: Extract metadata (tags, labels) for Docker |
| 36 | + id: meta |
| 37 | + uses: docker/metadata-action@v6.0.0 |
| 38 | + with: |
| 39 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 40 | + |
| 41 | + build-test-containers: |
| 42 | + needs: |
| 43 | + - gather-metadata |
| 44 | + # - changes |
| 45 | + runs-on: ubuntu-latest |
| 46 | + strategy: |
| 47 | + # Keep going on other deployments if anything bloops |
| 48 | + fail-fast: false |
| 49 | + matrix: |
| 50 | + # changed_file: ${{ fromJson(needs.changes.outputs.changed_file) }} |
| 51 | + changed_file: [ 'installation/Singularity.def' ] |
| 52 | + singularity_version: |
| 53 | + - '4.3.1' |
| 54 | + |
| 55 | + container: |
| 56 | + image: quay.io/singularity/singularity:v${{ matrix.singularity_version }} |
| 57 | + options: --privileged |
| 58 | + |
| 59 | + name: Check ${{ matrix.changed_file }} |
| 60 | + steps: |
| 61 | + |
| 62 | + - name: Check out code for the container builds |
| 63 | + uses: actions/checkout@v6 |
| 64 | + |
| 65 | + - name: Continue if Singularity Recipe |
| 66 | + run: | |
| 67 | + # Continue if we have a changed Singularity recipe |
| 68 | + case "${{ matrix.changed_file }}" in |
| 69 | + */Singularity*def) |
| 70 | + echo "keepgoing=true" >> "$GITHUB_ENV" |
| 71 | + ;; |
| 72 | + esac |
| 73 | +
|
| 74 | + - name: Build Container |
| 75 | + if: ${{ env.keepgoing == 'true' }} |
| 76 | + env: |
| 77 | + recipe: ${{ matrix.changed_file }} |
| 78 | + run: | |
| 79 | + ls |
| 80 | + if [ -f "$recipe" ]; then |
| 81 | + sudo -E singularity build --build-arg treecript_checkout=${{ github.sha }} container.sif "$recipe" |
| 82 | + tag="${recipe/Singularity\./}" |
| 83 | + if [ "$tag" == "def" ]; then |
| 84 | + tag=latest |
| 85 | + fi |
| 86 | + # Build the container and name by tag |
| 87 | + echo "Tag is $tag." |
| 88 | + echo "tag=$tag" >> "$GITHUB_ENV" |
| 89 | + else |
| 90 | + echo "$recipe is not found." |
| 91 | + echo "Present working directory: $PWD" |
| 92 | + ls |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Login and Deploy Container |
| 96 | + if: (github.event_name != 'pull_request') |
| 97 | + env: |
| 98 | + keepgoing: ${{ env.keepgoing }} |
| 99 | + run: | |
| 100 | + if [[ "${keepgoing}" == "true" ]]; then |
| 101 | + echo "${{ secrets.GITHUB_TOKEN }}" | singularity remote login -u "${{ secrets.GHCR_USERNAME }}" --password-stdin oras://ghcr.io |
| 102 | + declare -a tags=( ${{ needs.gather-metadata.outputs.tags }} ) |
| 103 | + for tag in "${tags[@]}" ; do |
| 104 | + echo singularity push container.sif "oras://ghcr.io/${GITHUB_REPOSITORY}:${tag}" |
| 105 | + done |
| 106 | + fi |
0 commit comments