Skip to content

Release Minor SDK Package to NPM and CDN by @ashleysmithTTD #58

Release Minor SDK Package to NPM and CDN by @ashleysmithTTD

Release Minor SDK Package to NPM and CDN by @ashleysmithTTD #58

name: Release SDK Package to NPM and CDN
run-name: ${{ inputs.release_type == 'Snapshot' && 'Publish Pre-release' || format('Release {0}', inputs.release_type)}} SDK Package to NPM and CDN by @${{ github.actor }}
on:
workflow_dispatch:
inputs:
release_type:
type: choice
description: The type of release
options:
- Major
- Minor
- Patch
- Snapshot
required: true
with_tag:
description: By default, running npm publish will tag your package with the latest dist-tag. To use another dist-tag, please add tag here
required: false
publish_to_npm:
type: boolean
description: Publish package to NPM (In general, always release to both)
required: false
default: true
publish_to_cdn:
type: boolean
description: Publish package to CDN (In general, always release to both)
required: false
default: true
jobs:
incrementVersionNumber:
uses: IABTechLab/uid2-shared-actions/.github/workflows/shared-increase-version-number.yaml@v2
with:
release_type: ${{ inputs.release_type }}
secrets: inherit
build:
runs-on: ubuntu-latest
needs: [incrementVersionNumber]
strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
target: [development, production]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Get Package Version
id: version
run: |
echo "package_version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
- name: Install dependencies
run: npm install
- name: Build script
run: npm run build -- --mode=${{ matrix.target }}
- uses: actions/upload-artifact@v4
if: inputs.publish_to_cdn
with:
name: uid2SDK-${{ matrix.target }}-${{ steps.version.outputs.package_version }}
path: ./dist/uid2-sdk-${{ steps.version.outputs.package_version }}.js
- uses: actions/upload-artifact@v4
if: inputs.publish_to_cdn
with:
name: euidSDK-${{ matrix.target }}-${{ steps.version.outputs.package_version }}
path: ./dist/euid-sdk-${{ steps.version.outputs.package_version }}.js
outputs:
sdkVersion: ${{ steps.version.outputs.package_version }}
publish-package:
if: inputs.publish_to_npm
needs: [build, incrementVersionNumber]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
scope: uid2
- run: npm ci
- name: Build package
run: npm run build-package
- name: Publish Latest package
if: ${{!github.event.inputs.with_tag}}
run: |
npm publish ./dist/uid2-npm --access public
npm publish ./dist/euid-npm --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Latest package with tag
if: ${{github.event.inputs.with_tag}}
run: |
npm publish ./dist/uid2-npm --tag ${{github.event.inputs.with_tag}} --access public
npm publish ./dist/euid-npm --tag ${{github.event.inputs.with_tag}} --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
cdn-deployment-uid2:
if: inputs.publish_to_cdn
needs: [build, incrementVersionNumber]
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
environment: [integ, production]
environment: ${{ matrix.environment }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
- uses: ./.github/actions/cdn_deployment_aws
with:
environment: ${{ matrix.environment }}
artifact: uid2SDK-${{ (matrix.environment == 'integ' && 'development') || matrix.environment }}-${{ needs.build.outputs.sdkVersion}}
invalidate_paths: '/uid2-sdk-${{ needs.build.outputs.sdkVersion}}.js'
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }}
aws_bucket_name: ${{ vars.S3_BUCKET }}
aws_distribution_id: ${{ secrets.AWS_DISTRIBUTION_ID }}
cdn-deployment-euid:
if: inputs.publish_to_cdn
needs: [build, incrementVersionNumber]
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
environment: [integ, production]
environment: ${{ matrix.environment }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.incrementVersionNumber.outputs.git_tag_or_hash }}
- uses: ./.github/actions/cdn_deployment_aws
with:
environment: ${{ matrix.environment }}
artifact: euidSDK-${{ (matrix.environment == 'integ' && 'development') || matrix.environment }}-${{ needs.build.outputs.sdkVersion}}
invalidate_paths: '/euid-sdk-${{ needs.build.outputs.sdkVersion}}.js'
aws_account_id: ${{ vars.EUID_AWS_ACCOUNT_ID }}
aws_bucket_name: ${{ vars.EUID_S3_BUCKET }}
aws_distribution_id: ${{ secrets.EUID_AWS_DISTRIBUTION_ID }}