Skip to content

Commit 3d7cb6c

Browse files
committed
xuy-UID2-6105-deployment-pipeline
1 parent fe0abba commit 3d7cb6c

File tree

2 files changed

+189
-3
lines changed

2 files changed

+189
-3
lines changed

.github/actions/cdn_deployment_aws/action.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: CDN Deployment for AWS
22
description: Deploys to AWS CDN and optionally invalidates the path in CloudFront
33
inputs:
4-
environment:
5-
description: Environment to deploy to
6-
default: 'integ'
74
artifact:
85
description: Name of the artifact
96
required: true
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Release SDK Package to NPM and CDN (Consolidated)
2+
run-name: ${{ inputs.release_type == 'Snapshot' && 'Publish Pre-release' || format('Release {0}', inputs.release_type)}} SDK Package to NPM and CDN by @${{ github.actor }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
release_type:
8+
type: choice
9+
description: The type of release
10+
options:
11+
- Major
12+
- Minor
13+
- Patch
14+
- Snapshot
15+
required: true
16+
with_tag:
17+
description: By default, running npm publish will tag your package with the latest dist-tag. To use another dist-tag, please add tag here
18+
required: false
19+
publish_to_npm:
20+
type: boolean
21+
description: Publish package to NPM (In general, always release to both)
22+
required: false
23+
default: true
24+
publish_to_cdn:
25+
type: boolean
26+
description: Publish package to CDN (In general, always release to both)
27+
required: false
28+
default: true
29+
30+
jobs:
31+
incrementVersionNumber:
32+
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-increase-version-number.yaml@v2
33+
with:
34+
release_type: ${{ inputs.release_type }}
35+
secrets: inherit
36+
37+
build:
38+
runs-on: ubuntu-latest
39+
needs: [incrementVersionNumber]
40+
strategy:
41+
matrix:
42+
node-version: [20.x]
43+
target: [development, production]
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
48+
- name: Use Node.js ${{ matrix.node-version }}
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: ${{ matrix.node-version }}
52+
- name: Get Package Version
53+
id: version
54+
run: |
55+
echo "package_version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
56+
- name: Install dependencies
57+
run: npm install
58+
- name: Build script
59+
run: npm run build -- --mode=${{ matrix.target }}
60+
- uses: actions/upload-artifact@v4
61+
if: inputs.publish_to_cdn
62+
with:
63+
name: uid2SDK-${{ matrix.target }}-${{ steps.version.outputs.package_version }}
64+
path: ./dist/uid2-sdk-${{ steps.version.outputs.package_version }}.js
65+
- uses: actions/upload-artifact@v4
66+
if: inputs.publish_to_cdn
67+
with:
68+
name: euidSDK-${{ matrix.target }}-${{ steps.version.outputs.package_version }}
69+
path: ./dist/euid-sdk-${{ steps.version.outputs.package_version }}.js
70+
outputs:
71+
sdkVersion: ${{ steps.version.outputs.package_version }}
72+
73+
createNpmJsRelease:
74+
needs: [incrementVersionNumber, build]
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Build Changelog
78+
id: github_release_changelog
79+
uses: mikepenz/release-changelog-builder-action@v4
80+
with:
81+
toTag: v${{ needs.incrementVersionNumber.outputs.new_version }}
82+
configurationJson: |
83+
{
84+
"pr_template": " - #{{TITLE}} - ( PR: ##{{NUMBER}} )"
85+
}
86+
- name: Create Release Notes
87+
uses: softprops/action-gh-release@v2
88+
with:
89+
name: v${{ needs.incrementVersionNumber.outputs.new_version }}
90+
body: ${{ steps.github_release_changelog.outputs.changelog }}
91+
draft: true
92+
93+
publish-package:
94+
if: inputs.publish_to_npm
95+
needs: [build, incrementVersionNumber]
96+
runs-on: ubuntu-latest
97+
steps:
98+
- uses: actions/checkout@v4
99+
with:
100+
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
101+
- uses: actions/setup-node@v4
102+
with:
103+
node-version: '20.x'
104+
registry-url: 'https://registry.npmjs.org'
105+
scope: uid2
106+
- run: npm ci
107+
- name: Build package
108+
run: npm run build-package
109+
- name: Publish Latest package
110+
if: ${{!github.event.inputs.with_tag}}
111+
run: |
112+
npm publish ./dist/uid2-npm --access public
113+
npm publish ./dist/euid-npm --access public
114+
env:
115+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
116+
- name: Publish Latest package with tag
117+
if: ${{github.event.inputs.with_tag}}
118+
run: |
119+
npm publish ./dist/uid2-npm --tag ${{github.event.inputs.with_tag}} --access public
120+
npm publish ./dist/euid-npm --tag ${{github.event.inputs.with_tag}} --access public
121+
env:
122+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
123+
124+
# Test Environment - UID2 only first
125+
cdn-deployment-test:
126+
if: inputs.publish_to_cdn
127+
needs: [build, incrementVersionNumber]
128+
runs-on: ubuntu-latest
129+
permissions:
130+
id-token: write
131+
environment: test
132+
steps:
133+
- uses: actions/checkout@v4
134+
with:
135+
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
136+
- uses: ./.github/actions/cdn_deployment_aws
137+
with:
138+
artifact: uid2SDK-development-${{ needs.build.outputs.sdkVersion}}
139+
invalidate_paths: '/uid2-sdk-${{ needs.build.outputs.sdkVersion}}.js'
140+
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}
141+
aws_bucket_name: ${{ secrets.S3_BUCKET }}
142+
aws_distribution_id: ${{ secrets.AWS_DISTRIBUTION_ID }}
143+
144+
approval-to-deploy:
145+
name: Approval To Deploy
146+
needs: [cdn-deployment-test]
147+
runs-on: ubuntu-latest
148+
environment: production
149+
steps:
150+
- name: Approval to deploy
151+
shell: bash
152+
run: echo "Approved"
153+
154+
# Consolidated CDN Deployment with Matrix
155+
cdn-deployment:
156+
if: inputs.publish_to_cdn
157+
needs: [build, incrementVersionNumber, approval-to-deploy]
158+
runs-on: ubuntu-latest
159+
permissions:
160+
id-token: write
161+
strategy:
162+
matrix:
163+
include:
164+
# UID2 Environments
165+
- product: uid2
166+
github_env: uid2-integ
167+
build_type: development
168+
- product: uid2
169+
github_env: uid2-prod
170+
build_type: production
171+
# EUID Environments
172+
- product: euid
173+
github_env: euid-integ
174+
build_type: development
175+
- product: euid
176+
github_env: euid-prod
177+
build_type: production
178+
environment: ${{ matrix.github_env }}
179+
steps:
180+
- uses: actions/checkout@v4
181+
with:
182+
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
183+
- uses: ./.github/actions/cdn_deployment_aws
184+
with:
185+
artifact: ${{ matrix.product }}SDK-${{ matrix.build_type }}-${{ needs.build.outputs.sdkVersion}}
186+
invalidate_paths: '/${{ matrix.product }}-sdk-${{ needs.build.outputs.sdkVersion}}.js'
187+
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}
188+
aws_bucket_name: ${{ secrets.S3_BUCKET }}
189+
aws_distribution_id: ${{ secrets.AWS_DISTRIBUTION_ID }}

0 commit comments

Comments
 (0)