Skip to content

Commit

Permalink
Merge pull request #30 from bnb-chain/fix/cicd
Browse files Browse the repository at this point in the history
chore: Add code owners
  • Loading branch information
wenty22 authored Oct 21, 2024
2 parents 9fa4a8a + 287927d commit 1a9acaf
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @aiden-cao @wenty22 @Halibao-Lala @doge95
15 changes: 15 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: 'setup'
description: Prepare the environment

inputs:
npm-token:
description: 'npm token'
required: false

runs:
using: composite
steps:
Expand All @@ -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 }}
12 changes: 12 additions & 0 deletions .github/workflows/alpha-sdk.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions .github/workflows/alpha-widget.yaml
Original file line number Diff line number Diff line change
@@ -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
88 changes: 88 additions & 0 deletions .github/workflows/alpha.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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: |
Expand All @@ -73,23 +71,15 @@ 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
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: 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:
Expand All @@ -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
35 changes: 24 additions & 11 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 1a9acaf

Please sign in to comment.