Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy as Apptainer container image to GitHub Container Registry | |
on: | |
pull_request: [] | |
push: | |
branches: | |
- main | |
release: | |
types: [ published ] | |
jobs: | |
build-deploy-container: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -leo pipefail {0} | |
permissions: | |
packages: | |
write | |
strategy: | |
matrix: | |
deffiles: [[Singularity, latest]] | |
env: | |
container: nectarchain | |
registry: ghcr.io | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Setup Apptainer | |
uses: eWaterCycle/setup-apptainer@v2 | |
with: | |
apptainer-version: 1.1.7 | |
- name: Build ${{ env.container }} container | |
run: | | |
echo "Preparing to build ${{ env.container }} from ${{ matrix.deffiles[0] }}" | |
if [ ! -f "${{ matrix.deffiles[0]}}" ]; then | |
echo "Singularity definition file ${{ matrix.deffiles[0] }} does not exist" | |
exit 1 | |
fi | |
apptainer build ${{ env.container }}.sif ${{ matrix.deffiles[0] }} | |
ls -lh | |
- name: Login to GitHub Container Registry | |
# Don't log into registry on pull request. | |
if: github.event_name != 'pull_request' | |
run: | | |
echo ${{ github.token }} | apptainer remote login --username ${{ github.actor }} --password-stdin oras://${{ env.registry }} | |
- name: Deploy ${{ env.container }} container ${{ github.ref_name }} | |
# Assign the release tag to container on release | |
if: github.event_name == 'release' | |
run: | | |
fullversionname=${{ github.ref_name }} | |
# Remove the leading "v" character | |
versionname=${fullversionname:1} | |
apptainer push ${{ env.container }}.sif oras://${{ env.registry }}/${{ github.repository }}:${versionname} | |
- name: Deploy ${{ env.container }} container ${{ matrix.deffiles[1] }} | |
# Otherwise, the container tag is "latest" by default. | |
# Don't push the container on a pull request. | |
if: ${{ (github.event_name != 'release') && (github.event_name != 'pull_request') }} | |
run: | | |
apptainer push ${{ env.container }}.sif oras://${{ env.registry }}/${{ github.repository }}:${{ matrix.deffiles[1] }} | |
- name: Post Login to GitHub Container Registry | |
# Don't log out from registry on pull request. | |
if: github.event_name != 'pull_request' | |
run: | | |
apptainer remote logout oras://${{ env.registry }} |