Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Added build matrix to handle linting of multiple Dockerfiles #10

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,63 @@
# Build container images according to https://github.com/marketplace/actions/build-and-push-docker-images
name: ci
#on: [push, pull_request]
on:
push:
branches:
- 'master'
on: [push, pull_request]
#on:
# push:
# branches:
# - 'master'

jobs:
matrix:
# Generate matrix for linting (essentially locating all Dockerfile directories)
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-dockerfiles.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- id: set-dockerfiles
run: |
#echo "::set-output name=matrix::$(./paths_to_dockerfile.sh | jq .)"
#echo "::set-output name=matrix::{\"dockerfiles\":[\"./aiidalab/Dockerfile\"]}"
export PATHS_TO_DOCKERFILE=`find -name Dockerfile | jq -R -s 'split("\n")[:-1]'`
echo "::set-output name=matrix::{\"dockerfiles\": $PATHS_TO_DOCKERFILE}"
check-matrix:
runs-on: ubuntu-latest
needs: matrix
# Only run of there are Dockerfiles present
#if: "join(fromJSON(needs.matrix.outputs.matrix), '') != ''"
steps:
- name: Install json2yaml
run: |
sudo npm install -g json2yaml

- name: Check matrix definition
run: |
matrix='${{ needs.matrix.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
echo $matrix | json2yaml
linter:
runs-on: ubuntu-latest
# Run linter on all located Dockerfiles
needs: matrix
# Only run of there are Dockerfiles present
#if: "join(fromJSON(needs.matrix.outputs.matrix), '') != ''"
strategy:
matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: check directory content
run: ls
- uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
dockerfile: ${{ matrix.dockerfiles }}
build:
needs: [linter]
needs: linter
# Should consider to use https://github.com/marketplace/actions/build-and-push-docker-images instead, but requires rewrite
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub Registry
run: echo ${{ secrets.QUAY_PASSWORD }} | docker login -u ${{ secrets.QUAY_USERNAME }} --password-stdin quay.io
- name: Run build script
run: ./build.sh
# - name: Run build script
# run: ./build.sh
14 changes: 14 additions & 0 deletions paths_to_dockerfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
STRING=`find -name Dockerfile`
PATHS_TO_DOCKERFILE=($STRING)
echo '{ "dockerfiles" : ['
for path in ${PATHS_TO_DOCKERFILE[@]};
do
if [[ $path == ${PATHS_TO_DOCKERFILE[-1]} ]];
then
echo "\"$path\""
else
echo "\"$path\","
fi
done
echo "]}"