-
Notifications
You must be signed in to change notification settings - Fork 20
224 lines (194 loc) · 9.65 KB
/
documentation-deploy-pr.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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Deploy documentations artefacts [PR]
on:
pull_request_target:
branches:
- dev
pull_request:
branches:
- master
concurrency:
# New commit on branch cancels running workflows of the same branch
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
authorize:
name: Authorize external pull request
if: ${{ !startsWith(github.head_ref, 'release') }}
uses: ./.github/workflows/authorize-external-pr.yml
state:
name: Handle lerna changed state
needs: [authorize]
uses: ./.github/workflows/change-detection.yml
with:
ref: refs/pull/${{github.event.pull_request.number}}/merge
secrets: inherit
deploy-website:
name: Deploy website artifacts
needs: [ state ]
if: ${{ fromJSON(needs.state.outputs.STATE).HAS_DEPLOY_WEBSITE }}
runs-on: ubuntu-22.04
env:
PR_NAME: pr-${{ github.event.number }}
PREFIX: pr/pr-${{ github.event.number }}
steps:
- uses: actions/checkout@v4
with:
ref: refs/pull/${{github.event.pull_request.number}}/merge
show-progress: false
- name: Prepare environment
uses: ./.github/actions/prepare-environment
- name: Lerna bootstrap
run: npx lerna bootstrap --scope="@salutejs/core-themes" --scope="@salutejs/plasma-{b2c,web,website,tokens-b2c,typo,icons,new-hope,themes}"
- name: Prepare directory
run: |
mkdir -p s3_build/${PR_NAME}
# TODO: https://github.com/salute-developers/plasma/issues/603
- name: Plasma Website
run: |
export NODE_OPTIONS=--openssl-legacy-provider
npm run build --prefix="./website/plasma-website"
cp -R ./website/plasma-website/build/. ./s3_build/${PR_NAME}
- name: Install s3cmd
run: pip3 install s3cmd
- name: s3 Upload
run: >
s3cmd
--access_key ${{ secrets.AWS_ACCESS_KEY_ID }}
--secret_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
--host ${{ secrets.AWS_ENDPOINT }}
--host-bucket ${{ secrets.AWS_ENDPOINT }}
--bucket-location ${{ secrets.AWS_REGION }}
--signature-v2
--no-mime-magic
sync
./s3_build/${PR_NAME}/
s3://${{ secrets.AWS_S3_BUCKET_2 }}/pr/${PR_NAME}/
deploy-artifacts:
name: Deploy artifacts
needs: [ state, deploy-website ]
if: ${{ fromJSON(needs.state.outputs.STATE).HAS_PACKAGES_DS_CHANGES }}
runs-on: ubuntu-22.04
env:
PR_NAME: pr-${{ github.event.number }}
PREFIX: pr/pr-${{ github.event.number }}
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.state.outputs.STATE).PACKAGES_DOCUMENTATIONS_RUN }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
ref: refs/pull/${{github.event.pull_request.number}}/merge
- name: Prepare environment
uses: ./.github/actions/prepare-environment
- name: Set job environment variables
run: |
echo "SHORT_NAME=$(echo ${{ matrix.package }} | sed -r 's/plasma-//g')" >> $GITHUB_ENV
echo "HAS_PACKAGE_DOCS=$([ -d "./website/${{ matrix.package }}-docs" ] && echo true || echo false)" >> $GITHUB_ENV
- name: Get lerna scope
id: lerna-scope
uses: actions/github-script@v7
env:
PROCESSED_DATA: ${{ toJSON(fromJson(needs.state.outputs.STATE).PROCESSED_DATA) }}
PACKAGE: ${{ matrix.package }}
with:
result-encoding: string
script: |
const getLernaScope = require('./.github/get-lerna-scope.js');
return getLernaScope();
- name: Lerna bootstrap
run: npx lerna bootstrap --scope="${{ steps.lerna-scope.outputs.result }}"
- name: Prepare directory
run: mkdir -p s3_build/${PR_NAME}
- name: Build documentation - "${{ matrix.package }}"
if: ${{ fromJSON(env.HAS_PACKAGE_DOCS) }}
run: |
npm run build --prefix="./website/${{ matrix.package }}-docs" -- --no-minify
cp -R ./website/${{ matrix.package }}-docs/build ./s3_build/${PR_NAME}/${{ env.SHORT_NAME }}
- name: Build storybook - "${{ matrix.package }}"
run: |
npm run storybook:build --prefix="./packages/${{ matrix.package }}"
cp -R ./packages/${{ matrix.package }}/build-sb ./s3_build/${PR_NAME}/${{ env.SHORT_NAME }}-storybook
## Проверяем если в пакете скрипт отвечающий за сборку компонентов на основе черновика
- name: Build draft components storybook - "${{ matrix.package }}"
run: |
if grep -q '"storybook:draft"' "./packages/${{ matrix.package }}/package.json"; then
npm run storybook:build:draft --prefix="./packages/${{ matrix.package }}"
cp -R ./packages/${{ matrix.package }}/build-sb-draft ./s3_build/${PR_NAME}/${{ env.SHORT_NAME }}-draft-storybook
echo "HAS_DRAFT_COMPONENTS=true" >> $GITHUB_ENV
else
echo "Package not have draft components"
fi
- name: Install s3cmd
run: pip3 install s3cmd
- name: s3 upload docs
if: ${{ fromJSON(env.HAS_PACKAGE_DOCS) }}
run: >
s3cmd
--access_key ${{ secrets.AWS_ACCESS_KEY_ID }}
--secret_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
--host ${{ secrets.AWS_ENDPOINT }}
--host-bucket ${{ secrets.AWS_ENDPOINT }}
--bucket-location ${{ secrets.AWS_REGION }}
--signature-v2
--delete-removed
--no-mime-magic
sync
./s3_build/${PR_NAME}/${{ env.SHORT_NAME }}/
s3://${{ secrets.AWS_S3_BUCKET_2 }}/pr/${PR_NAME}/${{ env.SHORT_NAME }}/
- name: s3 upload storybook by draft components
if: ${{ env.HAS_DRAFT_COMPONENTS == 'true' }}
run: >
s3cmd
--access_key ${{ secrets.AWS_ACCESS_KEY_ID }}
--secret_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
--host ${{ secrets.AWS_ENDPOINT }}
--host-bucket ${{ secrets.AWS_ENDPOINT }}
--bucket-location ${{ secrets.AWS_REGION }}
--signature-v2
--delete-removed
--no-mime-magic
sync
./s3_build/${PR_NAME}/${{ env.SHORT_NAME }}-draft-storybook/
s3://${{ secrets.AWS_S3_BUCKET_2 }}/pr/${PR_NAME}/${{ env.SHORT_NAME }}-draft-storybook/
- name: s3 upload storybook
run: >
s3cmd
--access_key ${{ secrets.AWS_ACCESS_KEY_ID }}
--secret_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
--host ${{ secrets.AWS_ENDPOINT }}
--host-bucket ${{ secrets.AWS_ENDPOINT }}
--bucket-location ${{ secrets.AWS_REGION }}
--signature-v2
--delete-removed
--no-mime-magic
sync
./s3_build/${PR_NAME}/${{ env.SHORT_NAME }}-storybook/
s3://${{ secrets.AWS_S3_BUCKET_2 }}/pr/${PR_NAME}/${{ env.SHORT_NAME }}-storybook/
attache-comment:
name: Attached comment
needs: [ state, deploy-website, deploy-artifacts ]
if: ${{ always() && (contains(needs.deploy-website.result, 'success') || contains(needs.deploy-artifacts.result, 'success')) }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: refs/pull/${{github.event.pull_request.number}}/merge
show-progress: false
- name: Create comment
id: comment-link
uses: actions/github-script@v7
env:
PACKAGES_DS: ${{ toJSON(fromJSON(needs.state.outputs.STATE).PACKAGES_DOCUMENTATIONS_RUN) }}
BASE_URL: ${{ vars.STAGE_STABLE_URL }}/pr/pr-${{ github.event.number }}
with:
result-encoding: string
script: |
const createLinks = require('./.github/create-links.js');
return createLinks();
- name: Attach comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: Links
message: ${{ steps.comment-link.outputs.result }}