-
Notifications
You must be signed in to change notification settings - Fork 1
168 lines (140 loc) · 6.05 KB
/
publish-pipelines.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Publish Pipelines generated when project is tagged
name: Publish Pipelines generated
on:
workflow_dispatch:
push:
branches:
- main
jobs:
generate:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: maven
- name: Build with Maven
run: mvn -B clean package
- name: Run the builder application over the existing configurations
run: |
# Cleanup the generated folder
rm -rf generated/**/*
cfg_files=(configurations/**/*.yaml)
for f in "${cfg_files[@]}"
do
java -jar target/quarkus-app/quarkus-run.jar builder -o generated -c $f
done
# NOT USED ANYMORE
# Sometimes the python script happens ``` end of the last YAML line and remove the next README CR
#
#- name: Markdown Code Embed
# continue-on-error: true
# #if: steps.changed-files-yaml.outputs.doc_any_changed == 'true'
# run: |
# #!/usr/bin/env bash
# set -e
#
# git clone https://github.com/ippie52/markdown_code_embed.git
#
# python markdown_code_embed/mdce.py -f README.md
# NOT USED
#- name: Get doc files that have changed
# id: changed-files-yaml
# uses: tj-actions/changed-files@v44
# with:
# files_yaml: |
# doc:
# - '**.md'
- name: Generate the content of the SCENARIO.md file
run: |
CMD="java -jar target/quarkus-app/quarkus-run.jar builder"
cfg_files=$(find configurations -type f -name "*.yaml" -o -name "*.yml")
providers=()
domains=()
values=()
# Loop through the found files and extract the 'provider' and 'domain' fields
for file in $cfg_files; do
provider=$(yq eval '.provider' "$file" 2>/dev/null || echo "tekton")
domain=$(yq eval '.domain' "$file" 2>/dev/null || echo "demo")
# If either field is missing, set default values
provider=${provider:-"unknown_provider"}
domain=${domain:-"unknown_domain"}
# Create the key as type:domain
key="$provider:$domain"
# Check if the key already exists in the arrays
found=0
for i in "${!providers[@]}"; do
if [[ "${providers[$i]}" == "$provider" && "${domains[$i]}" == "$domain" ]]; then
# Append the file to the corresponding value
values[$i]="${values[$i]} $file"
found=1
break
fi
done
# If the key was not found, add a new entry
if [[ $found -eq 0 ]]; then
providers+=("$provider")
domains+=("$domain")
values+=("$file")
fi
done
# Print the markdown headers and grouped files, grouping by type
last_provider=""
printf '%s\n\n' "# Scenario" > SCENARIO.md
printf '%s\n' "This document is generated by the job \'.github/workflows/publish-pipelines.yml\' using the [configurations](configurations/) files !" >> SCENARIO.md
for i in "${!providers[@]}"; do
provider="${providers[$i]}"
domain="${domains[$i]}"
# Print the type header only if it's different from the last printed type
if [[ "$provider" != "$last_type" ]]; then
printf '%s\n\n' "## $provider" >> SCENARIO.md
last_provider="$provider"
fi
# Print the domain as a subheader
printf '%s\n\n' "### ${domain^}" >> SCENARIO.md
# Print the files under this type and domain
for f in ${values[$i]}; do
title=$(cat "$f" | yq -r ".job.description")
fileName=$(cat "$f" | yq -r ".job.name")
resourceProvider=$(cat "$f" | yq -r ".resourceType" || echo "PipelineRun")
printf '%s\n\n' "#### ${title^}" >> SCENARIO.md
printf '%s\n' "Command to be executed: " >> SCENARIO.md
printf '%s\n' "\`\`\`bash" >> SCENARIO.md
printf '%s\n' "$CMD -o out/flows -c $f" >> SCENARIO.md
printf '%s\n' "\`\`\`" >> SCENARIO.md
printf '%s\n' "using as configuration: " >> SCENARIO.md
printf '%s\n' "\`\`\`yaml" >> SCENARIO.md
printf '%s\n' "# $f" >> SCENARIO.md
printf '%s\n' "\`\`\`" >> SCENARIO.md
printf '%s\n' "Generated file: " >> SCENARIO.md
printf '%s\n' "\`\`\`yaml" >> SCENARIO.md
generate_path="generated/$provider/$domain/$(echo $resourceProvider | awk '{print tolower($0)}')-$fileName.yaml"
printf '%s\n' "# $generate_path" >> SCENARIO.md
printf '%s\n' "\`\`\`" >> SCENARIO.md
done
done
- name: Embed snippet code within the SCENARIO.md file
run: |
npx embedme SCENARIO.md
- name: Get current date
id: date
#if: steps.changed-files-yaml.outputs.doc_any_changed == 'true'
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Create pull request for the updated SCENARIO.md file
#if: steps.changed-files-yaml.outputs.doc_any_changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: new-generated-pipelines-${{ env.CURRENT_DATE }}
title: "New resources generated and SCENARIO.md file updated - ${{ env.CURRENT_DATE }}"
labels: |
documentation
body: |
Pull request for New resources generated and SCENARIO.md changed.