diff --git a/.github/actions/alpha/action.yaml b/.github/actions/alpha/action.yaml new file mode 100644 index 00000000..ffbc4cff --- /dev/null +++ b/.github/actions/alpha/action.yaml @@ -0,0 +1,31 @@ +name: alpha-cicd-trigger-by-comment + +inputs: + app-name: + description: 'app name' + required: true + +runs: + using: composite + steps: + - name: Install & build + shell: bash + run: | + node .release/scripts/install.js + + node common/scripts/install-run-rush.js install -t @bnb-chain/$APP_NAME + node common/scripts/install-run-rush.js build -t @bnb-chain/$APP_NAME + env: + APP_NAME: ${{inputs.app-name}} + + - 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/actions/gh-pages/action.yaml b/.github/actions/gh-pages/action.yaml new file mode 100644 index 00000000..019fb084 --- /dev/null +++ b/.github/actions/gh-pages/action.yaml @@ -0,0 +1,46 @@ +name: github-pages-cicd + +runs: + using: composite + steps: + - name: Creating .env + shell: bash + run: | + cat << EOF > "./apps/canonical-bridge-ui/.env" + NEXT_PUBLIC_APP_NAME=$APP_NAME + NEXT_PUBLIC_BASE_PATH=$BASE_PATH + NEXT_PUBLIC_ASSET_PREFIX=$ASSET_PREFIX + NEXT_PUBLIC_SERVER_ENDPOINT=$SERVER_ENDPOINT + NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID + EOF + env: + APP_NAME: canonical-bridge + BASE_PATH: /canonical-bridge + ASSET_PREFIX: /canonical-bridge + SERVER_ENDPOINT: ${{ vars.SERVER_ENDPOINT }} + WALLET_CONNECT_PROJECT_ID: ${{ vars.WALLET_CONNECT_PROJECT_ID }} + + - name: Install & build + shell: bash + run: | + node common/scripts/install-run-rush.js install -t @bnb-chain/canonical-bridge-ui + node common/scripts/install-run-rush.js build -t @bnb-chain/canonical-bridge-ui + + - name: Pushes to another repository + uses: cpina/github-action-push-to-another-repository@main + env: + API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} + with: + source-directory: './apps/canonical-bridge-ui/dist' + destination-github-username: 'wenty22' + 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/actions/setup/action.yaml b/.github/actions/setup/action.yaml index f32de174..fc887bdb 100644 --- a/.github/actions/setup/action.yaml +++ b/.github/actions/setup/action.yaml @@ -1,11 +1,6 @@ name: 'setup' description: Prepare the environment -inputs: - npm-token: - description: 'npm token' - required: false - runs: using: composite steps: @@ -33,11 +28,10 @@ runs: 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 }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/alpha-sdk.yaml b/.github/workflows/alpha-sdk.yaml deleted file mode 100644 index fdef34e8..00000000 --- a/.github/workflows/alpha-sdk.yaml +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index f3c9cf1a..00000000 --- a/.github/workflows/alpha-widget.yaml +++ /dev/null @@ -1,12 +0,0 @@ -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/gh-pages.yaml b/.github/workflows/gh-pages.yaml deleted file mode 100644 index 0ba91e90..00000000 --- a/.github/workflows/gh-pages.yaml +++ /dev/null @@ -1,100 +0,0 @@ -name: github-pages-cicd - -on: - issue_comment: - types: [created] - -jobs: - 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: - - 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 - - - name: Creating .env - shell: bash - run: | - cat << EOF > "./apps/canonical-bridge-ui/.env" - NEXT_PUBLIC_APP_NAME=$APP_NAME - NEXT_PUBLIC_BASE_PATH=$BASE_PATH - NEXT_PUBLIC_ASSET_PREFIX=$ASSET_PREFIX - NEXT_PUBLIC_SERVER_ENDPOINT=$SERVER_ENDPOINT - NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=$WALLET_CONNECT_PROJECT_ID - EOF - env: - APP_NAME: canonical-bridge - BASE_PATH: /canonical-bridge - ASSET_PREFIX: /canonical-bridge - SERVER_ENDPOINT: ${{ vars.SERVER_ENDPOINT }} - WALLET_CONNECT_PROJECT_ID: ${{ vars.WALLET_CONNECT_PROJECT_ID }} - - - name: Install & build - shell: bash - run: | - 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: Pushes to another repository - uses: cpina/github-action-push-to-another-repository@main - env: - API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} - with: - source-directory: './apps/canonical-bridge-ui/dist' - destination-github-username: 'wenty22' - 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/alpha.yaml b/.github/workflows/qa-deploy.yaml similarity index 61% rename from .github/workflows/alpha.yaml rename to .github/workflows/qa-deploy.yaml index f94ffeda..97680bfa 100644 --- a/.github/workflows/alpha.yaml +++ b/.github/workflows/qa-deploy.yaml @@ -1,18 +1,13 @@ -name: alpha-cicd-trigger-by-comment +name: cicd-trigger-by-comment on: - workflow_call: - inputs: - package-name: - description: 'package name' - type: string - required: true - default: '' + issue_comment: + types: [created] jobs: pre-check: runs-on: ubuntu-latest - if: github.repository == 'bnb-chain/canonical-bridge' && contains(github.event.comment.body, '/qa-deploy:${{inputs.package-name}}') + if: github.repository == 'bnb-chain/canonical-bridge' && contains(github.event.comment.body, '/qa-deploy') outputs: codeowners: ${{ steps.codeowners.outputs.content }} steps: @@ -54,6 +49,15 @@ jobs: BRANCH_NAME=${{ fromJSON(steps.get-pr.outputs.result).head.ref }} echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT + - name: get comment + id: get-comment + run: | + #!/bin/bash + input_comment="${{ github.event.comment.body }}" + comment_format=${input_comment// /} + APP_NAME=${comment_format#*:} + echo "APP_NAME=${APP_NAME}" >> $GITHUB_OUTPUT + - name: Checkout code repository uses: actions/checkout@v4 with: @@ -61,28 +65,19 @@ jobs: 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: Deploy github pages + if: contains(steps.get-comment.outputs.APP_NAME, 'canonical-bridge-ui') + uses: ./.github/actions/gh-pages - - name: Enter pre mode - run: pnpm ci:enter + - name: Deploy SDK + if: contains(steps.get-comment.outputs.APP_NAME, 'canonical-bridge-sdk') + uses: ./.github/actions/alpha + with: + app-name: ${{steps.get-comment.outputs.APP_NAME}} - - name: Create and publish versions - uses: changesets/action@v1 + - name: Deploy Widget + if: contains(steps.get-comment.outputs.APP_NAME, 'canonical-bridge-widget') + uses: ./.github/actions/alpha 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 }} + app-name: ${{steps.get-comment.outputs.APP_NAME}} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 17ea2668..a312dc86 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,7 +13,7 @@ on: jobs: pre-check: runs-on: ubuntu-latest - if: github.repository == 'bnb-chain/canonical-bridge' && contains(github.event.comment.body, '/qa-deploy:${{inputs.package-name}}') + if: github.repository == 'bnb-chain/canonical-bridge' outputs: codeowners: ${{ steps.codeowners.outputs.content }} steps: @@ -28,18 +28,14 @@ jobs: cicd: needs: [pre-check] - if: contains(needs.pre-check.outputs.codeowners, github.event.comment.user.login) + if: contains(needs.pre-check.outputs.codeowners, github.event.pull_request.user.login) timeout-minutes: 10 runs-on: ubuntu-latest steps: - name: Checkout code repository uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/setup - with: - npm-token: ${{ secrets.NPM_TOKEN }} - name: Install & build shell: bash