From 913a44297cbfc5d274b0b955975ee701912583c8 Mon Sep 17 00:00:00 2001 From: huyhuynh3103 Date: Wed, 17 Jan 2024 10:45:25 +0700 Subject: [PATCH] chore: add ci scripts --- .../workflows/create-PR-deploy-to-release.yml | 64 +++++ .github/workflows/create-PR-implement.yml | 1 - .../create-PR-release-to-network.yml | 47 ++++ .github/workflows/create-PR-release.yml | 241 +++--------------- .github/workflows/create-release-tag.yml | 64 +++++ .github/workflows/{unittest.yml => test.yml} | 22 +- 6 files changed, 225 insertions(+), 214 deletions(-) create mode 100644 .github/workflows/create-PR-deploy-to-release.yml create mode 100644 .github/workflows/create-PR-release-to-network.yml create mode 100644 .github/workflows/create-release-tag.yml rename .github/workflows/{unittest.yml => test.yml} (60%) diff --git a/.github/workflows/create-PR-deploy-to-release.yml b/.github/workflows/create-PR-deploy-to-release.yml new file mode 100644 index 000000000..bf1c04bed --- /dev/null +++ b/.github/workflows/create-PR-deploy-to-release.yml @@ -0,0 +1,64 @@ +name: Create PR Deploy to Release + +on: + push: + branches: + - deploy/* + pull_request: + types: + - opened + branches: + - 'deploy/**' + +env: + HEAD_BRANCH: ${{ github.head_ref || github.ref_name }} + +permissions: + contents: write + pull-requests: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Set Env + run: | + echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV + echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV + echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV + - name: Checkout code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: 'release/${{ env.VERSION }}' + fetch-depth: 0 + fetch-tags: 'true' + + - name: Get Testnet Latest Tag + if: ${{ env.NETWORK == 'testnet' }} + run: | + echo "LATESTTAG=$(git describe --tags --match "*testnet*" --abbrev=0)" >> $GITHUB_ENV + + - name: Get Mainnet Latest Tag + if: ${{ env.NETWORK == 'mainnet' }} + run: | + echo "LATESTTAG=$(git describe --tags --match "*mainnet*" --abbrev=0)" >> $GITHUB_ENV + + - name: Reset promotion branch + run: | + git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} + git reset --hard ${HEAD_BRANCH} + + - name: Generate Release note + id: template + run: | + echo "VERSION=${{ env.VERSION }} - SHA: ${{ github.sha }}" > CHANGELOG.md + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 #v5.0.2 + with: + labels: automated PR + delete-branch: true + title: 'chore(`release/${{ env.VERSION }}`): merge from `${{ env.HEAD_BRANCH}}`' + body: ${{ steps.template.outputs.result }} + branch: ${{ env.PR_BRANCH }} diff --git a/.github/workflows/create-PR-implement.yml b/.github/workflows/create-PR-implement.yml index 606a47697..33d00a598 100644 --- a/.github/workflows/create-PR-implement.yml +++ b/.github/workflows/create-PR-implement.yml @@ -46,6 +46,5 @@ jobs: branch: ${{ env.HEAD_BRANCH }} base: ${{env.FEATURE_BRANCH}} labels: automated PR - team-reviewers: axieinfinity/smart-contract title: 'feat(${{env.FEATURE_NAME}}): implement `${{env.IMPLEMENT_NAME}}`' body: ${{ steps.template.outputs.result }} \ No newline at end of file diff --git a/.github/workflows/create-PR-release-to-network.yml b/.github/workflows/create-PR-release-to-network.yml new file mode 100644 index 000000000..bd52ca2ec --- /dev/null +++ b/.github/workflows/create-PR-release-to-network.yml @@ -0,0 +1,47 @@ +name: Create PR from release to network + +on: + pull_request: + branches: + - release/* + types: + - closed + +permissions: + contents: write + pull-requests: write + +env: + HEAD_BRANCH: ${{ github.head_ref || github.ref_name }} + RELEASE_BRANCH: ${{ github.event.pull_request.base.ref}} + +jobs: + merge-release-to-network: + runs-on: ubuntu-latest + if: ${{ (github.event.pull_request.merged == true) && (contains(github.head_ref, 'deploy') || contains(github.ref_name, 'deploy')) }} + steps: + - name: Set Env + run: | + echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV + echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV + echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV + + - name: Checkout code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ env.NETWORK }} + + - name: Reset promotion branch + run: | + git fetch origin ${RELEASE_BRANCH}:${RELEASE_BRANCH} + git reset --hard ${RELEASE_BRANCH} + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 #v5.0.2 + with: + labels: automated PR + delete-branch: true + title: 'chore(`${{ env.NETWORK }}`): merge from `${{ env.HEAD_BRANCH}}`' + body: ${{ steps.template.outputs.result }} + branch: ${{env.PR_BRANCH}} diff --git a/.github/workflows/create-PR-release.yml b/.github/workflows/create-PR-release.yml index b40cfd565..87944c64f 100644 --- a/.github/workflows/create-PR-release.yml +++ b/.github/workflows/create-PR-release.yml @@ -13,213 +13,53 @@ env: HEAD_BRANCH: ${{ github.head_ref || github.ref_name }} jobs: - mergeRelease2FeatureRnsUnified: + fetchAllFeatureBranches: runs-on: ubuntu-latest - steps: - - name: Set env - run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/rns-unified" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: feature/rns-unified - - name: Reset promotion branch - run: | - git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} - git reset --hard ${HEAD_BRANCH} - - - name: Render template - id: template - uses: chuhlomin/render-template@v1.4 - with: - template: .github/template/create-pull-request.md - vars: | - fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/rns-unified - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - labels: automated PR - team-reviewers: axieinfinity/smart-contract - delete-branch: true - title: 'chore(rns-unified): merge from `${{env.HEAD_BRANCH}}`' - body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} - - mergeRelease2FeatureController: - runs-on: ubuntu-latest - steps: - - name: Set env - run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/controller" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: feature/controller - - name: Reset promotion branch - run: | - git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} - git reset --hard ${HEAD_BRANCH} - - - name: Render template - id: template - uses: chuhlomin/render-template@v1.4 - with: - template: .github/template/create-pull-request.md - vars: | - fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/controller - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - labels: automated PR - team-reviewers: axieinfinity/smart-contract - delete-branch: true - title: 'chore(controller): merge from `${{env.HEAD_BRANCH}}`' - body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} - - mergeRelease2FeatureDomainPrice: - runs-on: ubuntu-latest - steps: - - name: Set env - run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/domain-price" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: feature/domain-price - - name: Reset promotion branch - run: | - git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} - git reset --hard ${HEAD_BRANCH} - - - name: Render template - id: template - uses: chuhlomin/render-template@v1.4 - with: - template: .github/template/create-pull-request.md - vars: | - fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/domain-price - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - labels: automated PR - team-reviewers: axieinfinity/smart-contract - delete-branch: true - title: 'chore(domain-price): merge from `${{env.HEAD_BRANCH}}`' - body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} - mergeRelease2FeatureAuction: - runs-on: ubuntu-latest steps: - - name: Set env - run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/auction" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: feature/auction - - name: Reset promotion branch - run: | - git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} - git reset --hard ${HEAD_BRANCH} - - - name: Render template - id: template - uses: chuhlomin/render-template@v1.4 - with: - template: .github/template/create-pull-request.md - vars: | - fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/auction - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - labels: automated PR - team-reviewers: axieinfinity/smart-contract - delete-branch: true - title: 'chore(auction): merge from `${{env.HEAD_BRANCH}}`' - body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} - - mergeRelease2FeaturePublicResolver: - runs-on: ubuntu-latest - steps: - - name: Set env - run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/public-resolver" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: feature/public-resolver - - name: Reset promotion branch - run: | - git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} - git reset --hard ${HEAD_BRANCH} - - - name: Render template - id: template - uses: chuhlomin/render-template@v1.4 - with: - template: .github/template/create-pull-request.md - vars: | - fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/public-resolver - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - labels: automated PR - team-reviewers: axieinfinity/smart-contract - delete-branch: true - title: 'chore(public-resolver): merge from `${{env.HEAD_BRANCH}}`' - body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} - - mergeRelease2FeatureCI: - runs-on: ubuntu-latest - steps: - - name: Set env - run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/ci" >> $GITHUB_ENV - - uses: actions/checkout@v3 - with: - ref: feature/ci - - name: Reset promotion branch - run: | - git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} - git reset --hard ${HEAD_BRANCH} - - - name: Render template - id: template - uses: chuhlomin/render-template@v1.4 - with: - template: .github/template/create-pull-request.md - vars: | - fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/ci - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v5 - with: - labels: automated PR - team-reviewers: axieinfinity/smart-contract - delete-branch: true - title: 'chore(ci): merge from `${{env.HEAD_BRANCH}}`' - body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} - - mergeRelease2FeatureReverseRegistrar: + - id: step1 + name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - id: step2 + name: List all the remote feature branches + run: | + branches=$(git branch -r | grep -E '.*origin\/feature\/.*' | sed -e "s/.*origin\///" | tr "\n" " ") + JSON="[" + for branch in ${branches[@]}; do + echo $branch + JSONline="\"$branch\"," + # we don't need to iterate on the same branch over and over, so + # onnly include it when it wasn't included + if [[ "$JSON" != *"$JSONline"* ]]; then + JSON="$JSON$JSONline" + fi + done + # Remove last "," and add the closing bracket + if [[ $JSON == *, ]]; then + JSON="${JSON%?}" + fi + JSON="$JSON]" + echo $JSON + echo "BRANCHES={\"branch_name\": $( echo "$JSON" )}" >> "$GITHUB_OUTPUT" + outputs: + BRANCHES: ${{ steps.step2.outputs.BRANCHES }} + + mergeRelease2FeatureRepo: runs-on: ubuntu-latest + needs: fetchAllFeatureBranches + strategy: + matrix: ${{ fromJSON(needs.fetchAllFeatureBranches.outputs.BRANCHES) }} steps: - name: Set env run: | - echo "PR_BRANCH=merge/${HEAD_BRANCH}-feature/reverse-registrar" >> $GITHUB_ENV + echo "PR_BRANCH=merge/${HEAD_BRANCH}-${{matrix.branch_name}}" >> $GITHUB_ENV + echo "FEATURE_NAME=$(echo ${{matrix.branch_name}} | cut -d'/' -f2)" >> $GITHUB_ENV - uses: actions/checkout@v3 with: - ref: feature/reverse-registrar + ref: ${{matrix.branch_name}} - name: Reset promotion branch run: | git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} @@ -232,14 +72,13 @@ jobs: template: .github/template/create-pull-request.md vars: | fromBranch: ${{env.HEAD_BRANCH}} - toBranch: feature/reverse-registrar + toBranch: ${{matrix.branch_name}} - name: Create Pull Request uses: peter-evans/create-pull-request@v5 with: labels: automated PR - team-reviewers: axieinfinity/smart-contract delete-branch: true - title: 'chore(reverse-registrar): merge from `${{env.HEAD_BRANCH}}`' + title: 'chore(`${{env.FEATURE_NAME}}`): merge from `${{env.HEAD_BRANCH}}`' body: ${{ steps.template.outputs.result }} branch: ${{env.PR_BRANCH}} diff --git a/.github/workflows/create-release-tag.yml b/.github/workflows/create-release-tag.yml new file mode 100644 index 000000000..23a41c24d --- /dev/null +++ b/.github/workflows/create-release-tag.yml @@ -0,0 +1,64 @@ +name: Create Release Tag + +on: + pull_request: + types: [closed] + branches: + - mainnet + - testnet + +env: + HEAD_BRANCH: ${{ github.head_ref || github.ref_name }} + +permissions: + contents: write + pull-requests: write + +jobs: + create-release-tag: + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true + steps: + - name: Set Env + run: | + echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV + echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV + + - name: Checkout code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + ref: ${{ env.NETWORK }} + fetch-depth: 0 + fetch-tags: 'true' + + - name: Set Mainnet Tag + if: ${{ env.NETWORK == 'mainnet' }} + run: | + echo "TAG=${{ env.VERSION }}" >> $GITHUB_ENV + + - name: Set Testnet Tag + if: ${{ env.NETWORK == 'testnet' }} + run: | + echo "TAG=${{ env.VERSION }}-testnet" >> $GITHUB_ENV + + - name: Get Testnet Latest Tag + if: ${{ env.NETWORK == 'testnet' }} + run: | + echo "LATESTTAG=$(git describe --tags --match "*testnet*" --abbrev=0)" >> $GITHUB_ENV + + - name: Get Mainnet Latest Tag + if: ${{ env.NETWORK == 'mainnet' }} + run: | + echo "LATESTTAG=$(git describe --tags --match "*mainnet*" --abbrev=0)" >> $GITHUB_ENV + + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.TAG }} + run: | + gh release create "$tag" \ + --repo "$GITHUB_REPOSITORY" \ + --title "${{ env.NETWORK }} release ${{ env.VERSION }}" \ + --target "${{ env.NETWORK }}" \ + --notes-start-tag "${{ env.LATESTTAG }}" \ + --generate-notes \ No newline at end of file diff --git a/.github/workflows/unittest.yml b/.github/workflows/test.yml similarity index 60% rename from .github/workflows/unittest.yml rename to .github/workflows/test.yml index 6e82e46f0..ad49e528b 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,5 @@ -name: Run tests +name: test + on: push: branches: @@ -13,13 +14,8 @@ on: - 'feature/*' - 'features/*' -permissions: - contents: read - packages: read - -concurrency: - group: ${{ github.head_ref || github.run_id }} - cancel-in-progress: true +env: + FOUNDRY_PROFILE: ci jobs: check: @@ -29,20 +25,22 @@ jobs: name: Foundry project runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 with: submodules: recursive - name: Install Foundry - uses: foundry-rs/foundry-toolchain@cb603ca0abb544f301eaed59ac0baf579aa6aecf #v1.0.10 + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly - name: Run Forge build run: | forge --version - forge build --names + forge build id: build - name: Run Forge tests run: | - forge test --no-match-path '*forking/*' -vvv + forge test -vvv id: test