Skip to content

Release Workflow

Release Workflow #18

name: Release Workflow
on:
release:
types: [published]
jobs:
#
# Build homepage distribution from source
#
build_homepage:
name: "Build Homepage Distribution"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
#
# Step 1
# Checkout the project's sourcecode
#
- name: Checkout
uses: actions/checkout@v3
#
# Step 2
# Set Node.js version
#
- name: Request Node Version
uses: actions/setup-node@v3
with:
node-version: '16.19.0'
cache: 'npm'
#
# Step 3
#
- name: Initialise NPM
run: npm i
working-directory: homepage
#
# Step 4
#
- name: Build dist folder
run: npm run build
working-directory: homepage
#
# Step 5
# Store homepage distribution workflow artifacts
#
- name: Archive dist artifacts
uses: actions/upload-artifact@v3
with:
name: homepage-dist
path: homepage/dist/
#
# Build CDN Distribution from source
#
build_dist:
name: "Build CDN Distribution"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
#
# Step 1
# Checkout the project's sourcecode
#
- name: Checkout
uses: actions/checkout@v3
#
# Step 2
# Set Node.js version
#
- name: Request Node Version
uses: actions/setup-node@v3
with:
node-version: '16.19.0'
cache: 'npm'
#
# Step 3
#
- name: Initialise NPM
run: npm i
#
# Step 4
#
- name: Build dist folder
run: npm run dist:build:prod
#
# Step 5
# Store CDN distribution workflow artifacts
#
- name: Archive dist artifacts
uses: actions/upload-artifact@v3
with:
name: cdn-dist
path: |
dist/fonts/
dist/icons/
dist/images/
dist/scripts/
dist/static/
dist/stylesheets/
#
# Build Storybook from source
#
build_storybook:
name: "Build Storybook Distribution"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
#
# Step 1
# Checkout the project's sourcecode
#
- name: Checkout
uses: actions/checkout@v3
#
# Step 2
# Set Node.js version
#
- name: Request Node Version
uses: actions/setup-node@v3
with:
node-version: '16.19.0'
cache: 'npm'
#
# Step 3
#
- name: Initialise NPM
run: npm i
#
# Step 4
# Build storybook project
#
- name: Build Storybook
env:
STORYBOOK_VERSION: ${{ github.ref_name }}
run: npm run storybook:build
#
# Step 5
# Store Storybook workflow artifacts
#
- name: Archive storybook artifact
uses: actions/upload-artifact@v3
with:
name: storybook-dist
path: storybook-static/
#
# Build NPM Package from source
#
build_npm_package:
name: "Build NPM Distribution"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
#
# Step 1
# Checkout the project's sourcecode
#
- name: Checkout
uses: actions/checkout@v3
#
# Step 2
# Set Node.js version
#
- name: Request Node Version
uses: actions/setup-node@v3
with:
node-version: '16.19.0'
cache: 'npm'
#
# Step 3
#
- name: Initialise NPM
run: npm i
#
# Step 4
#
- name: Build NPM
run: npm run package:build:prod
#
# Step 5
# Store NPM Package workflow artifacts
#
- name: Archive NPM package artifact
uses: actions/upload-artifact@v3
with:
name: npm-dist
path: |
package/
add_release_assets:
name: "Add release assets"
needs:
- build_homepage
- build_dist
- build_storybook
- build_npm_package
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
#
# Step 0
# Checkout is required for the upload-release-asset action to work.
#
- name: Checkout
uses: actions/checkout@v3
#
# Step 1
#
- name: Download all workflow artifacts
uses: actions/download-artifact@v3
id: download
with:
path: workflow-artifacts
#
# Step 2
#
- name: Read version
id: version
run: |
echo "version=$(cat ${{steps.download.outputs.download-path}}/version/version)" >> $GITHUB_OUTPUT
#
# Step 3
# Zip up each build artifacts with it's version number injected.
#
#
# Step 3.1
#
- name: Zip CDN distribution
run: |
echo ${{ github.ref_name }} > version
zip -r ../cdn-dist.zip .
working-directory: ${{steps.download.outputs.download-path}}/cdn-dist
#
# Step 3.2
#
- name: Zip storybook distribution
run: |
echo ${{ github.ref_name }} > version
zip -r ../storybook.zip .
working-directory: ${{steps.download.outputs.download-path}}/storybook-dist
#
# Step 3.3
#
- name: Zip NPM package distribution
run: |
echo ${{ github.ref_name }} > version
zip -r ../npm-dist.zip .
working-directory: ${{steps.download.outputs.download-path}}/npm-dist
#
# Step 3.4
#
- name: Zip Homepage distribution
run: |
echo ${{ github.ref_name }} > version
zip -r ../homepage-dist.zip .
working-directory: ${{steps.download.outputs.download-path}}/homepage-dist
#
# Step 4
# Add release assets
# - Adds dist, storybook and package to the release
- name: Upload Homepage Dist Zip
uses: ./.github/actions/upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{steps.download.outputs.download-path}}/homepage-dist.zip
asset_name: homepage-dist-${{ github.ref_name }}.zip
asset_content_type: application/zip
- name: Upload CDN Dist Zip
uses: ./.github/actions/upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{steps.download.outputs.download-path}}/cdn-dist.zip
asset_name: cdn-dist-${{ github.ref_name }}.zip
asset_content_type: application/zip
- name: Upload Storybook Zip
uses: ./.github/actions/upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{steps.download.outputs.download-path}}/storybook.zip
asset_name: storybook-dist-${{ github.ref_name }}.zip
asset_content_type: application/zip
- name: Upload NPM Package Zip
uses: ./.github/actions/upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{steps.download.outputs.download-path}}/npm-dist.zip
asset_name: npm-dist-${{ github.ref_name }}.zip
asset_content_type: application/zip
#
# Put CDN distribution artifact onto the S3 origin.
#
dist_cdn:
name: "Distribute CDN"
needs:
- build_dist
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
#
# Step 1
# Download CDN artifact and merge version artifact into the same folder
#
- name: Download CDN artifacts
uses: actions/download-artifact@v3
id: download
with:
name: cdn-dist
path: cdn-dist
#
# Step 2
# Set up AWS CLI
#
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.PIPELINE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIPELINE_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
#
# Step 3
# Replace 'latest' folder's content
#
- name: Replace latest
working-directory: ${{steps.download.outputs.download-path}}
run: aws s3 sync . s3://${{ secrets.S3_ORIGIN }}/cdn/latest --delete
#
# Put the Storybook distribution artifact onto the S3 origin.
#
dist_storybook:
name: "Distribute Storybook"
needs:
- build_storybook
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
#
# Step 1
# Download CDN artifact and merge version artifact into the same folder
#
- name: Download all workflow artifacts
uses: actions/download-artifact@v3
id: download
with:
name: storybook-dist
path: storybook-dist
#
# Step 2
# Set up AWS CLI
#
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.PIPELINE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIPELINE_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
#
# Step 3
# Replace 'latest' folder's content
#
- name: Replace latest
working-directory: ${{steps.download.outputs.download-path}}
run: aws s3 sync . s3://${{ secrets.S3_ORIGIN }}/storybook/latest --delete
#
# Put the homepage distribution artifact onto the S3 origin.
#
dist_homepage:
name: "Distribute Homepage"
needs:
- build_homepage
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
#
# Step 1
# Download CDN artifact and merge version artifact into the same folder
#
- name: Download all workflow artifacts
uses: actions/download-artifact@v3
id: download
with:
name: homepage-dist
path: homepage-dist
- name: Download version artifacts
uses: actions/download-artifact@v3
with:
path: homepage-dist
#
# Step 2
# Set up AWS CLI
#
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.PIPELINE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIPELINE_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
#
# Step 3
# Create versioned release in S3
#
# WARNING BEFORE UPDATING CONFIG
# The sync --delete has the power to remove everything from the bucket. Please try --dryrun before committing an
# update!!!
#
- name: Replace homepage and it's assets
working-directory: ${{steps.download.outputs.download-path}}
run: aws s3 sync . s3://${{ secrets.S3_ORIGIN }}/ --exclude "cdn/*" --exclude "storybook/*" --exclude="error.html" --delete
#
# Clear the CloudFront cache.
#
clear_cache:
name: "Clear CloudFront Cache"
needs:
- dist_homepage
- dist_cdn
- dist_storybook
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
#
# Step 1
# Set up AWS CLI
#
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.PIPELINE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PIPELINE_AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-2
#
# Step 2
# Replace latest and invalid CloudFront's catch of latest
#
- name: Refesh CloudFront Cache
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} --paths "/storybook/latest/*" "/cdn/latest/*" "/index.html"