Skip to content

Commit a567dac

Browse files
fix: update build-docker examples from Dockers2
see CCBR/Dockers2#389 resolves #151
1 parent 7cd1df9 commit a567dac

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed

examples/build-docker-auto.yml

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
name: build-docker-auto
2121

22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
2226
on:
2327
push:
2428
branches:
@@ -32,12 +36,17 @@ on:
3236
- dev
3337
paths:
3438
- "**/Dockerfile.*" # Only trigger if a Dockerfile.* is modified in any directory
39+
types:
40+
- opened
41+
- reopened
42+
- synchronize
43+
- ready_for_review # Ensures the workflow triggers only when a draft is marked "Ready for Review"
3544

3645
env:
37-
suffix: ${{ github.base_ref == 'main' && github.event_name == 'pull_request' && 'main' || github.base_ref == 'dev' && github.event_name == 'pull_request' && 'dev' || 'feat' }}
38-
39-
permissions:
40-
contents: read
46+
suffix:
47+
${{ github.base_ref == 'main' && github.event_name == 'pull_request' &&
48+
'main' || github.base_ref == 'dev' && github.event_name == 'pull_request' &&
49+
'dev' || 'feat' }}
4150

4251
jobs:
4352
get-files:
@@ -48,22 +57,35 @@ jobs:
4857
- name: Checkout repository
4958
id: checkout
5059
uses: actions/checkout@v6
60+
with:
61+
fetch-depth: 2 # Need parent commit to diff against for HEAD~1..HEAD
62+
ref: ${{ github.head_ref || github.ref_name }}
5163

5264
- id: changed-files
5365
name: Check changed files
54-
uses: knu/changed-files@v1
55-
with:
56-
paths: |
57-
**/Dockerfile.*
66+
# Compare only the latest commit (HEAD~1..HEAD) so that subsequent pushes
67+
# to a PR do not re-trigger builds for Dockerfiles touched in earlier commits.
68+
run: |
69+
files=$(git diff --name-only HEAD~1 HEAD | grep -E '(^|/)Dockerfile\.' || true)
70+
echo "matched_files<<EOF" >> "$GITHUB_OUTPUT"
71+
echo "$files" >> "$GITHUB_OUTPUT"
72+
echo "EOF" >> "$GITHUB_OUTPUT"
73+
if [ -z "$files" ]; then
74+
echo 'matched_files_json=[]' >> "$GITHUB_OUTPUT"
75+
else
76+
json=$(echo "$files" | jq -R -s 'split("\n") | map(select(length > 0))')
77+
echo "matched_files_json=$json" >> "$GITHUB_OUTPUT"
78+
fi
5879
5980
- name: Show changed files
6081
id: matrix
6182
run: |
6283
echo "matched files:"
63-
echo "${{ steps.changed-files.outputs.matched_files }}" | sed 's|^| |'
84+
echo "${{ steps.changed-files.outputs.matched_files }}" | sed 's/^/ /'
6485
6586
build-docker:
6687
needs: [get-files]
88+
if: needs.get-files.outputs.json != '[]' # Skip if no Dockerfiles changed in the latest commit
6789
strategy:
6890
matrix:
6991
file: "${{ fromJson(needs.get-files.outputs.json) }}"
@@ -76,18 +98,10 @@ jobs:
7698
pull-requests: write
7799
steps:
78100
- uses: actions/checkout@v6
79-
name: "checkout PR ${{ github.head_ref }}"
80-
if: github.event_name == 'pull_request'
81-
with:
82-
fetch-depth: 0
83-
ref: ${{ github.head_ref }} # branch name of PR
84-
85-
- uses: actions/checkout@v6
86-
name: "checkout push ${{ github.ref_name }}"
87-
if: github.event_name == 'push'
101+
name: Checkout repository
88102
with:
89103
fetch-depth: 0
90-
ref: ${{ github.ref_name }} # branch name of push
104+
ref: ${{ github.head_ref || github.ref_name }}
91105

92106
- uses: CCBR/actions/build-docker@latest
93107
with:
@@ -97,6 +111,4 @@ jobs:
97111
dockerhub-token: ${{ secrets.DOCKERHUBRW_TOKEN_VK }}
98112
suffix: ${{ env.suffix }}
99113
push: true
100-
ccbr-actions-version: v0.3
101114
github-token: ${{ github.token }}
102-
config-file: "scripts/tool_version_commands.txt"

examples/build-docker-manual.yml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@
2020
name: build-docker-manual
2121
run-name: build-docker ${{ inputs.dockerfile }}-${{ inputs.suffix }}
2222

23+
permissions:
24+
contents: write
25+
pull-requests: write
26+
2327
on:
2428
workflow_dispatch:
2529
inputs:
2630
dockerfile:
2731
type: string
28-
description: path to the Dockerfile in the repo (e.g. common/ccbr_bwa/Dockerfile)
32+
description: path to the Dockerfile in the repo (e.g.
33+
base_images/ccbr_ubuntu_22.04/Dockerfile.v4)
2934
required: true
3035
dockerhub-namespace:
3136
type: string
@@ -34,32 +39,34 @@ on:
3439
default: nciccbr
3540
suffix:
3641
type: string
37-
description: Suffix to add to image tag eg. "dev" to add "-dev"
42+
description: Suffix to add to image tag (e.g. "dev" to add "-dev")
3843
required: true
3944
default: feat
4045
push:
4146
type: boolean
42-
description: Push to DockerHub (leave unchecked to just build the container without pushing)
47+
description:
48+
Push to DockerHub (leave unchecked to just build the container
49+
without pushing)
4350
required: true
4451
default: false
4552
ccbr-actions-version:
46-
description: "The version of ccbr_actions to use"
53+
description: "The version or branch of ccbr_actions to use (see
54+
https://github.com/ccbr/actions)"
4755
required: true
48-
default: "v0.3"
49-
50-
permissions:
51-
contents: read
56+
default: "latest"
5257

5358
jobs:
5459
build-docker:
5560
runs-on: ubuntu-latest
5661
permissions:
57-
contents: write
62+
contents: "write"
5863
pull-requests: write
5964
steps:
6065
- name: Checkout repository
6166
id: checkout
6267
uses: actions/checkout@v6
68+
with:
69+
ref: ${{ github.head_ref || github.ref_name }}
6370

6471
- uses: CCBR/actions/build-docker@latest
6572
with:
@@ -71,4 +78,4 @@ jobs:
7178
push: ${{ github.event.inputs.push }}
7279
ccbr-actions-version: ${{ github.event.inputs.ccbr-actions-version }}
7380
github-token: ${{ github.token }}
74-
config-file: "scripts/tool_version_commands.txt"
81+
github-actor: ${{ github.actor }}

0 commit comments

Comments
 (0)