Skip to content

Commit d671b6f

Browse files
committed
Use reusable workflows
1 parent 56ae37e commit d671b6f

1 file changed

Lines changed: 34 additions & 55 deletions

File tree

.github/workflows/deploy-published-releases.yaml

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,36 @@ env:
1414
PREVIEW_WIDGET_URL: https://cdn.croct.io/js/v1/lib/plug/widget-${{ github.ref_name }}.html
1515

1616
jobs:
17+
publish-npm:
18+
uses: croct-tech/github-workflows/.github/workflows/general/publish-npm-package.yml@unify-workflows
19+
with:
20+
node-version: "23"
21+
publish-access: "public"
22+
prepare-script: >-
23+
cp LICENSE README.md build/ &&
24+
cd build &&
25+
find . -type f -path '*/*\.js.map' -exec sed -i -e "s~../src~src~" {} + &&
26+
sed -i -e "s~\"version\": \"0.0.0-dev\"~\"version\": \"${GITHUB_REF##*/}\"~" package.json &&
27+
sed -i -e "s~<@cdnUrl@>~${CDN_URL}~" constants.* &&
28+
sed -i -e "s~<@playgroundOrigin@>~${PLAYGROUND_ORIGIN}~" constants.* &&
29+
sed -i -e "s~<@playgroundConnectUrl@>~${PLAYGROUND_CONNECT_URL}~" constants.* &&
30+
sed -i -e "s~<@previewWidgetOrigin@>~${PREVIEW_WIDGET_ORIGIN}~" constants.* &&
31+
sed -i -e "s~<@previewWidgetUrl@>~${PREVIEW_WIDGET_URL}~" constants.*
32+
secrets:
33+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
1735
deploy-library:
36+
if: ${{ !github.event.release.prerelease }}
37+
needs: publish-npm
1838
permissions:
19-
id-token: write # This is required for requesting the JWT
20-
contents: read # This is required for actions/checkout
39+
id-token: write
40+
contents: read
2141
runs-on: ubuntu-latest
2242
steps:
2343
- uses: actions/checkout@v6
2444
- uses: actions/setup-node@v6
2545
with:
26-
registry-url: 'https://registry.npmjs.org'
2746
node-version: 23
28-
env:
29-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3047

3148
- name: Cache dependencies
3249
id: cache-dependencies
@@ -37,65 +54,27 @@ jobs:
3754

3855
- name: Install dependencies
3956
if: steps.cache-dependencies.outputs.cache-hit != 'true'
40-
run: |-
41-
npm ci
42-
rm -rf ~/.npmrc
43-
44-
- name: Build package
45-
run: |-
46-
npm run build
47-
48-
- name: Prepare release
49-
run: |-
50-
cp LICENSE README.md build/
51-
cd build
52-
find . -type f -path '*/*\.js.map' -exec sed -i -e "s~../src~src~" {} +
53-
sed -i -e "s~\"version\": \"0.0.0-dev\"~\"version\": \"${GITHUB_REF##*/}\"~" package.json
54-
sed -i -e "s~<@cdnUrl@>~${CDN_URL}~" constants.*
55-
sed -i -e "s~<@playgroundOrigin@>~${PLAYGROUND_ORIGIN}~" constants.*
56-
sed -i -e "s~<@playgroundConnectUrl@>~${PLAYGROUND_CONNECT_URL}~" constants.*
57-
sed -i -e "s~<@previewWidgetOrigin@>~${PREVIEW_WIDGET_ORIGIN}~" constants.*
58-
sed -i -e "s~<@previewWidgetUrl@>~${PREVIEW_WIDGET_URL}~" constants.*
59-
60-
- name: Publish pre-release to NPM
61-
if: ${{ github.event.release.prerelease }}
62-
run: |-
63-
cd build
64-
npm publish --access public --tag next
65-
env:
66-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
67-
68-
- name: Publish release to NPM
69-
if: ${{ !github.event.release.prerelease }}
70-
run: |-
71-
cd build
72-
npm publish --access public
73-
env:
74-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
57+
run: npm ci
7558

7659
- name: Bundle package
77-
if: ${{ !github.event.release.prerelease }}
7860
run: |-
79-
rm -rf build
8061
npm run bundle -- --config-cdn-url=${CDN_URL} \
8162
--config-playground-origin=${PLAYGROUND_ORIGIN} \
8263
--config-playground-connect-url=${PLAYGROUND_CONNECT_URL} \
8364
--config-preview-widget-origin=${PREVIEW_WIDGET_ORIGIN} \
8465
--config-preview-widget-url=${PREVIEW_WIDGET_URL}
8566
86-
- id: 'auth'
87-
name: 'Authenticate to Google Cloud'
88-
if: ${{ !github.event.release.prerelease }}
89-
uses: 'google-github-actions/auth@v3'
67+
- name: Authenticate to Google Cloud
68+
id: auth
69+
uses: google-github-actions/auth@v3
9070
with:
91-
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}'
92-
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}'
71+
workload_identity_provider: ${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}
72+
service_account: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
9373

9474
- name: Set up Cloud SDK
9575
uses: google-github-actions/setup-gcloud@v3
9676

9777
- name: Deploy to GCS
98-
if: ${{ !github.event.release.prerelease }}
9978
env:
10079
GCLOUD_BUCKET: ${{ secrets.GCLOUD_BUCKET }}
10180
run: |-
@@ -104,8 +83,8 @@ jobs:
10483
10584
deploy-preview-widget:
10685
permissions:
107-
id-token: write # This is required for requesting the JWT
108-
contents: read # This is required for actions/checkout
86+
id-token: write
87+
contents: read
10988
runs-on: ubuntu-latest
11089
defaults:
11190
run:
@@ -130,12 +109,12 @@ jobs:
130109
- name: Build package
131110
run: npm run build
132111

133-
- id: auth
134-
name: Authenticate to Google Cloud
112+
- name: Authenticate to Google Cloud
113+
id: auth
135114
uses: google-github-actions/auth@v3
136115
with:
137-
workload_identity_provider: '${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}'
138-
service_account: '${{ secrets.GCLOUD_SERVICE_ACCOUNT }}'
116+
workload_identity_provider: ${{ secrets.GCLOUD_WORKLOAD_IDENTITY }}
117+
service_account: ${{ secrets.GCLOUD_SERVICE_ACCOUNT }}
139118

140119
- name: Set up Cloud SDK
141120
uses: google-github-actions/setup-gcloud@v3

0 commit comments

Comments
 (0)