generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
195 lines (171 loc) · 7.94 KB
/
deploy-pr-preview.yaml
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
185
186
187
188
189
190
191
192
193
194
195
# Run it locally with act
# 1. Install act:
# `brew install act`
# 2. Create a .secret file with the following content:
# `GITHUB_TOKEN=your_github_token`
# PULL REQUEST
# 1. Create a act_pull_request.json file in case of a pull request with the following content:
# `{"pull_request": {"number": <PR number>, "head": {"ref": "<PR branch name>", "sha": "PR commit sha"}, "base": {"ref": "main"}}, "repository": {"name": "juno", "owner": {"login": "cloudoperators"}}}`
# 2. Run the following command:
# `act pull_request --container-architecture linux/amd64 -P default=catthehacker/ubuntu:act-latest -e act_pull_request.json -W .github/workflows/deploy-pr-preview.yaml`
name: PR Preview Deployment 🚀
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
paths:
- "packages/ui-components/**"
- "apps/supernova/**"
- "apps/heureka/**"
- "apps/doop/**"
- "apps/carbon/**"
- "apps/greenhouse/**"
# Limit the concurrency of entire workflow
concurrency: deploy-pr-preview-${{ github.ref }}
env:
DEPLOY_PATH: tmp
jobs:
run-detect-changes:
uses: ./.github/workflows/shared-detect-pkg-changes.yaml
with:
paths: "packages apps"
runs-on: default
build-deploy:
needs: [run-detect-changes]
runs-on: [default]
steps:
- uses: actions/checkout@v4
- name: Precompile ENVs
if: github.event.action != 'closed'
id: compile-envs
run: |
#setup ENVs for each app to preview
echo "IS_STORYBOOK_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'ui-components') }}" >> $GITHUB_ENV
echo "IS_SUPERNOVA_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'supernova') }}" >> $GITHUB_ENV
echo "IS_HEUREKA_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'heureka') }}" >> $GITHUB_ENV
echo "IS_DOOP_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'doop') }}" >> $GITHUB_ENV
echo "IS_CARBON_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'carbon') }}" >> $GITHUB_ENV
echo "IS_GREENHOUSE_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'greenhouse') }}" >> $GITHUB_ENV
echo "IS_EXAMPLE_CHANGED=${{ contains(needs.run-detect-changes.outputs.changes, 'example') || contains(needs.run-detect-changes.outputs.changes, 'ui-components') }}" >> $GITHUB_ENV
- uses: actions/setup-node@v4
if: github.event.action != 'closed'
with:
node-version: "20.x"
- name: Install dependencies
if: github.event.action != 'closed'
run: |
npm install --force
- name: Create a folder with all compiled apps and pkgs
if: github.event.action != 'closed'
run: |
mkdir -p ${{ env.DEPLOY_PATH }}
- name: Build STORYBOOK if changes detected
id: build-storybook
if: github.event.action != 'closed' && env.IS_STORYBOOK_CHANGED == 'true'
run: |
npm -w @cloudoperators/juno-ui-components run build-storybook
cp -r ${{ env.PACKAGE_PATH }}/storybook-static ${{ env.DEPLOY_PATH }}/${{ env.TARGET_FOLDER }}
env:
PACKAGE_PATH: packages/ui-components
TARGET_FOLDER: storybook
continue-on-error: true
- name: Build SUPERNOVA if changes detected
id: build-supernova
if: github.event.action != 'closed' && env.IS_SUPERNOVA_CHANGED == 'true'
run: |
./.github/scripts/build-vite-app.sh
env:
PACKAGE_PATH: apps/supernova
TARGET_FOLDER: supernova
APP_PROPS_BASE64: ${{ secrets.SUPERNOVA_APP_PROPS_BASE64 }}
continue-on-error: true
- name: Build HEUREKA if changes detected
id: build-heureka
if: github.event.action != 'closed' && env.IS_HEUREKA_CHANGED == 'true'
run: ./.github/scripts/build-vite-app.sh
env:
PACKAGE_PATH: apps/heureka
TARGET_FOLDER: heureka
APP_PROPS_BASE64: ${{ secrets.HEUREKA_APP_PROPS_BASE64 }}
continue-on-error: true
- name: Build DOOP if changes detected
id: build-doop
if: github.event.action != 'closed' && env.IS_DOOP_CHANGED == 'true'
run: ./.github/scripts/build-vite-app.sh
env:
PACKAGE_PATH: apps/doop
TARGET_FOLDER: doop
APP_PROPS_BASE64: ${{ secrets.DOOP_APP_PROPS_BASE64 }}
continue-on-error: true
- name: Build CARBON if changes detected
id: build-carbon
if: github.event.action != 'closed' && env.IS_CARBON_CHANGED == 'true'
run: ./.github/scripts/build-vite-app.sh
env:
PACKAGE_PATH: apps/carbon
TARGET_FOLDER: carbon
continue-on-error: true
- name: Build GREENHOUSE if changes detected
id: build-greenhouse
if: github.event.action != 'closed' && env.IS_GREENHOUSE_CHANGED == 'true'
run: |
./.github/scripts/build-vite-app.sh
# Specific changes for greenhouse
sed -i 's|/appProps.json?%VERSION%|./appProps.json|g' "$DEPLOY_PATH/$TARGET_FOLDER/index.html"
sed -i "s|/index.js?%VERSION%|./$entry_file_escaped|g" "$DEPLOY_PATH/$TARGET_FOLDER/index.html"
env:
PACKAGE_PATH: apps/greenhouse
TARGET_FOLDER: greenhouse
APP_PROPS_BASE64: ${{ secrets.GREENHOUSE_APP_PROPS_BASE64 }}
continue-on-error: true
- name: Build EXAMPLE if changes detected
id: build-example
if: github.event.action != 'closed' && env.IS_EXAMPLE_CHANGED == 'true'
run: ./.github/scripts/build-vite-app.sh
env:
PACKAGE_PATH: apps/example
TARGET_FOLDER: example
continue-on-error: true
- name: Generate index.html for Deployed Apps
if: github.event.action != 'closed'
env:
STORYBOOK_OUTCOME: "${{ steps.build-storybook.outcome }}"
SUPERNOVA_OUTCOME: "${{ steps.build-supernova.outcome }}"
HEUREKA_OUTCOME: "${{ steps.build-heureka.outcome }}"
DOOP_OUTCOME: "${{ steps.build-doop.outcome }}"
CARBON_OUTCOME: "${{ steps.build-carbon.outcome }}"
GREENHOUSE_OUTCOME: "${{ steps.build-greenhouse.outcome }}"
EXAMPLE_OUTCOME: "${{ steps.build-example.outcome }}"
run: |
echo "<!DOCTYPE html><head><title>PR Preview</title></head><html><body><h1>Deployed Packages for PR ${GITHUB_HEAD_REF}</h1><ul>" > ${{ env.DEPLOY_PATH }}/index.html
# components name should map to the IS_<component>_CHANGED
COMPONENTS=("storybook" "supernova" "heureka" "doop" "carbon" "example" "greenhouse")
for component in "${COMPONENTS[@]}"; do
CHANGED_VAR="IS_${component^^}_CHANGED" # Make it uppercase for the env var
CHANGED="${!CHANGED_VAR}" # Get the value of the environment variable
if [ "$CHANGED" = "true" ]; then
OUTCOME_VAR="${component^^}_OUTCOME" # Make it uppercase for the env var
echo "==OUTCOME_VAR=="
echo $OUTCOME_VAR
echo "==="
BUILD_OUTCOME="${!OUTCOME_VAR}" # Get the value of the environment variable
echo "==BUILD_OUTCOME=="
echo $BUILD_OUTCOME
echo "==="
if [ "$BUILD_OUTCOME" == "success" ]; then
echo "<li><a href='./${component}/index.html' target="_blank">${component^} <span style='color:green;'>✓ Success</span></a></li>" >> ${{ env.DEPLOY_PATH }}/index.html
else
echo "<li>${component^} <span style='color:red;'>✗ Failed</span></li>" >> ${{ env.DEPLOY_PATH }}/index.html
fi
fi
done
echo "</ul></body></html>" >> ${{ env.DEPLOY_PATH }}/index.html
- uses: rossjrw/pr-preview-action@v1
with:
source-dir: ${{ env.DEPLOY_PATH }}/
preview-branch: gh-pages
umbrella-dir: pr-preview
action: auto