Merge pull request #275 from TokenScript/staging #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Deploy Ecommerce Production | |
#descriptions: Deploys the ecommerce demo to the production environment | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
paths: | |
- "ecommerce-store-website/**" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 16 | |
cache: "npm" | |
cache-dependency-path: ecommerce-store-website/package-lock.json | |
- run: | | |
echo -n "Node version: " | |
node -v | |
echo -n "Npm version: " | |
npm -v | |
- name: building | |
run: | | |
cd ecommerce-store-website | |
npm ci | |
export BASE_PATH=/demo | |
export ANALYTICS_URL=https://analytics-api-stage.smarttokenlabs.com | |
export ANALYTICS_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJicmFuZCI6IkJyYW5kIENvbm5lY3RvciIsImNhbXBhaWduIjoiRGVtbyIsImNsaWVudF9pZCI6IlNUTCIsImlhdCI6MTY4MzE3MDk5Nn0.HhW_sUtU0LKLpK2_puK7pj63CkaXmFa5sJ_wfx1ASR8 | |
npm run build | |
short_sha="${GITHUB_SHA:0:7}" | |
build_version="${GITHUB_REF_NAME}-${short_sha}" | |
build_time="$(date --utc --iso-8601=seconds)" | |
find out/ -name index.html -print0 |\ | |
xargs -0 -r \ | |
sed -i "s/<head>/<head><meta name=\"build-version\" content=\"${build_version}\"><meta name=\"build-time\" content=\"${build_time}\">/" | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: ecommerce-store-website | |
path: ecommerce-store-website/out/ | |
deploy: | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/download-artifact@v3 | |
with: | |
name: ecommerce-store-website | |
path: ecommerce-store-website/out/ | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-west-1 | |
- name: deploy | |
env: | |
S3_BUCKET: brandconnector-ts-site | |
CLOUDFRONT_ID: E3U7RHKWP3P1PT | |
run: | | |
aws s3 sync ecommerce-store-website/out/ "s3://${S3_BUCKET}/demo/" --cache-control 'max-age=31536000' --quiet \ | |
&& aws s3 cp "s3://${S3_BUCKET}/demo/index.html" "s3://${S3_BUCKET}/demo/index.html" --cache-control 'max-age=0,s-maxage=2592000' \ | |
&& aws cloudfront create-invalidation --distribution-id "${CLOUDFRONT_ID}" --paths '/demo/*' |