-
Notifications
You must be signed in to change notification settings - Fork 36
55 lines (50 loc) · 1.72 KB
/
publish_docker_matrix.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
name: Docker Image Publish Matrix (All)
on:
workflow_dispatch:
repository_dispatch:
types: [trigger-workflow]
push:
branches:
- master
- develop
tags:
- tc_nightly*
- tc_v*.*.*
pull_request:
branches: [ "master", "develop" ]
jobs:
discover-and-trigger:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Discover Workflows
id: discover_workflows
run: |
# Find all YAML files in the .github/workflows directory that start with "publish_docker_matrix_"
workflows=$(find .github/workflows -name 'publish_docker_matrix_*.yml' -exec basename {} \;)
echo "Found workflows: $workflows"
# Convert to JSON array
matrix_json=$(echo "$workflows" | tr ' ' '\n' | sed 's/^/"/;s/$/"/' | paste -sd, - | sed 's/^/[ /;s/$/ ]/')
echo "matrix_json=$matrix_json" >> $GITHUB_ENV
- name: Trigger Workflows
uses: actions/github-script@v6
env:
MATRIX_JSON: ${{ env.matrix_json }}
with:
script: |
const matrix = JSON.parse(process.env.MATRIX_JSON);
console.log("Triggering workflows: ", matrix);
for (const workflow of matrix) {
const owner = context.repo.owner;
const repo = context.repo.repo;
const event_type = 'trigger-workflow'; // Matches the repository_dispatch trigger
const client_payload = { "branch": process.env.GITHUB_REF_NAME };
await github.repos.createDispatchEvent({
owner,
repo,
event_type,
client_payload,
workflow
});
};