From 50507901a865d36f61dec2b46ac57140a3ab8612 Mon Sep 17 00:00:00 2001 From: wenty22 Date: Tue, 29 Oct 2024 13:59:19 +0800 Subject: [PATCH] chore: Update cicd --- .github/actions/alpha/action.yaml | 41 ----------- .github/actions/gh-pages/action.yaml | 57 --------------- .github/actions/server/action.yaml | 45 ------------ .github/workflows/demo.yaml | 56 +++++++++++++++ .github/workflows/qa-deploy.yaml | 100 -------------------------- .github/workflows/release-server.yaml | 42 ----------- .github/workflows/release.yaml | 42 ++++++----- .github/workflows/server.yaml | 52 ++++++++++++++ 8 files changed, 128 insertions(+), 307 deletions(-) delete mode 100644 .github/actions/alpha/action.yaml delete mode 100644 .github/actions/gh-pages/action.yaml delete mode 100644 .github/actions/server/action.yaml create mode 100644 .github/workflows/demo.yaml delete mode 100644 .github/workflows/qa-deploy.yaml delete mode 100644 .github/workflows/release-server.yaml create mode 100644 .github/workflows/server.yaml diff --git a/.github/actions/alpha/action.yaml b/.github/actions/alpha/action.yaml deleted file mode 100644 index 63bad07e..00000000 --- a/.github/actions/alpha/action.yaml +++ /dev/null @@ -1,41 +0,0 @@ -name: alpha - -inputs: - app-name: - description: 'app name' - required: true - npm-token: - description: 'npm token' - required: true - github-token: - description: 'github token' - required: true - branch: - description: 'branch' - 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' - branch: ${{ inputs.branch }} - env: - GITHUB_TOKEN: ${{ inputs.github-token }} - NPM_TOKEN: ${{ inputs.npm-token }} diff --git a/.github/actions/gh-pages/action.yaml b/.github/actions/gh-pages/action.yaml deleted file mode 100644 index 88f95169..00000000 --- a/.github/actions/gh-pages/action.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: github-pages - -inputs: - server-endpoint: - description: 'server endpoint' - required: true - wallet-connect-project-id: - description: 'wallet connect project id' - required: true - api-token-github: - description: 'api token github' - required: true - -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: ${{ inputs.server-endpoint }} - WALLET_CONNECT_PROJECT_ID: ${{ inputs.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: ${{ inputs.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/server/action.yaml b/.github/actions/server/action.yaml deleted file mode 100644 index 428ce6ac..00000000 --- a/.github/actions/server/action.yaml +++ /dev/null @@ -1,45 +0,0 @@ -name: server - -inputs: - username: - description: 'username' - required: true - github-token: - description: 'github token' - required: true - -runs: - using: composite - steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ inputs.username }} - password: ${{ inputs.github-token }} - - - name: image meta - id: meta - uses: docker/metadata-action@v5 - with: - images: | - ghcr.io/${{ inputs.username }}/canonical-bridge-server - tags: | - type=ref,event=branch - type=ref,event=tag - type=semver,pattern={{version}} - type=sha - - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - file: ./apps/canonical-bridge-server/Dockerfile - push: true - provenance: false - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/demo.yaml b/.github/workflows/demo.yaml new file mode 100644 index 00000000..bc17d094 --- /dev/null +++ b/.github/workflows/demo.yaml @@ -0,0 +1,56 @@ +name: Release demo + +on: + push: + branches: [demo] + paths: + - .github/** + - apps/canonical-bridge-ui/** + - packages/canonical-bridge-sdk/** + - packages/canonical-bridge-widget/** + +jobs: + cicd: + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - name: Checkout code repository + uses: actions/checkout@v4 + + - uses: ./.github/actions/setup + with: + npm-token: ${{ secrets.NPM_TOKEN }} + + - 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 diff --git a/.github/workflows/qa-deploy.yaml b/.github/workflows/qa-deploy.yaml deleted file mode 100644 index 7c105162..00000000 --- a/.github/workflows/qa-deploy.yaml +++ /dev/null @@ -1,100 +0,0 @@ -name: cicd-trigger-by-comment - -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') - 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: 30 - 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: | - #!/bin/bash - input_comment="${{ github.event.comment.body }}" - comment_format=${input_comment// /} - APP_NAME=${comment_format#*:} - echo "APP_NAME=${APP_NAME}" >> $GITHUB_OUTPUT - - 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 }} - fetch-depth: 0 - - - uses: ./.github/actions/setup - with: - npm-token: ${{ secrets.NPM_TOKEN }} - - - name: Deploy github pages - if: contains(steps.pr-env.outputs.APP_NAME, 'canonical-bridge-ui') - uses: ./.github/actions/gh-pages - with: - server-endpoint: ${{ vars.SERVER_ENDPOINT }} - wallet-connect-project-id: ${{ vars.WALLET_CONNECT_PROJECT_ID }} - api-token-github: ${{ secrets.API_TOKEN_GITHUB }} - - - name: Create server docker - if: contains(steps.pr-env.outputs.APP_NAME, 'canonical-bridge-server') - uses: ./.github/actions/server - with: - username: ${{ github.repository_owner }} - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish sdk - if: contains(steps.pr-env.outputs.APP_NAME, 'canonical-bridge-sdk') - uses: ./.github/actions/alpha - with: - app-name: ${{steps.pr-env.outputs.APP_NAME}} - npm-token: ${{ secrets.NPM_TOKEN }} - github-token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ steps.pr-env.outputs.BRANCH_NAME }} - - - name: Publish widget - if: contains(steps.pr-env.outputs.APP_NAME, 'canonical-bridge-widget') - uses: ./.github/actions/alpha - with: - app-name: ${{steps.pr-env.outputs.APP_NAME}} - npm-token: ${{ secrets.NPM_TOKEN }} - github-token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ steps.pr-env.outputs.BRANCH_NAME }} diff --git a/.github/workflows/release-server.yaml b/.github/workflows/release-server.yaml deleted file mode 100644 index a966cab6..00000000 --- a/.github/workflows/release-server.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: Release server - -on: - pull_request: - types: - - closed - branches: - - main - paths: - - apps/canonical-bridge-server/** - -jobs: - pre-check: - runs-on: ubuntu-latest - if: github.repository == 'bnb-chain/canonical-bridge' - 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.pull_request.merged_by.login) - timeout-minutes: 30 - runs-on: ubuntu-latest - - steps: - - name: Checkout code repository - uses: actions/checkout@v4 - - - name: Create server docker - uses: ./.github/actions/server - with: - username: ${{ github.repository_owner }} - github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9ca3173e..c35398f1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,35 +1,19 @@ name: Release on: - pull_request: - types: - - closed + push: branches: - main + - alpha + paths: + - .github/** - .release/** - packages/canonical-bridge-sdk/** - packages/canonical-bridge-widget/** jobs: - pre-check: - runs-on: ubuntu-latest - if: github.repository == 'bnb-chain/canonical-bridge' - 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.pull_request.merged_by.login) timeout-minutes: 30 runs-on: ubuntu-latest steps: @@ -41,7 +25,6 @@ jobs: npm-token: ${{ secrets.NPM_TOKEN }} - name: Install & build - shell: bash run: | node .release/scripts/install.js @@ -51,10 +34,25 @@ jobs: node common/scripts/install-run-rush.js install -t @bnb-chain/canonical-bridge-widget node common/scripts/install-run-rush.js build -t @bnb-chain/canonical-bridge-widget + - name: Get branch name + id: get-branch + run: | + echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + + - name: Enter pre mode + if: steps.get-branch.outputs.branch == 'alpha' + run: | + pnpm ci:enter + + - name: Exit pre mode + if: steps.get-branch.outputs.branch == 'main' + run: | + pnpm ci:exit + - name: Create and publish versions uses: changesets/action@v1 with: - version: pnpm ci:stable-version + version: pnpm ci:version publish: pnpm ci:publish commit: 'chore: Update versions' title: 'chore: Update versions' diff --git a/.github/workflows/server.yaml b/.github/workflows/server.yaml new file mode 100644 index 00000000..71fa12b2 --- /dev/null +++ b/.github/workflows/server.yaml @@ -0,0 +1,52 @@ +name: Build server docker + +on: + push: + branches: + - main + + paths: + - .github/** + - apps/canonical-bridge-server/** + +jobs: + cicd: + timeout-minutes: 30 + runs-on: ubuntu-latest + + steps: + - name: Checkout code repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: image meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ghcr.io/${{ github.repository_owner }}/canonical-bridge-server + tags: | + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=sha + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./apps/canonical-bridge-server/Dockerfile + push: true + provenance: false + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64