Skip to content

Commit 6b6e7b3

Browse files
jamieomaguireBen Siggerysiggerzz
authored
feat(pie-cookie-banner): DSW-2679 CDN build output (#2193)
* feat(pie-cookie-banner): DSW-2679 cDN build output * include dist * test * add github action to publish to CDN * add github action to publish to CDN * add github action to publish to CDN * add github action to publish to CDN * add github action to publish to CDN * add github action to publish to CDN * fix formatting * trigger ci * trigger ci * try native aws cli * try native aws cli * try native aws cli * fi region * uncomment ci * update bucket artifact dest path * fix path * fix file name --------- Co-authored-by: Ben Siggery <[email protected]> Co-authored-by: Ben Siggery <[email protected]>
1 parent 2774a61 commit 6b6e7b3

File tree

9 files changed

+175
-40
lines changed

9 files changed

+175
-40
lines changed

.changeset/tidy-dolls-confess.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@justeattakeaway/pie-cookie-banner": patch
3+
---
4+
5+
[Added] - CDN dist output containing all cookie-banner and dependency code for uses where consumers cannot use npm/yarn or build tools.

.github/workflows/changeset-release.yml

+21
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ env:
2222

2323
jobs:
2424
changesets:
25+
outputs:
26+
published: ${{ steps.changesets-main.outputs.published }}
27+
published-packages: ${{ steps.changesets-main.outputs.publishedPackages }}
2528
runs-on: ${{ inputs.os }}
2629
if: github.repository == 'justeattakeaway/pie' && ${{ github.event_name != 'pull_request' }} &&
2730
(contains(github.ref_name, 'main') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'feature'))
@@ -198,3 +201,21 @@ jobs:
198201
}
199202
env:
200203
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
204+
205+
publish-cookie-banner-cdn:
206+
needs: changesets
207+
runs-on: ${{ inputs.os }}
208+
if: needs.changesets.outputs.published == 'true' && contains(needs.changesets.outputs.publishedPackages, '@justeattakeaway/pie-cookie-banner')
209+
steps:
210+
- name: Extract cookie banner version
211+
id: extract-version
212+
run: |
213+
PACKAGES='${{ needs.changesets.outputs.publishedPackages}}'
214+
COOKIE_BANNER_VERSION=$(echo $PACKAGES | jq -r '.[] | select(.name == "@justeattakeaway/pie-cookie-banner") | .version')
215+
echo "cookie_banner_version=$COOKIE_BANNER_VERSION" >> $GITHUB_OUTPUT
216+
- name: Publish Cookie Banner CDN
217+
uses: ./.github/workflows/pie-cookie-banner-cdn-publish.yml
218+
with:
219+
os: ${{ inputs.os }}
220+
node-version: ${{ inputs.node-version }}
221+
package-version: v${{ steps.extract-version.outputs.cookie_banner_version }}

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,4 @@ jobs:
363363
with:
364364
# "allowed-skips" lists jobs that are optional but should not fail
365365
allowed-skips: browser-tests-components, deploy-docs, deploy-storybook, browser-tests-docs
366-
jobs: ${{ toJSON(needs) }}
366+
jobs: ${{ toJSON(needs) }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish Pie Cookie Banner to CDN
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
os:
7+
required: true
8+
type: string
9+
node-version:
10+
required: true
11+
type: string
12+
package-version:
13+
required: true
14+
type: string
15+
16+
env:
17+
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
18+
19+
jobs:
20+
publish-cookie-banner-cdn:
21+
runs-on: ${{ inputs.os }}
22+
steps:
23+
# Checkout the Repo
24+
- name: Checkout
25+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+
# Setup Repo
27+
- name: Setup Repo
28+
uses: ./.github/actions/setup-repo
29+
with:
30+
node-version: ${{ inputs.node-version }}
31+
os: ${{ inputs.os }}
32+
# Build
33+
- name: Build Cookie Banner
34+
uses: ./.github/actions/run-script
35+
with:
36+
script-name: "build --filter=pie-cookie-banner"
37+
38+
- name: Upload to S3
39+
run: |
40+
aws s3 sync ${{ github.workspace }}/packages/components/pie-cookie-banner/cdn_dist/ s3://${{ vars.PIE_CDN_BUCKET_NAME }}/pie-cookie-banner/${{ inputs.package-version }}/ --region ${{ env.AWS_REGION }} --content-type "text/javascript"
41+
env:
42+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
43+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
44+
AWS_REGION: eu-west-1

packages/components/pie-cookie-banner/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.turbo
2+
cdn_dist
23
dist
34
node_modules
45
lit-browsers-report
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cdn_dist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { defineConfig } from 'vite';
2+
import dts from 'vite-plugin-dts';
3+
import { visualizer } from 'rollup-plugin-visualizer';
4+
5+
import { deepmerge } from 'deepmerge-ts';
6+
7+
// https://vitejs.dev/config/
8+
const sharedConfig = ({ build = {}, plugins = [], ...rest }) => defineConfig({
9+
build: deepmerge({
10+
lib: {
11+
entry: {
12+
index: 'src/index.ts',
13+
},
14+
formats: ['es'],
15+
},
16+
rollupOptions: {
17+
external: (id) => {
18+
if (['react', '@lit/react'].includes(id)) {
19+
return true;
20+
}
21+
return false;
22+
},
23+
},
24+
outDir: 'cdn_dist',
25+
}, build),
26+
test: {
27+
dir: '.',
28+
environment: 'jsdom',
29+
globals: true,
30+
include: [
31+
'./src/__tests__/**/*.{spec,test}.{js,ts}',
32+
'./test/unit/**/*.{spec,test}.{js,ts}',
33+
],
34+
exclude: ['**/node_modules/**'],
35+
},
36+
plugins: deepmerge([dts({
37+
insertTypesEntry: true,
38+
outputDir: 'cdn_dist',
39+
rollupTypes: true,
40+
}),
41+
visualizer({
42+
gzipSize: true,
43+
brotliSize: true,
44+
})], plugins),
45+
46+
...rest,
47+
});
48+
49+
export default sharedConfig;

packages/components/pie-cookie-banner/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
"custom-elements.json",
1717
"src",
1818
"dist",
19+
"cdn_dist",
1920
"locales",
2021
"**/*.d.ts"
2122
],
2223
"pieMetadata": {
2324
"componentStatus": "stable"
2425
},
2526
"scripts": {
26-
"build": "run -T vite build",
27+
"build": "run -T vite build && yarn build:cdn",
28+
"build:cdn": "run -T vite build --config './cdn.vite.config.js'",
2729
"build:react-wrapper": "npx build-react-wrapper",
2830
"create:manifest": "yarn cem analyze --litelement",
2931
"lint:scripts": "run -T eslint .",
@@ -61,6 +63,7 @@
6163
},
6264
"customElements": "custom-elements.json",
6365
"sideEffects": [
64-
"dist/*.js"
66+
"dist/*.js",
67+
"cdn_dist/*.js"
6568
]
6669
}
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,51 @@
11
{
2-
"$schema": "https://turborepo.org/schema.json",
3-
"extends": [
4-
"//"
5-
],
6-
"pipeline": {
7-
"test:browsers": {
8-
"cache": true,
9-
"dependsOn": [],
10-
"inputs": [
11-
"$TURBO_DEFAULT$",
12-
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
13-
]
14-
},
15-
"test:browsers:ci": {
16-
"cache": true,
17-
"dependsOn": [],
18-
"inputs": [
19-
"$TURBO_DEFAULT$",
20-
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
21-
]
22-
},
2+
"$schema": "https://turborepo.org/schema.json",
3+
"extends": [
4+
"//"
5+
],
6+
"pipeline": {
7+
"build": {
8+
"cache": true,
9+
"dependsOn": [
10+
"^build",
11+
"build:react-wrapper"
12+
],
13+
"outputs": [
14+
"dist/**",
15+
"cdn_dist/**"
16+
]
17+
},
18+
"test:browsers": {
19+
"cache": true,
20+
"dependsOn": [],
21+
"inputs": [
22+
"$TURBO_DEFAULT$",
23+
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
24+
]
25+
},
26+
"test:browsers:ci": {
27+
"cache": true,
28+
"dependsOn": [],
29+
"inputs": [
30+
"$TURBO_DEFAULT$",
31+
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
32+
]
33+
},
2334
"test:visual": {
24-
"cache": false,
25-
"dependsOn": [],
26-
"inputs": [
27-
"$TURBO_DEFAULT$",
28-
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
29-
]
30-
},
31-
"test:visual:ci": {
32-
"cache": false,
33-
"dependsOn": [],
34-
"inputs": [
35-
"$TURBO_DEFAULT$",
36-
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
37-
]
38-
}
35+
"cache": false,
36+
"dependsOn": [],
37+
"inputs": [
38+
"$TURBO_DEFAULT$",
39+
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
40+
]
41+
},
42+
"test:visual:ci": {
43+
"cache": false,
44+
"dependsOn": [],
45+
"inputs": [
46+
"$TURBO_DEFAULT$",
47+
"../../../apps/pie-storybook/stories/testing/pie-cookie-banner.test.stories.ts"
48+
]
3949
}
40-
}
50+
}
51+
}

0 commit comments

Comments
 (0)