Skip to content

Merge pull request #6 from vdblab/fix_set_output #133

Merge pull request #6 from vdblab/fix_set_output

Merge pull request #6 from vdblab/fix_set_output #133

Workflow file for this run

name: 'build'
on:
push:
branches:
- main
pull_request:
jobs:
list-manifests:
runs-on: ubuntu-latest
outputs:
#
# DRYRUN: ["rgi,5.2.1", "redcap,1.0.0"]
#
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- id: set-matrix
run: echo "matrix=$(cat build_manifest.csv |grep -v '^#' | jq --raw-input . | jq -c --slurp .)" >> $GITHUB_OUTPUT
build:
name: 'Build'
needs: list-manifests
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
manifest: ${{ fromJson(needs.list-manifests.outputs.matrix) }}
steps:
- name: "Build:checkout"
uses: actions/checkout@v2
# there is likely a more elegant way to parse this back in the list-manifests step.
# See https://code.dblock.org/2021/09/03/generating-task-matrix-by-looping-over-repo-files-with-github-actions.html and
# https://stackoverflow.com/questions/73402042/github-action-expressions-split-string and
# https://stackoverflow.com/questions/66025220/paired-values-in-github-actions-matrix for inspiration
- name: Get version
env:
tool_ver: ${{ matrix.manifest }}
id: versplit
run: echo "VERSION=${tool_ver##*,}" >> $GITHUB_OUTPUT
- name: Get tool
env:
tool_ver: ${{ matrix.manifest }}
id: toolsplit
run: echo "TOOL=${tool_ver%,*}" >> $GITHUB_OUTPUT
- name: build/doihaveto
id: checkregistry
env:
PAT: ${{ secrets.GITHUB_TOKEN }}
URL: "https://ghcr.io/v2/vdblab/${{ steps.toolsplit.outputs.TOOL }}/manifests/${{ steps.versplit.outputs.VERSION }}"
run: |
# curl_result=$(curl -v -X GET ${URL} -u vdblab:${{ secrets.GITHUB_TOKEN }})
# echo ::debug::echo $curl_result
# result=$(echo $curl_result | jq '.')
# echo ::debug::echo $result
# echo "RUN=$result" >> $GITHUB_OUTPUT
echo "EXISTS=$(docker manifest inspect ghcr.io/vdblab/${{ steps.toolsplit.outputs.TOOL }}:${{ steps.versplit.outputs.VERSION }} > /dev/null ; echo $?)" >> $GITHUB_OUTPUT
- name: build/doihavetocheck
id: checkregistryres
run: |
echo "::debug::${{ steps.checkregistry.outputs.EXISTS }}"
echo "::debug::${{ steps.versplit.outputs.VERSION }}"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: "ghcr.io"
username: vdblab
password: ${{ secrets.GITHUB_TOKEN }}
- name: 'Build:dockerimage'
# we want the actions's "if" to evaluate to true if the tag doesnt exist,
# so we try it to list the tag via curl; if that fails, let it return a successfull exit code via the echo statment
# otherwise raise an error
uses: docker/build-push-action@v2
env:
REGISTRY: "ghcr.io"
VERSION: ${{ steps.versplit.outputs.VERSION }}
TOOL: ${{ steps.toolsplit.outputs.TOOL }}
if: steps.checkregistry.outputs.EXISTS != 0
with:
build-args: "VERSION=${{ env.VERSION }}"
file: "${{ env.TOOL }}/Dockerfile"
context: "${{ env.TOOL }}/"
push: true
tags: "${{ env.REGISTRY }}/vdblab/${{ env.TOOL }}:${{ env.VERSION }}"