build-images #354
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-images | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: "0 0 * * *" | |
env: | |
REGISTRY: ghcr.io | |
jobs: | |
list: | |
runs-on: ubuntu-latest | |
outputs: | |
images: ${{ steps.output-images.outputs.images }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: list images | |
id: output-images | |
run: | | |
echo "images=$(ls images | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: list | |
strategy: | |
matrix: | |
image: ${{fromJSON(needs.list.outputs.images)}} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/changed-files@v39 | |
with: | |
files: | | |
images/${{ matrix.image }}/** | |
- name: changed files | |
if: steps.changed-files.outputs.any_changed == 'true' | |
run: | | |
echo ${{ steps.changed-files.outputs.any_changed }} | |
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}" | |
- name: Log in to the Container registry | |
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request' | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request' | |
id: meta | |
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 | |
with: | |
images: ${{ env.REGISTRY }}/${{ github.repository }}/${{ matrix.image }} | |
- name: Build and push Docker image | |
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request' | |
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 | |
with: | |
context: images/${{ matrix.image }} | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |