Base builds off changed directory structure of repo (#5) #10
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-push | |
on: | |
push: | |
jobs: | |
find-jobs: | |
name: Find changed directories | |
runs-on: ubuntu-latest | |
outputs: | |
folders: ${{ steps.jobs.outputs.folders }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- id: jobs | |
run: | | |
folders=$(git diff --diff-filter="ACMR" --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs dirname | awk -F '/' '{print $1}' | sort | uniq | grep -Ev "^\." | awk NF | jq -c --raw-input --slurp 'split("\n") | .[0:-1]') | |
echo $folders | jq . | |
echo "folders=$folders" >> $GITHUB_OUTPUT | |
get-tags: | |
needs: [find-jobs] | |
runs-on: ubuntu-latest | |
outputs: | |
tags: ${{ steps.tags.outputs.tags }} | |
steps: | |
- uses: actions/checkout@v4 | |
- id: tags | |
run: | | |
json_array=$(echo '${{ needs.find-jobs.outputs.folders }}' | jq -rc '.[]') | |
TAGS=$(while read -r REPO; do | |
if [ ! -d $REPO/.build-args ]; then | |
continue; | |
fi | |
for TAG in $(ls $REPO/.build-args); do | |
echo '{"context":"'${REPO}'", "image":"'${REPO}'-'${TAG}'", "args":"'$(cat ${REPO}/.build-args/${TAG})'"},' | |
done | |
done <<< "$json_array") | |
TAGS=$(echo "[${TAGS%,}]" | tr -d '\n') | |
echo $TAGS | jq . | |
echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
build-push-ar: | |
name: "Build and push ${{ matrix.tags.image }} to Google Artifact Registry" | |
needs: [get-tags] | |
strategy: | |
matrix: | |
tags: ${{ fromJson(needs.get-tags.outputs.tags) }} | |
uses: ./.github/workflows/build-push-ar.yml | |
with: | |
image: "internal/${{ matrix.tags.image }}" | |
context: ${{ matrix.tags.context }} | |
build-args: ${{ matrix.tags.args }} | |
permissions: | |
contents: read | |
id-token: write | |
secrets: inherit |