From b8d0af8033e86b152ef5270a44736f6271c047ea Mon Sep 17 00:00:00 2001 From: qui-pham <100757140+qui-pham@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:23:18 +0700 Subject: [PATCH 1/5] chore(ci): change condition to trigger workflows --- .github/workflows/merge-release-to-network.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/merge-release-to-network.yml b/.github/workflows/merge-release-to-network.yml index ae436a9e..11f64456 100644 --- a/.github/workflows/merge-release-to-network.yml +++ b/.github/workflows/merge-release-to-network.yml @@ -1,13 +1,15 @@ name: Merge release to network on: - push: + pull_request: branches: - - 'release/*' + - release/* + types: + - closed env: HEAD_BRANCH: ${{ github.head_ref || github.ref_name }} - + RELEASE_BRANCH: ${{ github.event.pull_request.base.ref}} permissions: contents: write pull-requests: write @@ -15,13 +17,13 @@ permissions: jobs: merge-release-to-network: runs-on: ubuntu-latest - if: ${{ contains(github.head_ref, 'release') }} || ${{ contains(github.ref_name, 'release') }} + if: (github.event.pull_request.merged == true) && (${{ contains(github.head_ref, 'deploy') }}) steps: - name: Set Env run: | echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV - echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/release\///' | cut -d'-' -f1)" >> $GITHUB_ENV - echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/release\/v[0-9\.]*-\(.*\)/\1/')" >> $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: Set Mainnet Tag if: ${{ env.NETWORK == 'mainnet' }} @@ -51,7 +53,7 @@ jobs: delete-branch: true title: 'chore(`${{ env.NETWORK }}`): merge from `${{ env.HEAD_BRANCH}}`' body: ${{ steps.template.outputs.result }} - branch: ${{env.PR_BRANCH}} + branch: ${{ env.PR_BRANCH }} - name: Auto Merge id: automerge From 5578e4b2a2582d14055e5e2b311098a5033d6a16 Mon Sep 17 00:00:00 2001 From: qui-pham Date: Thu, 4 Jan 2024 17:49:30 +0700 Subject: [PATCH 2/5] chore: fix condition --- .github/workflows/merge-release-to-network.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/merge-release-to-network.yml b/.github/workflows/merge-release-to-network.yml index 11f64456..cf1d0b9b 100644 --- a/.github/workflows/merge-release-to-network.yml +++ b/.github/workflows/merge-release-to-network.yml @@ -17,7 +17,7 @@ permissions: jobs: merge-release-to-network: runs-on: ubuntu-latest - if: (github.event.pull_request.merged == true) && (${{ contains(github.head_ref, 'deploy') }}) + if: ${{ github.event.pull_request.merged == true && (contains(github.head_ref, 'deploy') || contains(github.ref_name, 'deploy')) }} steps: - name: Set Env run: | From ab4fa1f5336ee25aafc8e0de709db1a071bccdb9 Mon Sep 17 00:00:00 2001 From: qui-pham Date: Thu, 4 Jan 2024 17:57:41 +0700 Subject: [PATCH 3/5] chore: trigger CI --- .github/workflows/merge-release-to-network.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/merge-release-to-network.yml b/.github/workflows/merge-release-to-network.yml index cf1d0b9b..e9ab115d 100644 --- a/.github/workflows/merge-release-to-network.yml +++ b/.github/workflows/merge-release-to-network.yml @@ -73,3 +73,5 @@ jobs: --repo="$GITHUB_REPOSITORY" \ --title="${{ env.NETWORK }} - ${{ env.VERSION }}" \ --generate-notes + + From 451c8b9e9dbe151b2b8f72c02019b0a1c37d3302 Mon Sep 17 00:00:00 2001 From: qui-pham <100757140+qui-pham@users.noreply.github.com> Date: Thu, 4 Jan 2024 17:58:36 +0700 Subject: [PATCH 4/5] Update merge-release-to-network.yml --- .github/workflows/merge-release-to-network.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/merge-release-to-network.yml b/.github/workflows/merge-release-to-network.yml index e9ab115d..a370b362 100644 --- a/.github/workflows/merge-release-to-network.yml +++ b/.github/workflows/merge-release-to-network.yml @@ -74,4 +74,3 @@ jobs: --title="${{ env.NETWORK }} - ${{ env.VERSION }}" \ --generate-notes - From 42afc5b37dbe213096685a5749c7a6b066cbb7a7 Mon Sep 17 00:00:00 2001 From: qui-pham Date: Fri, 5 Jan 2024 08:48:41 +0700 Subject: [PATCH 5/5] chore: add workflow automate create from deploy to release --- .../workflows/create-PR-deploy-to-feature.yml | 87 +++++++++++++++++++ .../workflows/create-PR-deploy-to-release.yml | 42 +++++++++ .../workflows/merge-release-to-network.yml | 5 +- 3 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/create-PR-deploy-to-feature.yml create mode 100644 .github/workflows/create-PR-deploy-to-release.yml diff --git a/.github/workflows/create-PR-deploy-to-feature.yml b/.github/workflows/create-PR-deploy-to-feature.yml new file mode 100644 index 00000000..88c6c7f3 --- /dev/null +++ b/.github/workflows/create-PR-deploy-to-feature.yml @@ -0,0 +1,87 @@ +name: Create Pull Request From Deploy to Feature +on: + push: + branches: + - 'deploy/*' + +permissions: + contents: write + pull-requests: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} + cancel-in-progress: true + +env: + HEAD_BRANCH: ${{ github.head_ref || github.ref_name }} + +jobs: + fetchAllFeatureBranches: + runs-on: ubuntu-latest + + steps: + - 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}-${{matrix.branch_name}}" >> $GITHUB_ENV + echo "FEATURE_NAME=$(echo ${{matrix.branch_name}} | cut -d'/' -f2)" >> $GITHUB_ENV + - uses: actions/checkout@v3 + with: + ref: ${{matrix.branch_name}} + - 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: ${{matrix.branch_name}} + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v5 + with: + labels: automated PR + delete-branch: true + 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-PR-deploy-to-release.yml b/.github/workflows/create-PR-deploy-to-release.yml new file mode 100644 index 00000000..867381b2 --- /dev/null +++ b/.github/workflows/create-PR-deploy-to-release.yml @@ -0,0 +1,42 @@ +name: Create PR Deploy to Release + +on: + push: + 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 }}' + + - name: Reset promotion branch + run: | + git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH} + git reset --hard ${HEAD_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(`release/${{ env.VERSION }}`): merge from `${{ env.HEAD_BRANCH}}`' + body: ${{ steps.template.outputs.result }} + branch: ${{ env.PR_BRANCH }} diff --git a/.github/workflows/merge-release-to-network.yml b/.github/workflows/merge-release-to-network.yml index cf1d0b9b..b63d7e2f 100644 --- a/.github/workflows/merge-release-to-network.yml +++ b/.github/workflows/merge-release-to-network.yml @@ -22,8 +22,8 @@ jobs: - 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 + 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: Set Mainnet Tag if: ${{ env.NETWORK == 'mainnet' }} @@ -72,4 +72,5 @@ jobs: gh release create "$tag" \ --repo="$GITHUB_REPOSITORY" \ --title="${{ env.NETWORK }} - ${{ env.VERSION }}" \ + --notes-start-tag="v0.3.2-testnet" \ --generate-notes