-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (95 loc) · 3.69 KB
/
build-containers.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
101
102
103
104
105
106
107
108
109
name: Singularity Build (docker)
on:
push:
# Edit the branches here if you want to change deploy behavior
branches:
- master
# Do the builds on all pull requests (to test them)
pull_request: []
jobs:
changes:
name: "Changed Singularity Recipes"
runs-on: ubuntu-latest
outputs:
changed_files: ${{ steps.combine.outputs.changed_files }}
steps:
- id: files
uses: Ana06/get-changed-files@v2.0.0
with:
format: 'json'
- id: combine
run: |
echo '${{ steps.files.outputs.added_modified }}' | tee added_modified.json
echo '${{ steps.files.outputs.renamed }}' | tee renamed.json
changes="$(cat added_modified.json renamed.json | jq -r -s 'add | unique | sort')"
echo "Added, modified, renamed files: $changes"
echo ::set-output name=changed_files::$(echo $changes | jq -c .)
build-test-containers:
needs:
- changes
runs-on: ubuntu-latest
strategy:
# Keep going on other deployments if anything bloops
fail-fast: false
matrix:
singularity_version:
- '3.9.2'
program:
- 'mrchem'
version:
- '1.0.2'
#- 'master'
variant:
- 'nompi'
#- 'openmpi4.0.5'
container:
image: quay.io/singularity/singularity:v${{ matrix.singularity_version }}
options: --privileged
name: Build ${{ matrix.program }}-${{ matrix.version }}-${{ matrix.variant }}
steps:
- name: Check out code for the container builds
uses: actions/checkout@v2
- name: Continue if the singularity recipe was changed
run: |
apk add jq
# Continue if the Singularity recipes changed
echo "Added, modified, removed files:"
echo '${{ needs.changes.outputs.changed_files }}' | tee changed_files.json
changed="true" #"$(cat changed_files.json | jq 'any(.[]; . == "Singularity.${{ matrix.variant }}")')"
if [[ "$changed" == "true" ]]; then
echo "Container to build: Singularity.v${{ matrix.version }}-${{ matrix.variant }}"
echo "keepgoing=true" >> $GITHUB_ENV
else
echo "Nothing to build!"
fi
- name: Build container
if: ${{ env.keepgoing == 'true' }}
env:
image_name: ${{ matrix.program }}-${{ matrix.version }}-${{ matrix.variant }}
pre_recipe: Singularity.${{ matrix.variant }}
post_recipe: Singularity.${{ matrix.version }}-${{ matrix.variant }}
run: |
echo "Building version ${{ matrix.version }} of ${{ matrix.program }}"
if [[ "${keepgoing}" == "true" ]]; then
echo "IMAGE_NAME=$image_name" >> $GITHUB_ENV
sed "s/@_VERSION_@/${{ matrix.version }}/g" "$pre_recipe" > "$post_recipe"
sudo -E singularity build container.sif "$post_recipe"
# use latest as tag
tag="latest"
# Build the container and name by tag
echo "TAG=$tag" >> $GITHUB_ENV
else
echo "No changes in $image_name"
echo "Present working directory: $PWD"
ls
fi
- name: Login and deploy container
if: (github.event_name != 'pull_request')
env:
keepgoing: ${{ env.keepgoing }}
run: |
if [[ "${keepgoing}" == "true" ]]; then
echo ${{ secrets.GITHUB_TOKEN }} | singularity remote login -u ${{ secrets.GHCR_USERNAME }} --password-stdin oras://ghcr.io
echo "Pushing $IMAGE_NAME with tag $TAG"
singularity push container.sif oras://ghcr.io/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${TAG}
fi