-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (84 loc) · 4.69 KB
/
go-pr-to-boarding.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#########################
## Open PR to Boarding ##
#########################
on:
workflow_call:
inputs:
board_tag:
type: string
description: 'Tag to trigger the Boarding PR. Example: board-request, board-n-release'
required: true
main_branch:
default: 'main'
type: string
description: 'Name of the Main Branch. Example: main, master'
required: false
secrets:
github_pat:
description: 'GitHub Token, with permissions to create PRs and push to the repository'
required: true
jobs:
boarding_area:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags and branches
set-safe-directory: '' # `git config --global --add safe.directory <path>`
token: '${{ secrets.github_pat }}' # PAT with permissions to create PRs
# Find Upstream Branch, pointing to the same commit as the Pushed Tag
- name: Discover User's Branch Name
id: user_branch
run: |
name=$(git branch -a --contains "$(git rev-parse HEAD)" | sed -n '2p' | sed 's/.*origin\///')
echo "NAME:" $name
echo USER_BRANCH=$name >> $GITHUB_OUTPUT
- name: "Exit Job, if User Branch is empty: '${{ steps.user_branch.outputs.USER_BRANCH }}'"
if: steps.user_branch.outputs.USER_BRANCH == ''
run: echo "[ERROR] User Branch not found. Searched for an Upstream branch, but was not found on the remote. Exiting.." && exit 1
- name: 'Derive name for Boarding target PR (aka base) branch: ${{ inputs.board_tag }}-${{ steps.user_branch.outputs.USER_BRANCH }}'
run: echo "BOARDING_BR=${{ inputs.board_tag }}-${{ steps.user_branch.outputs.USER_BRANCH }}" >> $GITHUB_ENV
# Ensure Upstream 'Boarding' Branch exists
- name: Track '${{ env.BOARDING_BR }}' Branch, if it exists on remote 'origin'
run: git branch --track ${{ env.BOARDING_BR }} "origin/${{ env.BOARDING_BR }}" || echo PREEXISTING_BOARDING=false >> $GITHUB_ENV
- name: Create '${{ env.BOARDING_BR }}' branch, if it doesn't exist
if: env.PREEXISTING_BOARDING == 'false'
run: |
git branch --track "${{ inputs.main_branch }}" "origin/${{ inputs.main_branch }}"
git checkout -b "${{ env.BOARDING_BR }}" "${{ inputs.main_branch }}" || true
git push origin "${{ env.BOARDING_BR }}" || true
# Close PR, if found already open
- name: Close PR, if already open
env:
GITHUB_TOKEN: ${{ secrets.github_pat }}
run: |
pr_id=$(gh pr list --state open --head "${{ steps.user_branch.outputs.USER_BRANCH }}" --base "${{ env.BOARDING_BR }}" --json number | jq -r '.[0].number')
if [ -n "$pr_id" ] && [ "$pr_id" != "null" ]; then
gh pr close $pr_id -c "Closing PR, as a new PR is being opened for the same User Branch"
fi
############## PR ##############
- name: 'Open PR ${{ steps.user_branch.outputs.USER_BRANCH }} --> ${{ env.BOARDING_BR }}, to classify file changes'
env:
GITHUB_TOKEN: ${{ secrets.github_pat }}
run: |
gh pr create --head "${{ steps.user_branch.outputs.USER_BRANCH }}" --base "${{ env.BOARDING_BR }}" \
--title "Boarding Area: Merging '${{ steps.user_branch.outputs.USER_BRANCH }}' into '${{ env.BOARDING_BR }}' Branch" \
--body "## :train: Boarding Area :train:
This PR is automatically generated by a GitHub Action workflow. It's part of the process of putting changes onto the **Boarding Auto** branch, setting the stage for the next steps in our GitOps journey.
### What's Happening Here?
- We're merging changes from `${{ steps.user_branch.outputs.USER_BRANCH }}` into the `${{ env.BOARDING_BR }}` branch.
- The PR is automatically labeled and classified, to help us understand the nature of the changes.
- The labels applied to this PR, signal what Automated Tests to run as Check before Mering into the Release Train.
### Type of Changes
- Source Distribution
- Documentation
### :white_check_mark: Automatic Merging :white_check_mark:
- This PR is designed to **automatically merge** once all CI checks pass.
"
# - name: 'Catch Error, if PR already exists'
# if: ${{ failure() }}
# run: |
# echo "[WARNING] PR already exists. Skipping PR creation, making sure Job is green"
# echo "## :warning: PR already exists :warning:" >> $GITHUB_STEP_SUMMARY
# echo "" >> $GITHUB_STEP_SUMMARY
# echo "This PR already exists. Skipping PR creation, making sure Job is green" >> $GITHUB_STEP_SUMMARY