|
| 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 | + |
| 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}} |
0 commit comments