From 287927dbc014685b507c5245fd4afc69908f87d6 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Mon, 21 Oct 2024 19:00:04 +0800 Subject: [PATCH] chore: Add code owners --- .github/CODEOWNERS | 1 + .github/actions/setup/action.yaml | 15 ++++ .github/workflows/alpha-sdk.yaml | 12 +++ .github/workflows/alpha-widget.yaml | 12 +++ .github/workflows/alpha.yaml | 88 +++++++++++++++++++ .../{gh-pages-cicd.yaml => gh-pages.yaml} | 56 ++++++------ .github/workflows/release.yaml | 35 +++++--- 7 files changed, 179 insertions(+), 40 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/alpha-sdk.yaml create mode 100644 .github/workflows/alpha-widget.yaml create mode 100644 .github/workflows/alpha.yaml rename .github/workflows/{gh-pages-cicd.yaml => gh-pages.yaml} (74%) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..f95c3c63 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @aiden-cao @wenty22 @Halibao-Lala @doge95 \ No newline at end of file diff --git a/.github/actions/setup/action.yaml b/.github/actions/setup/action.yaml index 1b420764..f32de174 100644 --- a/.github/actions/setup/action.yaml +++ b/.github/actions/setup/action.yaml @@ -1,6 +1,11 @@ name: 'setup' description: Prepare the environment +inputs: + npm-token: + description: 'npm token' + required: false + runs: using: composite steps: @@ -26,3 +31,13 @@ runs: path: | common/temp/pnpm-store key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }} + + - name: Creating .npmrc + if: inputs.npm-token != '' + shell: bash + run: | + cat << EOF > "$HOME/.npmrc" + //registry.npmjs.org/:_authToken=$NPM_TOKEN + EOF + env: + NPM_TOKEN: ${{ inputs.npm-token }} diff --git a/.github/workflows/alpha-sdk.yaml b/.github/workflows/alpha-sdk.yaml new file mode 100644 index 00000000..fdef34e8 --- /dev/null +++ b/.github/workflows/alpha-sdk.yaml @@ -0,0 +1,12 @@ +name: sdk-cicd-by-comment + +on: + issue_comment: + types: [created] + +jobs: + alpha-release: + uses: ./.github/workflows/alpha.yaml + secrets: inherit + with: + package-name: canonical-bridge-sdk diff --git a/.github/workflows/alpha-widget.yaml b/.github/workflows/alpha-widget.yaml new file mode 100644 index 00000000..f3c9cf1a --- /dev/null +++ b/.github/workflows/alpha-widget.yaml @@ -0,0 +1,12 @@ +name: widget-cicd-by-comment + +on: + issue_comment: + types: [created] + +jobs: + alpha-release: + uses: ./.github/workflows/alpha.yaml + secrets: inherit + with: + package-name: canonical-bridge-widget diff --git a/.github/workflows/alpha.yaml b/.github/workflows/alpha.yaml new file mode 100644 index 00000000..f94ffeda --- /dev/null +++ b/.github/workflows/alpha.yaml @@ -0,0 +1,88 @@ +name: alpha-cicd-trigger-by-comment + +on: + workflow_call: + inputs: + package-name: + description: 'package name' + type: string + required: true + default: '' + +jobs: + pre-check: + runs-on: ubuntu-latest + if: github.repository == 'bnb-chain/canonical-bridge' && contains(github.event.comment.body, '/qa-deploy:${{inputs.package-name}}') + outputs: + codeowners: ${{ steps.codeowners.outputs.content }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Read codeowners + id: codeowners + uses: juliangruber/read-file-action@v1 + with: + path: .github/CODEOWNERS + + cicd: + needs: [pre-check] + if: contains(needs.pre-check.outputs.codeowners, github.event.comment.user.login) + timeout-minutes: 10 + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v3 + id: get-pr + with: + script: | + const request = { + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number + } + core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`) + try { + const result = await github.pulls.get(request) + return result.data + } catch (err) { + core.setFailed(`Request failed with error ${err}`) + } + + - name: get pr env + id: pr-env + run: | + BRANCH_NAME=${{ fromJSON(steps.get-pr.outputs.result).head.ref }} + echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT + + - name: Checkout code repository + uses: actions/checkout@v4 + with: + ref: ${{ steps.pr-env.outputs.BRANCH_NAME }} + token: ${{ secrets.GITHUB_TOKEN }} + + - uses: ./.github/actions/setup + with: + npm-token: ${{ secrets.NPM_TOKEN }} + + - name: Install & build + shell: bash + run: | + node .release/scripts/install.js + + node common/scripts/install-run-rush.js install -t @bnb-chain/${{inputs.package-name}} + node common/scripts/install-run-rush.js build -t @bnb-chain/${{inputs.package-name}} + + - name: Enter pre mode + run: pnpm ci:enter + + - name: Create and publish versions + uses: changesets/action@v1 + with: + version: pnpm ci:alpha-version + publish: pnpm ci:publish + commit: 'chore: Update versions' + title: 'chore: Update versions' + cwd: '.release' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/gh-pages-cicd.yaml b/.github/workflows/gh-pages.yaml similarity index 74% rename from .github/workflows/gh-pages-cicd.yaml rename to .github/workflows/gh-pages.yaml index 6aae21fe..0ba91e90 100644 --- a/.github/workflows/gh-pages-cicd.yaml +++ b/.github/workflows/gh-pages.yaml @@ -4,13 +4,25 @@ on: issue_comment: types: [created] -env: - SERVER_ENDPOINT: ${{ vars.SERVER_ENDPOINT }} - WALLET_CONNECT_PROJECT_ID: ${{ vars.WALLET_CONNECT_PROJECT_ID }} - jobs: - cicd: + pre-check: + runs-on: ubuntu-latest if: github.repository == 'bnb-chain/canonical-bridge' && contains(github.event.comment.body, '/qa-deploy:canonical-bridge-ui') + outputs: + codeowners: ${{ steps.codeowners.outputs.content }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Read codeowners + id: codeowners + uses: juliangruber/read-file-action@v1 + with: + path: .github/CODEOWNERS + + cicd: + needs: [pre-check] + if: contains(needs.pre-check.outputs.codeowners, github.event.comment.user.login) timeout-minutes: 10 runs-on: ubuntu-latest steps: @@ -34,14 +46,7 @@ jobs: - name: get pr env id: pr-env run: | - GIT_REPOSITORY=${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }} - PR_NUMBER=${{ fromJSON(steps.get-pr.outputs.result).number }} - LATEST_COMMIT_SHA=${{ fromJSON(steps.get-pr.outputs.result).head.sha }} BRANCH_NAME=${{ fromJSON(steps.get-pr.outputs.result).head.ref }} - - echo "GIT_REPOSITORY=${GIT_REPOSITORY}" >> $GITHUB_OUTPUT - echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT - echo "LATEST_COMMIT_SHA=${LATEST_COMMIT_SHA}" >> $GITHUB_OUTPUT echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT - name: Checkout code repository @@ -52,13 +57,6 @@ jobs: - uses: ./.github/actions/setup - - name: Log - run: | - echo "${{steps.pr-env.outputs.BRANCH_NAME}}" - echo "${{steps.pr-env.outputs.GIT_REPOSITORY}}" - echo "${{steps.pr-env.outputs.LATEST_COMMIT_SHA}}" - echo "${{steps.pr-env.outputs.PR_NUMBER}}" - - name: Creating .env shell: bash run: | @@ -73,8 +71,8 @@ jobs: APP_NAME: canonical-bridge BASE_PATH: /canonical-bridge ASSET_PREFIX: /canonical-bridge - SERVER_ENDPOINT: ${{ env.SERVER_ENDPOINT }} - WALLET_CONNECT_PROJECT_ID: ${{ env.WALLET_CONNECT_PROJECT_ID }} + SERVER_ENDPOINT: ${{ vars.SERVER_ENDPOINT }} + WALLET_CONNECT_PROJECT_ID: ${{ vars.WALLET_CONNECT_PROJECT_ID }} - name: Install & build shell: bash @@ -82,14 +80,6 @@ jobs: node common/scripts/install-run-rush.js install -t canonical-bridge-ui node common/scripts/install-run-rush.js build -t canonical-bridge-ui - # - name: Deploy docs - # uses: JamesIves/github-pages-deploy-action@v4 - # with: - # folder: ./apps/canonical-bridge-ui/dist - # branch: 'gh-pages' - # clean: true - # force: true - - name: Pushes to another repository uses: cpina/github-action-push-to-another-repository@main env: @@ -100,3 +90,11 @@ jobs: destination-repository-name: 'canonical-bridge' user-email: github-actions[bot]@users.noreply.github.com target-branch: main + + # - name: Deploy docs + # uses: JamesIves/github-pages-deploy-action@v4 + # with: + # folder: ./apps/canonical-bridge-ui/dist + # branch: 'gh-pages' + # clean: true + # force: true diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 819da099..17ea2668 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,9 +6,29 @@ on: - closed branches: - main + paths: + - packages/canonical-bridge-sdk/** + - packages/canonical-bridge-widget/** + jobs: - release: - if: github.repository == 'bnb-chain/canonical-bridge' + pre-check: + runs-on: ubuntu-latest + if: github.repository == 'bnb-chain/canonical-bridge' && contains(github.event.comment.body, '/qa-deploy:${{inputs.package-name}}') + outputs: + codeowners: ${{ steps.codeowners.outputs.content }} + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Read codeowners + id: codeowners + uses: juliangruber/read-file-action@v1 + with: + path: .github/CODEOWNERS + + cicd: + needs: [pre-check] + if: contains(needs.pre-check.outputs.codeowners, github.event.comment.user.login) timeout-minutes: 10 runs-on: ubuntu-latest steps: @@ -18,15 +38,8 @@ jobs: fetch-depth: 0 - uses: ./.github/actions/setup - - - name: Creating .npmrc - shell: bash - run: | - cat << EOF > "$HOME/.npmrc" - //registry.npmjs.org/:_authToken=$NPM_TOKEN - EOF - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + with: + npm-token: ${{ secrets.NPM_TOKEN }} - name: Install & build shell: bash