-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-docker-auto.yml
99 lines (89 loc) · 3.19 KB
/
build-docker-auto.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# This GitHub Actions workflow is designed to trigger a manual Docker build for each modified Dockerfile.
#
# Workflow Name: build-docker-auto
# Short Description: Trigger Build Docker Manual for Each modified Dockerfile
#
# Triggers:
# - On push events to any branch except 'main' and 'dev', if any Dockerfile.* is modified.
# - On pull request events to 'main' and 'dev' branches, if any Dockerfile.* is modified.
#
# Jobs:
# - Runs on the latest Ubuntu environment.
# - Steps:
# 1. Check out the repository using actions/checkout@v4.
# 2. Identify modified Dockerfiles using git diff and store them in the environment variable 'dockerfiles'.
# 3. For each modified Dockerfile, trigger the 'build-docker-manual' workflow with the Dockerfile path and additional parameters.
#
# Environment Variables:
# - GITHUB_TOKEN: Used for authentication to trigger the 'build-docker-manual' workflow.
name: build-docker-auto
on:
push:
branches:
- "**autobuild**" # Only trigger if the branch name contains "autobuild"
paths:
- "**/Dockerfile.*" # Only trigger if a Dockerfile.* is modified in any directory
pull_request:
branches:
- main
- dev
paths:
- "**/Dockerfile.*" # Only trigger if a Dockerfile.* is modified in any directory
env:
suffix: ${{ github.base_ref == 'main' && github.event_name == 'pull_request' && 'main' || github.base_ref == 'dev' && github.event_name == 'pull_request' && 'dev' || 'feat' }}
jobs:
get-files:
runs-on: ubuntu-latest
outputs:
json: ${{ steps.changed-files.outputs.matched_files_json }}
steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4
- id: changed-files
name: Check changed files
uses: knu/changed-files@v1
with:
paths: |
**/Dockerfile.*
- name: Show changed files
id: matrix
run: |
echo "matched files:"
echo "${{ steps.changed-files.outputs.matched_files }}" | sed 's/^/ /'
build-docker:
needs: [get-files]
strategy:
matrix:
file: "${{ fromJson(needs.get-files.outputs.json) }}"
max-parallel: 1
fail-fast: false
continue-on-error: true
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: "checkout PR ${{ github.head_ref }}"
if: github.event_name == 'pull_request'
with:
fetch-depth: 0
ref: ${{ github.head_ref }} # branch name of PR
- uses: actions/checkout@v4
name: "checkout push ${{ github.ref_name }}"
if: github.event_name == 'push'
with:
fetch-depth: 0
ref: ${{ github.ref_name }} # branch name of push
- uses: CCBR/actions/[email protected]
with:
dockerfile: ${{ matrix.file }}
dockerhub-namespace: nciccbr
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME_VK }}
dockerhub-token: ${{ secrets.DOCKERHUBRW_TOKEN_VK }}
suffix: ${{ env.suffix }}
push: true
ccbr-actions-version: v0.2
github-token: ${{ github.token }}
json-file: "scripts/tool_version_commands.json"