From fecbf541d74e4d2be1d5fe11acd9ec4283e0b06f Mon Sep 17 00:00:00 2001 From: Florin Dzeladini Date: Mon, 25 Nov 2024 21:09:38 +0100 Subject: [PATCH 1/5] chore: ci-cd pipeline split --- .../workflows/deploy-wallet-get-starknet.yml | 90 ++++++++++++++++++- .github/workflows/publish-npm.yml | 33 ++++++- 2 files changed, 121 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-wallet-get-starknet.yml b/.github/workflows/deploy-wallet-get-starknet.yml index 7300d2b4..9ae20fcc 100644 --- a/.github/workflows/deploy-wallet-get-starknet.yml +++ b/.github/workflows/deploy-wallet-get-starknet.yml @@ -79,4 +79,92 @@ 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 + 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..0699ccb2 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -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 }} From 62c0a25afa490d6cd8aa98e7a4a0d766d0668af4 Mon Sep 17 00:00:00 2001 From: Florin Dzeladini Date: Mon, 25 Nov 2024 21:18:41 +0100 Subject: [PATCH 2/5] chore: ci-cd dev pipeline for test --- .../workflows/deploy-wallet-get-starknet.yml | 35 ++++++++++++---- .github/workflows/publish-npm.yml | 40 ++++++++++++++----- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/.github/workflows/deploy-wallet-get-starknet.yml b/.github/workflows/deploy-wallet-get-starknet.yml index 9ae20fcc..0ca3d57f 100644 --- a/.github/workflows/deploy-wallet-get-starknet.yml +++ b/.github/workflows/deploy-wallet-get-starknet.yml @@ -2,9 +2,15 @@ name: Deploy Wallet-UI and Get-starknet on: workflow_dispatch: + inputs: + environment: + description: 'Environment to deploy' + type: environment + required: true + jobs: prepare-deployment: - environment: production + environment: dev permissions: contents: write runs-on: ubuntu-latest @@ -19,22 +25,34 @@ jobs: - name: Prepare Parameters id: prepare_parameters run: | + ENV=${{ inputs.environment }} BASE=$(node -p "require('./packages/starknet-snap/package.json').version") - ENV=production - { 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" + + if [[ $ENV == "dev" ]]; then + HASH=$(git rev-parse --short HEAD) + DATE=$(date +%Y%m%d) + { + echo "VERSION=${BASE}-dev-${HASH}-${DATE}" + echo "ENV=dev" + } >> "$GITHUB_OUTPUT" + elif [[ $ENV == "production" ]]; then + { + echo "VERSION=${BASE}" + echo "ENV=prod" + } >> "$GITHUB_OUTPUT" + else + echo "Invalid environment" + exit 1 + fi 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 +85,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 }} @@ -85,6 +103,7 @@ jobs: runs-on: ubuntu-latest needs: - prepare-deployment + - install-build steps: - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index 0699ccb2..de72db32 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -2,9 +2,15 @@ name: Publish NPM on: workflow_dispatch: + inputs: + environment: + description: 'Environment to deploy' + type: environment + required: true + jobs: prepare-deployment: - environment: production + environment: dev permissions: contents: write runs-on: ubuntu-latest @@ -19,16 +25,30 @@ jobs: - name: Prepare Parameters id: prepare_parameters run: | + ENV=${{ inputs.environment }} BASE=$(node -p "require('./packages/starknet-snap/package.json').version") - ENV=production - - { - echo "VERSION=${BASE}" - echo "TAG=latest" - echo "ENV=prod" - echo "LOG_LEVEL=0" - } >> "$GITHUB_OUTPUT" - + if [[ $ENV == "dev" ]]; then + HASH=$(git rev-parse --short HEAD) + DATE=$(date +%Y%m%d) + { + echo "VERSION=${BASE}-dev-${HASH}-${DATE}" + echo "TAG=dev" + echo "ENV=dev" + echo "LOG_LEVEL=6" + } >> "$GITHUB_OUTPUT" + elif [[ $ENV == "production" ]]; then + { + echo "VERSION=${BASE}" + echo "TAG=latest" + echo "ENV=prod" + echo "LOG_LEVEL=0" + } >> "$GITHUB_OUTPUT" + else + echo "Invalid environment" + exit 1 + fi + + echo $GITHUB_OUTPUT outputs: VERSION: ${{ steps.prepare_parameters.outputs.VERSION }} TAG: ${{ steps.prepare_parameters.outputs.TAG }} From 120dfd61d2ae829c38b9693dda43d034ca8b73a3 Mon Sep 17 00:00:00 2001 From: Florin Dzeladini Date: Tue, 26 Nov 2024 01:01:24 +0100 Subject: [PATCH 3/5] chore: fix lint --- .github/workflows/deploy-wallet-get-starknet.yml | 2 +- .github/workflows/publish-npm.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-wallet-get-starknet.yml b/.github/workflows/deploy-wallet-get-starknet.yml index 0ca3d57f..5e19fbee 100644 --- a/.github/workflows/deploy-wallet-get-starknet.yml +++ b/.github/workflows/deploy-wallet-get-starknet.yml @@ -25,8 +25,8 @@ jobs: - name: Prepare Parameters id: prepare_parameters run: | - ENV=${{ inputs.environment }} BASE=$(node -p "require('./packages/starknet-snap/package.json').version") + ENV=${{ inputs.environment }} { echo "AWS_CLOUDFRONT_DISTRIBUTIONS_ID=${{ vars.AWS_CLOUDFRONT_DISTRIBUTIONS_ID }}" echo "AWS_S3_GET_STARKNET_URL=${{ vars.AWS_S3_GET_STARKNET_URL }}" diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index de72db32..eefe9b86 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -25,8 +25,8 @@ jobs: - name: Prepare Parameters id: prepare_parameters run: | - ENV=${{ inputs.environment }} BASE=$(node -p "require('./packages/starknet-snap/package.json').version") + ENV=${{ inputs.environment }} if [[ $ENV == "dev" ]]; then HASH=$(git rev-parse --short HEAD) DATE=$(date +%Y%m%d) From d7ab7aa66fa93aa890e6e16aea528a6709d5d0a3 Mon Sep 17 00:00:00 2001 From: Florin Dzeladini Date: Tue, 26 Nov 2024 10:09:18 +0100 Subject: [PATCH 4/5] chore: activate prod build --- .../workflows/deploy-wallet-get-starknet.yml | 28 +++------------ .github/workflows/publish-npm.yml | 36 +++++-------------- 2 files changed, 12 insertions(+), 52 deletions(-) diff --git a/.github/workflows/deploy-wallet-get-starknet.yml b/.github/workflows/deploy-wallet-get-starknet.yml index 5e19fbee..431571e5 100644 --- a/.github/workflows/deploy-wallet-get-starknet.yml +++ b/.github/workflows/deploy-wallet-get-starknet.yml @@ -2,15 +2,10 @@ name: Deploy Wallet-UI and Get-starknet on: workflow_dispatch: - inputs: - environment: - description: 'Environment to deploy' - type: environment - required: true jobs: prepare-deployment: - environment: dev + environment: production permissions: contents: write runs-on: ubuntu-latest @@ -26,30 +21,15 @@ jobs: id: prepare_parameters run: | BASE=$(node -p "require('./packages/starknet-snap/package.json').version") - ENV=${{ inputs.environment }} + { + 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 }}" } >> "$GITHUB_OUTPUT" - - if [[ $ENV == "dev" ]]; then - HASH=$(git rev-parse --short HEAD) - DATE=$(date +%Y%m%d) - { - echo "VERSION=${BASE}-dev-${HASH}-${DATE}" - echo "ENV=dev" - } >> "$GITHUB_OUTPUT" - elif [[ $ENV == "production" ]]; then - { - echo "VERSION=${BASE}" - echo "ENV=prod" - } >> "$GITHUB_OUTPUT" - else - echo "Invalid environment" - exit 1 - fi outputs: VERSION: ${{ steps.prepare_parameters.outputs.VERSION }} TAG: ${{ steps.prepare_parameters.outputs.TAG }} diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index eefe9b86..a0d80a05 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -2,15 +2,10 @@ name: Publish NPM on: workflow_dispatch: - inputs: - environment: - description: 'Environment to deploy' - type: environment - required: true jobs: prepare-deployment: - environment: dev + environment: production permissions: contents: write runs-on: ubuntu-latest @@ -26,29 +21,14 @@ jobs: id: prepare_parameters run: | BASE=$(node -p "require('./packages/starknet-snap/package.json').version") - ENV=${{ inputs.environment }} - if [[ $ENV == "dev" ]]; then - HASH=$(git rev-parse --short HEAD) - DATE=$(date +%Y%m%d) - { - echo "VERSION=${BASE}-dev-${HASH}-${DATE}" - echo "TAG=dev" - echo "ENV=dev" - echo "LOG_LEVEL=6" - } >> "$GITHUB_OUTPUT" - elif [[ $ENV == "production" ]]; then - { - echo "VERSION=${BASE}" - echo "TAG=latest" - echo "ENV=prod" - echo "LOG_LEVEL=0" - } >> "$GITHUB_OUTPUT" - else - echo "Invalid environment" - exit 1 - fi - echo $GITHUB_OUTPUT + { + echo "VERSION=${BASE}" + echo "TAG=latest" + echo "ENV=prod" + echo "LOG_LEVEL=0" + } >> "$GITHUB_OUTPUT" + outputs: VERSION: ${{ steps.prepare_parameters.outputs.VERSION }} TAG: ${{ steps.prepare_parameters.outputs.TAG }} From eaae6e9991171517b748c2ff13cc129dd0027df5 Mon Sep 17 00:00:00 2001 From: Florin Dzeladini Date: Tue, 26 Nov 2024 15:59:51 +0100 Subject: [PATCH 5/5] chore: fix comments --- .github/workflows/deploy-wallet-get-starknet.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-wallet-get-starknet.yml b/.github/workflows/deploy-wallet-get-starknet.yml index 431571e5..84a3a639 100644 --- a/.github/workflows/deploy-wallet-get-starknet.yml +++ b/.github/workflows/deploy-wallet-get-starknet.yml @@ -32,7 +32,6 @@ jobs: } >> "$GITHUB_OUTPUT" outputs: VERSION: ${{ steps.prepare_parameters.outputs.VERSION }} - TAG: ${{ steps.prepare_parameters.outputs.TAG }} 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 }}