From 4ee8763a81186339f6cb4d10357b5da1e31395b5 Mon Sep 17 00:00:00 2001 From: khanti42 Date: Tue, 26 Nov 2024 16:07:57 +0100 Subject: [PATCH] chore: ci cd split pipeline enabled dev and prod (#438) * chore: ci-cd pipeline split * chore: ci-cd dev pipeline for test * chore: fix lint * chore: activate prod build * chore: fix comments --- .../workflows/deploy-wallet-get-starknet.yml | 104 ++++++++++++++++-- .github/workflows/publish-npm.yml | 37 ++++++- 2 files changed, 129 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-wallet-get-starknet.yml b/.github/workflows/deploy-wallet-get-starknet.yml index 7300d2b4..84a3a639 100644 --- a/.github/workflows/deploy-wallet-get-starknet.yml +++ b/.github/workflows/deploy-wallet-get-starknet.yml @@ -2,6 +2,7 @@ name: Deploy Wallet-UI and Get-starknet on: workflow_dispatch: + jobs: prepare-deployment: environment: production @@ -20,21 +21,17 @@ jobs: id: prepare_parameters run: | BASE=$(node -p "require('./packages/starknet-snap/package.json').version") - ENV=production - + { + echo "VERSION=${BASE}" + echo "ENV=prod" echo "AWS_CLOUDFRONT_DISTRIBUTIONS_ID=${{ vars.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }}" echo "AWS_S3_GET_STARKNET_URL=${{ vars.AWS_S3_GET_STARKNET_URL }}" echo "AWS_S3_URL=${{ vars.AWS_S3_URL }}" echo "GET_STARKNET_PUBLIC_PATH=${{ vars.GET_STARKNET_PUBLIC_PATH }}" - echo "VERSION=${BASE}" - echo "TAG=latest" - echo "ENV=prod" } >> "$GITHUB_OUTPUT" outputs: VERSION: ${{ steps.prepare_parameters.outputs.VERSION }} - TAG: ${{ steps.prepare_parameters.outputs.TAG }} - ENV: ${{ steps.prepare_parameters.outputs.ENV }} AWS_S3_GET_STARKNET_URL: ${{ steps.prepare_parameters.outputs.AWS_S3_GET_STARKNET_URL }} AWS_CLOUDFRONT_DISTRIBUTIONS_ID: ${{ steps.prepare_parameters.outputs.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }} AWS_S3_URL: ${{ steps.prepare_parameters.outputs.AWS_S3_URL }} @@ -67,7 +64,7 @@ jobs: echo "Building Get Starknet with GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH" - SNAP_VERSION="${VERSION}$" GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH yarn workspace @consensys/get-starknet build + SNAP_VERSION="${VERSION}" GET_STARKNET_PUBLIC_PATH=$GET_STARKNET_PUBLIC_PATH yarn workspace @consensys/get-starknet build env: VERSION: ${{ needs.prepare-deployment.outputs.VERSION }} GET_STARKNET_PUBLIC_PATH: ${{ needs.prepare-deployment.outputs.GET_STARKNET_PUBLIC_PATH }} @@ -79,4 +76,93 @@ jobs: ./packages/get-starknet/dist/webpack ./packages/wallet-ui/build ./node_modules/.yarn-state.yml - key: ${{ needs.prepare-deployment.outputs.CACHE_KEY }} \ No newline at end of file + key: ${{ needs.prepare-deployment.outputs.CACHE_KEY }} + + deploy-wallet-ui: + runs-on: ubuntu-latest + needs: + - prepare-deployment + - install-build + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - name: Restore Cached Build + uses: actions/cache@v3 + id: restore-build + with: + path: | + ./packages/get-starknet/dist/webpack + ./packages/wallet-ui/build + ./node_modules/.yarn-state.yml + key: ${{ needs.prepare-deployment.outputs.CACHE_KEY }} + - name: Deploy to AWS + run: | + echo "Deployed Dapp to : $AWS_S3_URL" + aws s3 sync ./packages/wallet-ui/build "$AWS_S3_URL" + env: + AWS_S3_URL: ${{ needs.prepare-deployment.outputs.AWS_S3_URL }} + + deploy-get-starknet: + runs-on: ubuntu-latest + needs: + - prepare-deployment + - install-build + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - name: Restore Cached Build + uses: actions/cache@v3 + id: restore-build + with: + path: | + ./packages/get-starknet/dist/webpack + ./packages/wallet-ui/build + ./node_modules/.yarn-state.yml + key: ${{ needs.prepare-deployment.outputs.CACHE_KEY }} + - name: Deploy to AWS + run: | + echo "Deployed get Starknet to : $AWS_S3_GET_STARKNET_URL" + aws s3 sync ./packages/get-starknet/dist/webpack "$AWS_S3_GET_STARKNET_URL" + env: + AWS_S3_GET_STARKNET_URL: ${{ needs.prepare-deployment.outputs.AWS_S3_GET_STARKNET_URL }} + + invalid-aws-cdn-cache: + runs-on: ubuntu-latest + needs: + - deploy-wallet-ui + - deploy-get-starknet + - prepare-deployment + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: eu-central-1 + - name: Invalid AWS CDN Cache + run: | + echo "Distribution ID : $AWS_CLOUDFRONT_DISTRIBUTIONS_ID" + echo "$AWS_CLOUDFRONT_DISTRIBUTIONS_ID" | tr ',' '\n' | while read -r DISTRIBUTIONS_ID + do + echo "Processing Distribution ID : $DISTRIBUTIONS_ID" + INVALIDED_ID="$(aws cloudfront create-invalidation --distribution-id "$DISTRIBUTIONS_ID" --paths "/starknet/*" | grep Id | awk -F'"' '{ print $4}')" + echo "Waiting for invalidation $INVALIDED_ID" + aws cloudfront wait invalidation-completed --id "$INVALIDED_ID" --distribution-id "$DISTRIBUTIONS_ID" + echo "Invalidation $INVALIDED_ID completed" + done + env: + AWS_CLOUDFRONT_DISTRIBUTIONS_ID: ${{ needs.prepare-deployment.outputs.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }} diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index e58a152b..a0d80a05 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -2,6 +2,7 @@ name: Publish NPM on: workflow_dispatch: + jobs: prepare-deployment: environment: production @@ -20,8 +21,7 @@ jobs: id: prepare_parameters run: | BASE=$(node -p "require('./packages/starknet-snap/package.json').version") - ENV=production - + { echo "VERSION=${BASE}" echo "TAG=latest" @@ -113,4 +113,35 @@ jobs: run: | npm pack ./packages/starknet-snap --tag "$TAG" --access public env: - TAG: ${{ needs.prepare-deployment.outputs.TAG }} \ No newline at end of file + TAG: ${{ needs.prepare-deployment.outputs.TAG }} + + publish-npm: + runs-on: ubuntu-latest + needs: + - publish-npm-dry-run + - prepare-deployment + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.sha }} + - uses: actions/setup-node@v3 + with: + node-version: '20.x' + registry-url: 'https://registry.npmjs.org' + - name: Restore Cached Build + uses: actions/cache@v3 + id: restore-build + with: + # add /packages/snap/snap.manifest.json to include an updated shasum from build due to version update in auto PR + path: | + ./packages/starknet-snap/package.json + ./packages/starknet-snap/dist + ./packages/starknet-snap/snap.manifest.json + ./node_modules/.yarn-state.yml + key: ${{ needs.prepare-deployment.outputs.CACHE_KEY }} + - name: Run Publish + run: | + npm publish ./packages/starknet-snap --tag "$TAG" --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + TAG: ${{ needs.prepare-deployment.outputs.TAG }}