-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (147 loc) · 6.1 KB
/
Copy pathbuild-webcomponents.yml
File metadata and controls
176 lines (147 loc) · 6.1 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
name: Build WebComponents Bundle
on:
push:
branches:
- main
# Add more branches below to automatically trigger builds when pushing to them:
- feat-dock
workflow_dispatch:
inputs:
branch:
description: 'Branch to build from'
required: false
default: 'main'
type: string
permissions:
contents: write
jobs:
build-webcomponents:
runs-on: ubuntu-latest
steps:
- name: Get branch name
id: branch
run: |
BRANCH_NAME="${{ inputs.branch || github.ref_name }}"
# Sanitize branch name: keep only alphanumeric and hyphens
SAFE_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g')
echo "name=$BRANCH_NAME" >> $GITHUB_OUTPUT
echo "safe_name=$SAFE_BRANCH" >> $GITHUB_OUTPUT
echo "Building branch: $BRANCH_NAME (safe filename: $SAFE_BRANCH)"
- name: Checkout source branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch || github.ref_name }}
path: source
- name: Checkout main for docs update
uses: actions/checkout@v4
with:
ref: main
path: docs-repo
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
working-directory: source
run: yarn install
- name: Debug - Check Angular CLI and project structure
working-directory: source
run: |
echo "Angular CLI version:"
npx ng version
echo "Project structure:"
ls -la projects/
echo "khiops-webcomponent project:"
ls -la projects/khiops-webcomponent/
- name: Build Angular webcomponent
working-directory: source
run: |
echo "Building Angular webcomponent..."
npx ng build khiops-webcomponent --single-bundle
echo "Build completed, checking results..."
ls -la dist/ || echo "No dist directory"
ls -la dist/khiops-webcomponent/ || echo "No khiops-webcomponent directory"
- name: Process CSS and create bundle
working-directory: source
run: |
if [ -f "dist/khiops-webcomponent/styles.css" ]; then
echo "Processing CSS file..."
node ./scripts/wrap-css.js dist/khiops-webcomponent/styles.css dist/khiops-webcomponent/styles.js
else
echo "No styles.css found, creating empty styles.js"
touch dist/khiops-webcomponent/styles.js
fi
cd dist/khiops-webcomponent
# Process main.js if it exists
if [ -f "main.js" ]; then
sed -i -E 's/(--mdc-[^:]*color[^:]*)([^\w-]|:)/--mdc-v2-\1\2/g' main.js
else
echo "No main.js found"
touch main.js
fi
# Create empty files if they don't exist
[ ! -f "polyfills.js" ] && touch polyfills.js
[ ! -f "styles.js" ] && touch styles.js
# Create bundle
cat polyfills.js styles.js main.js > khiops-webcomponents.bundle.js
echo "Bundle created, contents:"
ls -la
cd ../..
- name: Debug - Final check
working-directory: source
run: |
echo "Final check - Contents of dist directory:"
find dist/ -type f -name "*.js" || echo "No JS files found"
- name: Copy bundle to docs-repo
run: |
SAFE_BRANCH="${{ steps.branch.outputs.safe_name }}"
BRANCH_NAME="${{ steps.branch.outputs.name }}"
BUNDLE_SRC="source/dist/khiops-webcomponent/khiops-webcomponents.bundle.js"
BUNDLE_DEST="docs-repo/docs/dist/khiops-webcomponents-${SAFE_BRANCH}.bundle.js"
mkdir -p docs-repo/docs/dist
echo "Copying bundle: $BUNDLE_SRC → $BUNDLE_DEST"
cp "$BUNDLE_SRC" "$BUNDLE_DEST"
# Also copy to the legacy location for main (backward compatibility)
if [ "$BRANCH_NAME" = "main" ]; then
cp "$BUNDLE_SRC" docs-repo/docs/dist/khiops-webcomponents.bundle.js
echo "Copied legacy bundle: docs-repo/docs/dist/khiops-webcomponents.bundle.js"
fi
echo "Contents of docs-repo/docs/dist:"
ls -lh docs-repo/docs/dist/
- name: Commit and push changes to main
working-directory: docs-repo
run: |
git config --local user.email "stephane.bouget@orange.com"
git config --local user.name "Stéphane Bouget"
SAFE_BRANCH="${{ steps.branch.outputs.safe_name }}"
BRANCH_NAME="${{ steps.branch.outputs.name }}"
BUNDLE_FILE="docs/dist/khiops-webcomponents-${SAFE_BRANCH}.bundle.js"
MANIFEST="docs/dist/branches.json"
# Pull latest main first to get the most up-to-date manifest
git pull --no-rebase origin main || true
# Update branches manifest with current branch
if [ -f "$MANIFEST" ]; then
EXISTING=$(cat "$MANIFEST")
else
EXISTING='[]'
fi
EXISTING_IDX=$(echo "$EXISTING" | jq --arg safe "$SAFE_BRANCH" 'map(.safe) | index($safe)')
if [ "$EXISTING_IDX" = "null" ]; then
UPDATED=$(echo "$EXISTING" | jq --arg name "$BRANCH_NAME" --arg safe "$SAFE_BRANCH" '. + [{name: $name, safe: $safe}]')
else
UPDATED=$(echo "$EXISTING" | jq --arg name "$BRANCH_NAME" --arg safe "$SAFE_BRANCH" --argjson idx "$EXISTING_IDX" '.[$idx] = {name: $name, safe: $safe}')
fi
echo "$UPDATED" | jq 'sort_by(if .name == "main" then "" else .name end)' > "$MANIFEST"
# Force add new files (even if in gitignore)
git add -f "$BUNDLE_FILE"
git add -f "$MANIFEST"
# Also add legacy bundle for main (backward compatibility)
if [ "$BRANCH_NAME" = "main" ]; then
git add -f docs/dist/khiops-webcomponents.bundle.js
fi
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Generate khiops-webcomponents bundle for branch $BRANCH_NAME [skip ci]"
git push origin main
fi