Skip to content

ci(pie-monorepo): DSW-000 add dummy changes #2

ci(pie-monorepo): DSW-000 add dummy changes

ci(pie-monorepo): DSW-000 add dummy changes #2

name: Amplify Deploy
on:
workflow_call:
inputs:
os:
required: true
type: string
node-version:
required: true
type: string
amplify-app-id:
description: "The ID for your Amplify app (which you can get from the end of its ARN)"
required: true
type: string
package-name:
description: "Name of the application being deployed"
required: true
type: string
package-dist-directory:
description: "The directory where the package dist is located"
required: true
type: string
bucket-name-preview:
description: "Name of the preview bucket being deployed to"
required: false
type: string
bucket-name-main:
description: "Name of the main bucket being deployed to"
required: true
type: string
build-script:
required: false
type: string
default: 'build'
env:
AMPLIFY_ID: ${{ inputs.amplify-app-id }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'eu-west-1'
BRANCH_NAME: ${{ github.event_name == 'pull_request' && format('pr{0}', github.event.number) || (github.ref == 'refs/heads/main' && 'main' || github.ref == 'refs/heads/master' && 'master') }}
BUCKET_NAME: ${{ github.event_name == 'pull_request' && inputs.bucket-name-preview || (github.ref == 'refs/heads/main' && inputs.bucket-name-main || github.ref == 'refs/heads/master' && inputs.bucket-name-main) }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
ZIP_NAME: ${{ github.event_name == 'pull_request' && format('{0}-{1}-preview.zip', inputs.package-name, github.event.number) || (github.ref == 'refs/heads/main' && format('{0}-main.zip', inputs.package-name) || github.ref == 'refs/heads/master' && format('{0}-master.zip', inputs.package-name)) }}
jobs:
deploy:
runs-on: ${{ inputs.os }}
steps:
# Checkout the Repo
- name: Checkout
uses: actions/checkout@v3
# Setup Repo
- name: Setup Repo
uses: ./.github/actions/setup-repo
with:
node-version: ${{ inputs.node-version }}
os: ${{ inputs.os }}
# Build
- name: Build ${{ inputs.package-name }}
uses: ./.github/actions/run-script
with:
script-name: "${{inputs.build-script }} --filter=${{ inputs.package-name }}"
# Create Github Deployment
- name: Create Docs GitHub deployment
if: ${{ github.event_name == 'pull_request' }}
uses: chrnorm/deployment-action@v2
id: deploy
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment: "${{ inputs.package-name}}-pr-${{ github.event.number }}"
# Zip dist folder
- name: Zip build output
shell: bash
run: |
cd ${{ inputs.package-dist-directory }}
zip -r ./${{ env.ZIP_NAME }} .
# Upload zip to S3
- name: Upload to S3
id: upload-s3
uses: hkusu/s3-upload-action@v2
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
aws-bucket: ${{ env.BUCKET_NAME }}
bucket-root: "/"
destination-dir: "/"
file-path: "${{inputs.package-dist-directory}}/${{ env.ZIP_NAME }}"
content-type: "application/zip"
public: true
# Create branch on Amplify
- name: Create Amplify branch
shell: bash
# We return true to prevent the step from failing if the branch already exists
run: |
aws amplify create-branch \
--app-id ${{ inputs.amplify-app-id }} \
--branch-name ${{ env.BRANCH_NAME }} \
|| true
# Deploy Amplify from S3
- name: Deploy Amplify from S3
shell: bash
run: |
aws amplify start-deployment \
--app-id ${{ inputs.amplify-app-id }} \
--branch-name ${{ env.BRANCH_NAME }} \
--source-url https://${{ env.BUCKET_NAME }}.s3.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ZIP_NAME }}
# Set env vars for domain name association
- name: Set environment variables for domain name association
if: github.event_name == 'pull_request'
run: |
PACKAGE_NAME_SUFFIX=$(echo "${{ inputs.package-name }}" | sed -e 's/^pie-//')
echo "SUB_DOMAIN=pr${{ github.event.number }}-$PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
- name: get existing domain associations
if: github.event_name == 'pull_request'
run: |
DOMAIN_ASSOCIATIONS=$(aws amplify get-domain-association \
--app-id ${{ inputs.amplify-app-id }} \
--domain-name pie.design \
| jq '
[.domainAssociation.subDomains[].subDomainSetting | { prefix: (.prefix // ""), branchName }] |
. |= (map(.branchName) | index("pr${{ github.event.number }}")) as $ix |
if $ix == null then
. + [{branchName: "pr${{ github.event.number }}", prefix: "${{ env.SUB_DOMAIN }}"}]
else . end
' -c)
echo "DOMAIN_ASSOCIATIONS=$DOMAIN_ASSOCIATIONS" >> $GITHUB_ENV
- name: Create Subdomain Association
if: github.event_name == 'pull_request'
shell: bash
run: |
aws amplify update-domain-association \
--app-id ${{inputs.amplify-app-id}} \
--domain-name pie.design \
--sub-domain-settings '${{ env.DOMAIN_ASSOCIATIONS }}'
# If successful
- name: Update deployment status (success)
if: ${{ github.event_name == 'pull_request' && success() }}
uses: chrnorm/deployment-status@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment-url: https://${{ env.SUB_DOMAIN }}.pie.design/
deployment-id: ${{ steps.deploy.outputs.deployment_id }}
state: "success"
- name: Comment PR with QR Code
if: ${{ github.event_name == 'pull_request' && success() }}
uses: siggerzz/QR-Code-Commenter-Action
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
links: "https://${{ env.SUB_DOMAIN }}.pie.design/"
messages: ":phone: - Scan the QR Code to view the ${{ inputs.package-name}} preview deployment on your mobile!"
# If it failed
- name: Update deployment status (failure)
if: ${{ github.event_name == 'pull_request' && failure() }}
uses: chrnorm/deployment-status@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
environment-url: https://${{ env.SUB_DOMAIN }}.pie.design/
deployment-id: ${{ steps.deploy.outputs.deployment_id }}
state: "failure"