forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (158 loc) · 6.73 KB
/
Copy pathdeploy.yml
File metadata and controls
184 lines (158 loc) · 6.73 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: 📰 Deploy VitePress site to GitHub Pages
on:
workflow_dispatch:
inputs:
repository_branches:
description: 'YAML-MAP or JSON with repository branches: {"btp-manager": "main", "istio": "release-1.20"} or [{"repository": "btp-manager", "branch": "main"}]'
required: false
default: '{}'
schedule:
- cron: '0 0,12,16 * * *' # Runs at 00:00, 12:00, and 16:00 UTC every day
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
copy-docs:
name: 📋 Copy doc files from external repositories
strategy:
fail-fast: false
matrix:
repository:
- btp-manager
- istio
- serverless
- telemetry-manager
- eventing-manager
- api-gateway
- nats-manager
- application-connector-manager
- keda-manager
- cloud-manager
- docker-registry
- busola
- cli
- registry-proxy
- community-modules
runs-on: ubuntu-latest
steps:
- name: 🔧 Determine branch for ${{matrix.repository}}
id: get-branch
run: |
set -euo pipefail
REPO="${{ matrix.repository }}"
INPUT_RAW="${{ inputs.repository_branches }}"
DEFAULT_BRANCH="main"
BRANCH="$DEFAULT_BRANCH"
echo "📄 Raw input: $INPUT_RAW"
echo "🔍 Repository: $REPO"
echo "🔍 Default branch: $DEFAULT_BRANCH"
# 1. Search in the env variables: build the variable name as repo name --> to capital --> replace " " and "-" with "_" --> append "_BRANCH"
REPO_VAR=$(echo "$REPO" | tr '[:lower:]' '[:upper:]' | tr ' -' '_')_BRANCH
echo "🔍 Computed env variable name: $REPO_VAR"
# Variable expansion using ! is not working for env if VARIABLE is dynamic. Combine jq and toJson to get the env variable value
VAR_BRANCH=$(jq -r --arg key "$REPO_VAR" '.[$key]' <<< '${{ toJson(vars) }}')
echo "🔍 Value from env ($REPO_VAR): ${VAR_BRANCH:-<not set>}"
if [ "$VAR_BRANCH" != "null" ]; then
BRANCH="$VAR_BRANCH"
echo "✅ Using branch '$BRANCH' from GitHub variable ($REPO_VAR) for $REPO"
else
echo "ℹ️ No GitHub variable found for $REPO, checking input YAML/JSON..."
# 2. No GitHub variable, read from input string
if [ -n "$INPUT_RAW" ] && [ "$INPUT_RAW" != "{}" ]; then
echo "🔍 Parsing input..."
if echo "$INPUT_RAW" | yq -o=json '.' >/dev/null 2>&1; then
PARSED=$(echo "$INPUT_RAW" | yq -o=json '.')
echo "✅ Input read as YAML converted to JSON"
elif echo "$INPUT_RAW" | jq empty >/dev/null 2>&1; then
PARSED="$INPUT_RAW"
echo "✅ Valid JSON conversion"
else
echo "⚠️ Not a valid YAML nor JSON"
PARSED="{}"
fi
echo "🔍 Parsed content: $PARSED"
# 3. Search in the map {repo: branch}
if echo "$PARSED" | jq -e "has(\"$REPO\")" >/dev/null 2>&1; then
BRANCH=$(echo "$PARSED" | jq -r ".[\"$REPO\"]")
echo "✅ Found branch '$BRANCH' for $REPO (map format)"
else
# 4. Search as array [{repository: repo, branch: branch}]
BRANCH_FROM_ARRAY=$(echo "$PARSED" | jq -r ".[] | select(.repository == \"$REPO\") | .branch" 2>/dev/null || echo "")
echo "🔍 Branch from array: ${BRANCH_FROM_ARRAY:-<none>}"
if [ -n "$BRANCH_FROM_ARRAY" ] && [ "$BRANCH_FROM_ARRAY" != "null" ]; then
BRANCH="$BRANCH_FROM_ARRAY"
echo "✅ Found branch '$BRANCH' for $REPO (array format)"
else
echo "ℹ️ Repository $REPO not found in input, using default branch '$DEFAULT_BRANCH'"
fi
fi
else
echo "ℹ️ No input provided, using default branch '$DEFAULT_BRANCH'"
fi
fi
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "🎯 Final decision: Using branch '$BRANCH' for repository '$REPO'"
- name: '🗂️ Checkout ${{matrix.repository}} (branch: ${{steps.get-branch.outputs.branch}})'
uses: actions/checkout@v4
with:
repository: kyma-project/${{matrix.repository}}
ref: ${{steps.get-branch.outputs.branch}}
path: ${{matrix.repository}}
- name: 🚢 Copy for main repo
run: |
SOURCE_PATH="${{matrix.repository}}/docs/user/"
TARGET_PATH="./docs/external-content/${{matrix.repository}}/docs/"
SOURCE_PATH_ASSETS="${{matrix.repository}}/docs/assets/"
TARGET_PATH_ASSETS="./docs/external-content/${{matrix.repository}}/docs/"
if [ -d "$SOURCE_PATH" ]; then
echo "📁 found in ${{matrix.repository}}, copy to $TARGET_PATH"
mkdir -p "$TARGET_PATH"
cp -rf "$SOURCE_PATH/" "$TARGET_PATH/"
if [ -d "$SOURCE_PATH_ASSETS" ]; then
echo "↳📁 found in ${{matrix.repository}}, copy to $TARGET_PATH_ASSETS"
mkdir -p "$TARGET_PATH_ASSETS"
cp -rf "$SOURCE_PATH_ASSETS/" "$TARGET_PATH_ASSETS/"
else
echo "↳🚫 no folder docs/assets in ${{matrix.repository}}"
fi
else
echo "🚫 No folder docs/users in ${{matrix.repository}}"
fi
- name: 📦 Upload copied docs
uses: actions/upload-artifact@v5
with:
name: ${{matrix.repository}}
path: ./docs/external-content/${{matrix.repository}}
build-and-deploy:
name: 🛠️ Build and Deploy VitePress
runs-on: ubuntu-latest
needs: copy-docs
steps:
- name: 🗂️ Checkout repository
uses: actions/checkout@v4
- name: 📥 Download copied docs
uses: actions/download-artifact@v5
with:
path: docs/external-content
- name: 🪢 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: 💾 Install dependencies
run: npm install
- name: 🛠️ Build VitePress site
run: npm run docs:build
- name: ⚙️ Configure GitHub Pages
uses: actions/configure-pages@v5
- name: 🚀 Upload build artifact
uses: actions/upload-pages-artifact@v3
with:
path: .vitepress/dist
- name: 🔝 Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4