-
Notifications
You must be signed in to change notification settings - Fork 14
150 lines (130 loc) · 5.06 KB
/
deploy-published-releases.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
name: Release
on:
release:
types:
- published
env:
CDN_URL: https://cdn.croct.io/js/v1/lib/plug.js
PLAYGROUND_ORIGIN: https://play.croct.com
PLAYGROUND_CONNECT_URL: https://play.croct.com/connect.html
PREVIEW_WIDGET_ORIGIN: https://cdn.croct.io
PREVIEW_WIDGET_PATH: js/v1/lib/plug/widget-${{ github.ref_name }}.html
PREVIEW_WIDGET_URL: https://cdn.croct.io/js/v1/lib/plug/widget-${{ github.ref_name }}.html
jobs:
deploy-library:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: |-
npm ci
rm -rf ~/.npmrc
- name: Build package
run: |-
npm run build
- name: Prepare release
run: |-
cp package.json LICENSE README.md build/
cd build
find . -type f -path '*/*\.js.map' -exec sed -i -e "s~../src~src~" {} +
sed -i -e "s~\"version\": \"0.0.0-dev\"~\"version\": \"${GITHUB_REF##*/}\"~" package.json
sed -i -e "s~<@cdnUrl@>~${CDN_URL}~" constants.*
sed -i -e "s~<@playgroundOrigin@>~${PLAYGROUND_ORIGIN}~" constants.*
sed -i -e "s~<@playgroundConnectUrl@>~${PLAYGROUND_CONNECT_URL}~" constants.*
sed -i -e "s~<@previewWidgetOrigin@>~${PREVIEW_WIDGET_ORIGIN}~" constants.*
sed -i -e "s~<@previewWidgetUrl@>~${PREVIEW_WIDGET_URL}~" constants.*
cp -r ../src src
- name: Publish pre-release to NPM
if: ${{ github.event.release.prerelease }}
run: |-
cd build
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
npm publish --access public --tag next
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish release to NPM
if: ${{ !github.event.release.prerelease }}
run: |-
cd build
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Bundle package
if: ${{ !github.event.release.prerelease }}
run: |-
rm -rf build
npm run bundle -- --config-cdn-url=${CDN_URL} \
--config-playground-origin=${PLAYGROUND_ORIGIN} \
--config-playground-connect-url=${PLAYGROUND_CONNECT_URL} \
--config-preview-widget-origin=${PREVIEW_WIDGET_ORIGIN} \
--config-preview-widget-url=${PREVIEW_WIDGET_URL}
- id: 'auth'
name: 'Authenticate to Google Cloud'
if: ${{ !github.event.release.prerelease }}
uses: 'google-github-actions/auth@v2'
with:
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}'
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Deploy to GCS
if: ${{ !github.event.release.prerelease }}
env:
GCLOUD_BUCKET: ${{ secrets.GCLOUD_BUCKET }}
run: |-
gsutil -m cp build/plug.min.js "gs://${GCLOUD_BUCKET}/js/v1/lib/plug.js"
gsutil -m setmeta -h "Cache-Control: public, max-age=3600" "gs://${GCLOUD_BUCKET}/js/v1/lib/plug.js"
deploy-preview-widget:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
runs-on: ubuntu-latest
defaults:
run:
working-directory: preview
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: |-
npm ci
- name: Build package
run: |-
npm run build
- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}'
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}'
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Deploy to GCS
env:
GCLOUD_BUCKET: ${{ secrets.GCLOUD_BUCKET }}
run: |-
gsutil -m cp dist/widget.html "gs://${GCLOUD_BUCKET}/${PREVIEW_WIDGET_PATH}"
gsutil -m setmeta -h "Cache-Control: public, max-age=3600" "gs://${GCLOUD_BUCKET}/${PREVIEW_WIDGET_PATH}"