From 117517ea922d8a97048ea852aba56c3ab0c4f370 Mon Sep 17 00:00:00 2001 From: Ken Vu Date: Mon, 27 Nov 2023 23:19:30 +1300 Subject: [PATCH 1/3] Update github/workflows with the new release system --- .github/workflows/check-pr.yml | 32 +++++++++++++ .github/workflows/deploy-prod.yml | 80 ------------------------------- .github/workflows/deploy-uat.yml | 55 --------------------- .github/workflows/sync-main.yml | 24 ++++++++++ .prettierignore | 4 +- package.json | 2 +- tools/vercel-build-control.js | 13 +++++ 7 files changed, 73 insertions(+), 137 deletions(-) create mode 100644 .github/workflows/check-pr.yml delete mode 100644 .github/workflows/deploy-prod.yml delete mode 100644 .github/workflows/deploy-uat.yml create mode 100644 .github/workflows/sync-main.yml create mode 100644 tools/vercel-build-control.js diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml new file mode 100644 index 00000000..cc648377 --- /dev/null +++ b/.github/workflows/check-pr.yml @@ -0,0 +1,32 @@ +name: Check | PR + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build: + name: Build and Test + timeout-minutes: 15 + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: lts/hydrogen + - name: Install yarn@3.5.0 + run: | + corepack enable + corepack prepare yarn@3.5.0 --activate + + - name: Install + run: yarn install + + - name: Lint + run: yarn lint diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml deleted file mode 100644 index 25011870..00000000 --- a/.github/workflows/deploy-prod.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Deploy | PROD -run-name: Deploy to `${{ github.event.inputs.branch }}` by @${{ github.actor }} -concurrency: - group: ${{ github.workflow }}-${{ github.event.inputs.branch }} - cancel-in-progress: true -on: - workflow_dispatch: - inputs: - branch: - type: choice - required: true - description: Select a PROD branch - options: ["", "prod/porcini", "prod/mainnet"] - commitSHA: - type: string - required: false - description: "And input a valid commit SHA (40 chars string) to reset the PROD branch to \n(Optional: defaults to latest commit if empty)" - token: - type: string - description: Deploy token, generate one with `repo` permission - required: true -jobs: - deploy_prod_head: - if: github.event.inputs.commitSHA == '' - runs-on: ubuntu-latest - steps: - - name: Checkout and fetch main branch - uses: actions/checkout@v3 - with: - token: ${{github.event.inputs.token}} - ref: ${{github.event.repository.default_branch}} - - - name: Get the commit message - id: step2 - run: | - MSG=$(git log -1 --pretty=format:%s) - echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_OUTPUT - - - name: Check if commit message starts with `Release v` - run: | - echo "commit message: ${{steps.step2.outputs.COMMIT_MESSAGE}}" - [[ "${{steps.step2.outputs.COMMIT_MESSAGE}}" = "Release v"* ]] && exit 0 - - - name: Run the deployment using latest commit from default branch - run: | - echo "Using default branch: ${{github.event.repository.default_branch}}" - git fetch - git checkout ${{github.event.inputs.branch}} - git reset --hard ${{github.event.repository.default_branch}} - git push origin ${{github.event.inputs.branch}} --force-with-lease - - deploy_prod_sha: - if: github.event.inputs.commitSHA != '' - runs-on: ubuntu-latest - steps: - - name: Checkout and fetch using provided commit SHA - uses: actions/checkout@v3 - with: - token: ${{github.event.inputs.token}} - ref: ${{github.event.inputs.commitSHA}} - - - name: Get the commit message - id: step2 - run: | - SHA="${{github.event.inputs.commitSHA}}" - MSG=$(git log -1 --pretty=format:%s $SHA) - echo "COMMIT_MESSAGE=${MSG}" >> $GITHUB_OUTPUT - - - name: Check if commit message starts with `Release v` - run: | - echo "commit message: ${{steps.step2.outputs.COMMIT_MESSAGE}}" - [[ "${{steps.step2.outputs.COMMIT_MESSAGE}}" = "Release v"* ]] && exit 0 - - - name: Run the deployment using provided commit SHA - run: | - echo "Using commit #: ${{github.event.inputs.commitSHA}}" - git fetch - git checkout ${{github.event.inputs.branch}} - git reset --hard ${{github.event.inputs.commitSHA}} - git push origin ${{github.event.inputs.branch}} --force-with-lease diff --git a/.github/workflows/deploy-uat.yml b/.github/workflows/deploy-uat.yml deleted file mode 100644 index 359b43c0..00000000 --- a/.github/workflows/deploy-uat.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Deploy | UAT -run-name: Deploy to `${{ github.event.inputs.branch }}` by @${{ github.actor }} -concurrency: - group: ${{ github.workflow }}-${{ github.event.inputs.branch }} - cancel-in-progress: true -on: - workflow_dispatch: - inputs: - branch: - type: choice - required: true - description: Select a UAT branch - options: ["", "uat/porcini", "uat/mainnet"] - token: - type: string - description: Deploy token, generate one with `repo` permission - required: true - commitSHA: - type: string - required: false - description: "And input a valid commit SHA (40 chars string) to reset the UAT branch to \n(Optional: defaults to latest commit if empty)" -jobs: - deploy_uat_head: - if: github.event.inputs.commitSHA == '' - runs-on: ubuntu-latest - steps: - - name: Checkout and fetch main branch - uses: actions/checkout@v3 - with: - token: ${{github.event.inputs.token}} - ref: ${{github.event.repository.default_branch}} - - name: Run the deployment using latest commit from default branch - run: | - echo "Using default branch: ${{github.event.repository.default_branch}}" - git fetch - git checkout ${{github.event.inputs.branch}} - git reset --hard ${{github.event.repository.default_branch}} - git push origin ${{github.event.inputs.branch}} --force-with-lease - - deploy_uat_sha: - if: github.event.inputs.commitSHA != '' - runs-on: ubuntu-latest - steps: - - name: Checkout and fetch using provided commit SHA - uses: actions/checkout@v3 - with: - token: ${{github.event.inputs.token}} - ref: ${{github.event.inputs.commitSHA}} - - name: Run the deployment using provided commit SHA - run: | - echo "Using commit #: ${{github.event.inputs.commitSHA}}" - git fetch - git checkout ${{github.event.inputs.branch}} - git reset --hard ${{github.event.inputs.commitSHA}} - git push origin ${{github.event.inputs.branch}} --force-with-lease diff --git a/.github/workflows/sync-main.yml b/.github/workflows/sync-main.yml new file mode 100644 index 00000000..dd77c87f --- /dev/null +++ b/.github/workflows/sync-main.yml @@ -0,0 +1,24 @@ +name: Utility | Sync +run-name: Sync `main` branch +on: + push: + branches: ["main"] +jobs: + sync_branch: + runs-on: ubuntu-latest + strategy: + matrix: + branch: + - uat/porcini + - uat/mainnet + - prod/porcini + + steps: + - name: Checkout latest code + uses: actions/checkout@v3 + - name: Sync `main` to `${{ matrix.branch }}` + run: | + git fetch + git checkout ${{ matrix.branch }} + git reset --hard main + git push origin ${{ matrix.branch }} --force-with-lease diff --git a/.prettierignore b/.prettierignore index 049f3da5..7d73cb7f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,4 +1,6 @@ .next yarn.lock node_modules -.yarn \ No newline at end of file +.yarn +.vercel +*.sublime-* \ No newline at end of file diff --git a/package.json b/package.json index 14602d84..cd21d006 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint", + "lint": "prettier --config .prettierrc.js --check . && next lint", "format": "prettier --config .prettierrc.js --write .", "gen": "graphql-codegen --config codegen.yml", "schema": "gq $GRAPHQL_ENDPOINT --introspect > libs/schema.graphql" diff --git a/tools/vercel-build-control.js b/tools/vercel-build-control.js new file mode 100644 index 00000000..8c6f19ca --- /dev/null +++ b/tools/vercel-build-control.js @@ -0,0 +1,13 @@ +const { VERCEL_ENV, VERCEL_GIT_COMMIT_REF, VERCEL_GIT_COMMIT_MESSAGE } = + process.env; + +const isProduction = + VERCEL_ENV === "production" || VERCEL_GIT_COMMIT_REF.indexOf("prod") >= 0; + +const isReleaseCommit = VERCEL_GIT_COMMIT_MESSAGE.indexOf("Release v") >= 0; + +// If deployment is production, build if it's a "release" commit +if (isProduction) process.exit(isReleaseCommit ? 1 : 0); + +// If deployment is not production, build if it's NOT a "release" commit +process.exit(!isReleaseCommit ? 1 : 0); From c136c05a53a2e194989f7421967420c5351e743c Mon Sep 17 00:00:00 2001 From: Ken Vu Date: Mon, 27 Nov 2023 23:19:37 +1300 Subject: [PATCH 2/3] Add details around the deployment --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2c8e7ea..799a2e6e 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,23 @@ yarn && yarn dev - Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +## Deployment + +### UAT Environments + +All commits merged to `main` branch will trigger deployments on Vercel for the following environments: + +- UAT/Porcini: https://trn-block-explorer-porcini.vercel.app +- UAT/Mainnet: https://trn-block-explorer-mainnet.vercel.app + +### PROD Environment + +A commit that starts with `Release v` message will trigger production deployment on Vercel when merge to `main` + +- PROD/Porcini: https://explorer.rootnet.cloud +- PROD/Mainnet: https://explorer.rootnet.live + ## 📥 Provide Feedback - [Start a Discussion](https://github.com/futureversecom/trn-block-explorer/discussions) with a question, piece of feedback, or idea you want to share with the team. -- [Open an Issue](https://github.com/futureversecom/trn-block-explorer/issues) if you believe you've encountered a bug that you want to flag for the team. \ No newline at end of file +- [Open an Issue](https://github.com/futureversecom/trn-block-explorer/issues) if you believe you've encountered a bug that you want to flag for the team. From 81f6a1497d8ffec8de3fb06cbf80e8754c0761bc Mon Sep 17 00:00:00 2001 From: Ken Vu Date: Tue, 28 Nov 2023 09:41:25 +1300 Subject: [PATCH 3/3] Apply prettier to resolve lint issue --- libs/hooks/useStakedBalance.ts | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/libs/hooks/useStakedBalance.ts b/libs/hooks/useStakedBalance.ts index 55f860e2..f73a3cb6 100644 --- a/libs/hooks/useStakedBalance.ts +++ b/libs/hooks/useStakedBalance.ts @@ -32,21 +32,27 @@ export const useStakedBalance = (address: string) => { const subscribeToLedger = async (address: string) => { const bondedAccount = await api.query.staking.bonded(address); - const stakedAccount = bondedAccount.toString() === address ? address : bondedAccount.toString(); - const unsub = await api.query.staking.ledger(stakedAccount, (res: Codec) => { - const ledger = res.toJSON() as unknown as Ledger; - const { total, active } = ledger ?? { total: 0, active: 0 }; - - setStateWithRef( - { - total, - active, - unlocking: total - active, - }, - setBalance, - balanceRef - ); - }); + const stakedAccount = + bondedAccount.toString() === address + ? address + : bondedAccount.toString(); + const unsub = await api.query.staking.ledger( + stakedAccount, + (res: Codec) => { + const ledger = res.toJSON() as unknown as Ledger; + const { total, active } = ledger ?? { total: 0, active: 0 }; + + setStateWithRef( + { + total, + active, + unlocking: total - active, + }, + setBalance, + balanceRef + ); + } + ); setStateWithRef(unsubsRef.current.concat(unsub), setUnsubs, unsubsRef); };