Skip to content

Commit

Permalink
#d7 ci updateed again
Browse files Browse the repository at this point in the history
  • Loading branch information
AarooneyFarr committed Oct 30, 2024
1 parent 5afe8f4 commit 763f756
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
name: CI Pipeline

on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
name: Build
name: Build frontend
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_version.outputs.version }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: set version
id: set_version
run: |
echo "version=$(date +'%Y%m%d.%H%M%S')" >> "$GITHUB_OUTPUT"
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: set version
id: set_version
run: |
version=$(date +'%Y%m%d.%H%M%S')
echo "version=$version" >> "$GITHUB_OUTPUT"
printf '{"version": "%s" }' "$version" > public/version.json
- name: Build
run: |
printf '{"version": "%s" }' ${{steps.set_version.outputs.version}} > public/version.json
npm ci && npm run build
- name: Update dist artifact
uses: actions/upload-artifact@v4
with:
name: package
path: dist/

- name: Run tests
run: |
npx playwright install --with-deps chromium
Expand All @@ -53,16 +45,21 @@ jobs:
git commit -m "generated"
git push
- name: Update pages artifact
uses: actions/upload-artifact@v4
with:
name: package
path: dist/
deploy:
needs: build
permissions:
id-token: write
runs-on: ubuntu-latest
env:
version: ${{needs.build.outputs.version}}
environment:
name: staging
url: https://stage-pizza.trakkup.com
env:
version: ${{needs.build.outputs.version}}
steps:
- name: Create OIDC token to AWS
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -71,26 +68,25 @@ jobs:
aws-region: us-east-1
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/${{ secrets.CI_IAM_ROLE }}

- name: Download build artifact
- name: Download pages artifact
uses: actions/download-artifact@v4
with:
name: package
path: dist/

- name: Push to AWS S3
run: |
echo Deploying $version
aws s3 cp dist s3://${{ secrets.APP_BUCKET }}/$version --recursive
- name: Update staging version
- name: Update the cloudfront distribution
run: |
# Get the current distribution and update it to use the new version
aws cloudfront get-distribution-config --id ${{ secrets.DISTRIBUTION_ID }} > original.json
etag=$(jq -r '.ETag' original.json)
jq '.DistributionConfig' original.json > request.json
jq --arg version "/$version" '.Origins.Items[0].OriginPath = $version' request.json > finalRequest.json
aws cloudfront update-distribution --id ${{ secrets.DISTRIBUTION_ID }} --if-match $etag --distribution-config file://finalRequest.json
aws cloudfront update-distribution --id ${{ secrets.DISTRIBUTION_ID }} --if-match $etag --distribution-config file://finalRequest.json
# Wait for the distribution to deploy and then invalidate the cache
while [ "$(aws cloudfront get-distribution --id ${{ secrets.DISTRIBUTION_ID }} --query 'Distribution.Status' --output text)" != "Deployed" ]; do echo "Distribution is still updating..."; sleep 5; done
aws cloudfront create-invalidation --distribution-id ${{ secrets.DISTRIBUTION_ID }} --paths "/*"
Expand All @@ -100,16 +96,17 @@ jobs:
- build
- deploy
runs-on: ubuntu-latest
env:
version: ${{needs.build.outputs.version}}
steps:
- name: Create Release
- name: Create staging release
uses: ncipollo/release-action@v1
env:
version: ${{needs.build.outputs.version}}
with:
tag: version-${{ env.version }}
name: Version ${{ env.version }}
tag: stage-version-${{ env.version }}
name: Staging ${{ env.version }}
generateReleaseNotes: true
body: |
## 🚀 Changes
## Description
${{ github.event.head_commit.message }}
Expand Down

0 comments on commit 763f756

Please sign in to comment.