Skip to content

Commit 42afc5b

Browse files
committed
chore: add workflow automate create from deploy to release
1 parent 5200ca5 commit 42afc5b

File tree

3 files changed

+132
-2
lines changed

3 files changed

+132
-2
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Create Pull Request From Deploy to Feature
2+
on:
3+
push:
4+
branches:
5+
- 'deploy/*'
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
13+
cancel-in-progress: true
14+
15+
env:
16+
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}
17+
18+
jobs:
19+
fetchAllFeatureBranches:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- id: step1
24+
name: Checkout code
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- id: step2
30+
name: List all the remote feature branches
31+
run: |
32+
branches=$(git branch -r | grep -E '.*origin\/feature\/.*' | sed -e "s/.*origin\///" | tr "\n" " ")
33+
JSON="["
34+
for branch in ${branches[@]}; do
35+
echo $branch
36+
JSONline="\"$branch\","
37+
# we don't need to iterate on the same branch over and over, so
38+
# onnly include it when it wasn't included
39+
if [[ "$JSON" != *"$JSONline"* ]]; then
40+
JSON="$JSON$JSONline"
41+
fi
42+
done
43+
# Remove last "," and add the closing bracket
44+
if [[ $JSON == *, ]]; then
45+
JSON="${JSON%?}"
46+
fi
47+
JSON="$JSON]"
48+
echo $JSON
49+
echo "BRANCHES={\"branch_name\": $( echo "$JSON" )}" >> "$GITHUB_OUTPUT"
50+
outputs:
51+
BRANCHES: ${{ steps.step2.outputs.BRANCHES }}
52+
53+
mergeRelease2FeatureRepo:
54+
runs-on: ubuntu-latest
55+
needs: fetchAllFeatureBranches
56+
strategy:
57+
matrix: ${{ fromJSON(needs.fetchAllFeatureBranches.outputs.BRANCHES) }}
58+
steps:
59+
- name: Set env
60+
run: |
61+
echo "PR_BRANCH=merge/${HEAD_BRANCH}-${{matrix.branch_name}}" >> $GITHUB_ENV
62+
echo "FEATURE_NAME=$(echo ${{matrix.branch_name}} | cut -d'/' -f2)" >> $GITHUB_ENV
63+
- uses: actions/checkout@v3
64+
with:
65+
ref: ${{matrix.branch_name}}
66+
- name: Reset promotion branch
67+
run: |
68+
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
69+
git reset --hard ${HEAD_BRANCH}
70+
71+
- name: Render template
72+
id: template
73+
uses: chuhlomin/[email protected]
74+
with:
75+
template: .github/template/create-pull-request.md
76+
vars: |
77+
fromBranch: ${{env.HEAD_BRANCH}}
78+
toBranch: ${{matrix.branch_name}}
79+
80+
- name: Create Pull Request
81+
uses: peter-evans/create-pull-request@v5
82+
with:
83+
labels: automated PR
84+
delete-branch: true
85+
title: 'chore(`${{env.FEATURE_NAME}}`): merge from `${{env.HEAD_BRANCH}}`'
86+
body: ${{ steps.template.outputs.result }}
87+
branch: ${{env.PR_BRANCH}}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Create PR Deploy to Release
2+
3+
on:
4+
push:
5+
branches:
6+
- deploy/*
7+
8+
env:
9+
HEAD_BRANCH: ${{ github.head_ref || github.ref_name }}
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Set Env
20+
run: |
21+
echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV
22+
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
23+
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
24+
- name: Checkout code
25+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
26+
with:
27+
ref: 'release/${{ env.VERSION }}'
28+
29+
- name: Reset promotion branch
30+
run: |
31+
git fetch origin ${HEAD_BRANCH}:${HEAD_BRANCH}
32+
git reset --hard ${HEAD_BRANCH}
33+
34+
- name: Create Pull Request
35+
id: cpr
36+
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 #v5.0.2
37+
with:
38+
labels: automated PR
39+
delete-branch: true
40+
title: 'chore(`release/${{ env.VERSION }}`): merge from `${{ env.HEAD_BRANCH}}`'
41+
body: ${{ steps.template.outputs.result }}
42+
branch: ${{ env.PR_BRANCH }}

.github/workflows/merge-release-to-network.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
- name: Set Env
2323
run: |
2424
echo "PR_BRANCH=merge/${HEAD_BRANCH}" >> $GITHUB_ENV
25-
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
26-
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
25+
echo "VERSION=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\///' | cut -d'-' -f1)" >> $GITHUB_ENV
26+
echo "NETWORK=$(echo -n ${{ env.HEAD_BRANCH }} | sed 's/.*deploy\/v[0-9\.]*-\(.*\)/\1/')" >> $GITHUB_ENV
2727
2828
- name: Set Mainnet Tag
2929
if: ${{ env.NETWORK == 'mainnet' }}
@@ -72,4 +72,5 @@ jobs:
7272
gh release create "$tag" \
7373
--repo="$GITHUB_REPOSITORY" \
7474
--title="${{ env.NETWORK }} - ${{ env.VERSION }}" \
75+
--notes-start-tag="v0.3.2-testnet" \
7576
--generate-notes

0 commit comments

Comments
 (0)