Skip to content

Commit dd7fd6c

Browse files
committed
Added test workflow for self-contained runner
1 parent 1aa1641 commit dd7fd6c

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: self hosted test Singularity Build (within a docker instance)
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: self-hosted
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+
tags: |
41+
type=schedule
42+
type=ref,event=branch
43+
type=ref,event=tag
44+
type=ref,event=pr
45+
type=sha
46+
# type=semver,pattern={{version}}
47+
# type=semver,pattern={{major}}.{{minor}}
48+
49+
build-test-containers:
50+
needs:
51+
- gather-metadata
52+
# - changes
53+
runs-on: self-hosted
54+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
55+
permissions:
56+
contents: read
57+
packages: write
58+
attestations: write
59+
id-token: write
60+
strategy:
61+
# Keep going on other deployments if anything bloops
62+
fail-fast: false
63+
matrix:
64+
# changed_file: ${{ fromJson(needs.changes.outputs.changed_file) }}
65+
changed_file: [ 'installation/Singularity.def' ]
66+
singularity_version:
67+
- '4.3.1'
68+
69+
container:
70+
image: quay.io/singularity/singularity:v${{ matrix.singularity_version }}
71+
options: --privileged
72+
73+
name: Check ${{ matrix.changed_file }}
74+
steps:
75+
76+
- name: Check out code for the container builds
77+
uses: actions/checkout@v6
78+
79+
- name: Continue if Singularity Recipe
80+
run: |
81+
# Continue if we have a changed Singularity recipe
82+
case "${{ matrix.changed_file }}" in
83+
*/Singularity*def)
84+
echo "keepgoing=true" >> "$GITHUB_ENV"
85+
;;
86+
esac
87+
88+
- name: Build Container
89+
if: env.keepgoing == 'true'
90+
env:
91+
recipe: ${{ matrix.changed_file }}
92+
run: |
93+
ls
94+
if [ -f "$recipe" ]; then
95+
sudo -E singularity build --build-arg treecript_checkout=${{ github.sha }} container.sif "$recipe"
96+
tag="${recipe/Singularity\./}"
97+
if [ "$tag" == "def" ]; then
98+
tag=latest
99+
fi
100+
# Build the container and name by tag
101+
echo "Tag is $tag."
102+
echo "tag=$tag" >> "$GITHUB_ENV"
103+
else
104+
echo "$recipe is not found."
105+
echo "Present working directory: $PWD"
106+
ls
107+
fi
108+
109+
- name: Login and Deploy Container
110+
if: (github.event_name != 'pull_request') && ( env.keepgoing == 'true' )
111+
shell: /bin/bash {0}
112+
run: |
113+
singularity registry login -u "${{ github.actor }}" -p "${{ secrets.GITHUB_TOKEN }}" oras://ghcr.io
114+
declare -a tags=( ${{ needs.gather-metadata.outputs.tags }} )
115+
for tag in "${tags[@]}" ; do
116+
singularity push container.sif "oras://ghcr.io/${GITHUB_REPOSITORY}:${tag#*:}"
117+
done

0 commit comments

Comments
 (0)