Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 2

Performing an action only on files that have changed

Hey all!

 

We have a repository that contains all of our Dockerfiles. Each Dockerfile is stored in a subdirectory like `postgres/`. We'd like to build images on push for the Dockerfiles that have changed and put them in the GitHub Package Registry.

 

Is this possible?

1 Reply
Highlighted
GitHub Partner
Message 2 of 2

Re: Performing an action only on files that have changed

Hi @anthonator ,

 

This should be possible, firstly you need to find out the directory where dockerfile has been changed, and then use a loop to docker build&push to Github Package Registry for each directory.

Here is an example about how to list the changed files, hope it helps!

name: publishmultipledockerimage
on: 
  push:
    paths: 
      - '**/Dockerfile'
  
jobs:
  job1:
    runs-on: [ubuntu-latest]
    steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: get changed files
        id: getfile
        run: |
          echo "::set-output name=files::$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }}| xargs)"

      - name: echo the changed files
        run: |
          for i in ${{ steps.getfile.outputs.files }}
          do
              echo $i
          done

changedfileslist.png