From 54a61ee2f3596e3727440f3b033076433059f242 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 29 May 2024 15:43:48 -0600 Subject: [PATCH 1/5] feat: embed path filtering --- .github/workflows/argus-docker-build.yaml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/argus-docker-build.yaml b/.github/workflows/argus-docker-build.yaml index 210fa59a..81a29d94 100644 --- a/.github/workflows/argus-docker-build.yaml +++ b/.github/workflows/argus-docker-build.yaml @@ -11,6 +11,17 @@ on: description: 'JSON array of images to build (required keys: dockerfile, context, name, platform)' required: true type: string + path_filters: + description: 'Path to the configuration file or YAML string with filters definition' + required: true + type: string + path_filters_base: + description: | + Git reference (e.g. branch name) against which the changes will be detected. Defaults to repository default branch (e.g. master). + If it references same branch it was pushed to, changes are detected against the most recent commit before the push. + This option is ignored if action is triggered by pull_request event. + required: false + type: string jobs: prep: @@ -21,6 +32,7 @@ jobs: image-tag: ${{ steps.build-tags.outputs.IMAGE_TAG }} images: ${{ steps.parse-images.outputs.images }} envs: ${{ steps.parse-envs.outputs.envs }} + run_build: ${{ steps.filter.outputs.run_on }} permissions: id-token: write contents: read @@ -28,6 +40,14 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + - uses: dorny/paths-filter@v3 + id: filter + with: + filters: | + run_on: + ${{ inputs.path_filters }} + base: ${{ inputs.path_filters_base }} + list-files: json - name: Get build tag id: build-tags run: | @@ -55,7 +75,7 @@ jobs: - ${{ matrix.image.platform == 'linux/amd64' && 'X64' || 'ARM64' }} env: IMAGE_TAG: ${{ needs.prep.outputs.image-tag }} - if: needs.prep.outputs.image-tag != '' && needs.prep.outputs.image-tag != 'sha-' && needs.prep.outputs.images != '[]' + if: needs.prep.outputs.run_build == 'true' && needs.prep.outputs.image-tag != '' && needs.prep.outputs.image-tag != 'sha-' && needs.prep.outputs.images != '[]' permissions: id-token: write contents: read From c9e87a0a65a03a2390b1184f130065f45f6dc206 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Wed, 29 May 2024 15:56:44 -0600 Subject: [PATCH 2/5] gh actions need array support but maybe this will do for now --- .github/workflows/argus-docker-build.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/argus-docker-build.yaml b/.github/workflows/argus-docker-build.yaml index 81a29d94..c38c9dab 100644 --- a/.github/workflows/argus-docker-build.yaml +++ b/.github/workflows/argus-docker-build.yaml @@ -13,8 +13,9 @@ on: type: string path_filters: description: 'Path to the configuration file or YAML string with filters definition' - required: true + required: false type: string + default: '**/*' path_filters_base: description: | Git reference (e.g. branch name) against which the changes will be detected. Defaults to repository default branch (e.g. master). @@ -40,12 +41,19 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Parse filters + id: parse_filters + uses: actions/github-script@v7 + with: + script: | + const filters = `${{ inputs.path_filters }}`.split(',').map(f => f.trim()); + const filtersStr = "run_on:\n" + filters.map(f => ` - ${f}`).join('\n'); + core.setOutput('filters', filtersStr); - uses: dorny/paths-filter@v3 id: filter with: filters: | - run_on: - ${{ inputs.path_filters }} + ${{ steps.parse_filters.outputs.filters }} base: ${{ inputs.path_filters_base }} list-files: json - name: Get build tag From 5dbbe5fb5d4f9608951254047e2858631733b9a9 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Thu, 30 May 2024 08:49:58 -0600 Subject: [PATCH 3/5] wrap in quotes --- .github/workflows/argus-docker-build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/argus-docker-build.yaml b/.github/workflows/argus-docker-build.yaml index c38c9dab..b8325d33 100644 --- a/.github/workflows/argus-docker-build.yaml +++ b/.github/workflows/argus-docker-build.yaml @@ -47,7 +47,7 @@ jobs: with: script: | const filters = `${{ inputs.path_filters }}`.split(',').map(f => f.trim()); - const filtersStr = "run_on:\n" + filters.map(f => ` - ${f}`).join('\n'); + const filtersStr = "run_on:\n" + filters.map(f => ` - '${f}'`).join('\n'); core.setOutput('filters', filtersStr); - uses: dorny/paths-filter@v3 id: filter From 142c60e0f5d42501eced28017b7fa20078d78a40 Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Thu, 30 May 2024 08:53:16 -0600 Subject: [PATCH 4/5] default base --- .github/workflows/argus-docker-build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/argus-docker-build.yaml b/.github/workflows/argus-docker-build.yaml index b8325d33..a77e0ffa 100644 --- a/.github/workflows/argus-docker-build.yaml +++ b/.github/workflows/argus-docker-build.yaml @@ -23,6 +23,7 @@ on: This option is ignored if action is triggered by pull_request event. required: false type: string + default: ${{ github.ref }} jobs: prep: From 34fd7b7c8f73dad249a77d47211237f71d387aea Mon Sep 17 00:00:00 2001 From: Hayden Spitzley Date: Thu, 30 May 2024 09:28:07 -0600 Subject: [PATCH 5/5] update description --- .github/workflows/argus-docker-build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/argus-docker-build.yaml b/.github/workflows/argus-docker-build.yaml index 5a66f43b..2e73266d 100644 --- a/.github/workflows/argus-docker-build.yaml +++ b/.github/workflows/argus-docker-build.yaml @@ -18,7 +18,7 @@ on: default: '**/*' path_filters_base: description: | - Git reference (e.g. branch name) against which the changes will be detected. Defaults to repository default branch (e.g. master). + Git reference (e.g. branch name) against which the changes will be detected. Defaults to the current branch. If it references same branch it was pushed to, changes are detected against the most recent commit before the push. This option is ignored if action is triggered by pull_request event. required: false