Skip to content

PR Diff that adds tests #31

PR Diff that adds tests

PR Diff that adds tests #31

name: Update Docker Image Reference on PR
on:
pull_request:
paths:
- 'templated_tests/**'
push:
branches:
- main
paths:
- 'templated_tests/**'
jobs:
changed-files:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed-files.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
matrix: true
dir_names: true
files: |
templated_tests/**
files_ignore: |
templated_tests/README.md
build-and-push-image:
needs: changed-files
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
files: ${{fromJson(needs.changed-files.outputs.matrix)}}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get Docker image name
id: image_name
run: |
image_name=$(echo ${{ matrix.files }} | sed 's/templated_tests\///')
echo "::set-output name=image_name::${{ secrets.DOCKERHUB_USERNAME }}/$image_name"
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image_name.outputs.image_name }}
tags: |
type=raw,value={{sha}},event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image to DockerHub
uses: docker/build-push-action@v6
with:
context: ${{ matrix.files }}
push: true
tags: ${{ steps.meta.outputs.tags }}