Build #382
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 | |
on: | |
#push: | |
# branches: | |
# - main | |
# - develop | |
#schedule: | |
# - cron: '55 22 * * 0' | |
workflow_dispatch: | |
jobs: | |
list-images: | |
runs-on: ubuntu-latest | |
outputs: | |
build: ${{ steps.list.outputs.build }} | |
matrix: ${{ steps.list.outputs.matrix }} | |
steps: | |
- name: Deep checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: List images | |
id: list | |
run: | | |
sha_prev=$(git rev-parse HEAD~1) | |
if [ "${{ github.event_name }}" == "push" ]; then | |
matrix=$(git diff --name-only --diff-filter=d $sha_prev ${{ github.sha }} | grep -Eo '^images(/[^/]+){3}' | xargs -r -n1 -d'\n' dirname | sort -u | jq -R -s -c 'split("\n")|map(select(.|length>0))|{"include":map({"path":.})}') | |
else | |
matrix=$(find images -type d -mindepth 2 -maxdepth 2 | jq -R -s -c 'split("\n")|map(select(.|length>0))|{"include":map({"path":.})}') | |
fi | |
echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
echo "build=$(jq '.include|length>0' <<<$matrix)" >> $GITHUB_OUTPUT | |
build: | |
if: ${{ needs.list-images.outputs.build == 'true' }} | |
runs-on: ubuntu-latest | |
needs: [ list-images ] | |
strategy: | |
matrix: ${{ fromJSON(needs.list-images.outputs.matrix) }} | |
steps: | |
- name: Get image name and tag | |
id: image | |
run: | | |
ref=${{ github.ref }} | |
ref=${ref#refs/heads/} | |
echo "IMAGE=$(basename $(dirname ${{ matrix.path }}))" >> $GITHUB_OUTPUT | |
echo "TAG=$(basename ${{ matrix.path }})" >> $GITHUB_OUTPUT | |
echo "PATH=${{ matrix.path }}" >> $GITHUB_OUTPUT | |
echo "TAG_SUFFIX=$( [[ $ref =~ ^(refs/heads/)?main$ ]] || echo .${ref//\//-})" >> $GITHUB_OUTPUT | |
- name: Shallow checkout | |
uses: actions/checkout@v2 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
id: docker_build | |
uses: docker/build-push-action@v4 | |
with: | |
context: ${{ steps.image.outputs.PATH }} | |
file: ${{ steps.image.outputs.PATH }}/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.image.outputs.IMAGE }}:${{ steps.image.outputs.TAG }}${{ steps.image.outputs.TAG_SUFFIX }} |