-
Notifications
You must be signed in to change notification settings - Fork 1
80 lines (72 loc) · 3.15 KB
/
cross-merge.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
name: Ibexa Reusable / Cross Org PR
on:
workflow_call:
secrets:
robot-token:
description: 'A PAT token used by the app/robot'
required: true
jobs:
job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.robot-token }}
- name: Inject slug/short variables
uses: rlespinasse/[email protected]
- name: Get merge map
uses: octokit/[email protected]
id: map
# Allow failures to be ignored.
# We will consider output as empty
continue-on-error: true
with:
owner: ibexa
repo: cross-merge-map
route: /repos/{owner}/{repo}/contents/${{ github.repository }}
env:
GITHUB_TOKEN: ${{ secrets.robot-token }}
# Parse json and find destination branch and repository
- name: Set destination variables
id: destinations
if: ${{ steps.map.outputs.data }}
run: |
cat > input.json <<'EOF'
${{ steps.map.outputs.data }}
EOF
jq -r '.["content"]' input.json | base64 --decode | jq -c . > map.json
echo Looking for destination for branch ${{ env.GITHUB_REF_SLUG }}
branch=$(jq -r '.["${{ env.GITHUB_REF_SLUG }}"] | select (.!=null)' map.json)
echo Destination branch found. It is ${branch}
repo=$(jq -r '.DEST' map.json)
destination=temp_${{ env.GITHUB_REF_SLUG }}_to_$branch
echo "branch=$branch" >> $GITHUB_OUTPUT
echo "repo=$repo" >> $GITHUB_OUTPUT
echo "destination=$destination" >> $GITHUB_OUTPUT
- name: Push updated code to temporary branch
if: ${{ steps.destinations.outputs.branch }}
env:
TOKEN: ${{ secrets.robot-token }}
REPO: ${{ steps.destinations.outputs.repo }}
DEST_BRANCH: ${{ steps.destinations.outputs.destination }}
run: |
git remote add cross https://x-access-token:${{ env.TOKEN }}@github.com/${{ env.REPO }}
# todo: implement generating *unique* temp branch
# todo: check if *previous* temp branch exists
git push cross HEAD:${{ env.DEST_BRANCH }} 2>&1
- name: Create Pull Request in Destination Repository
if: ${{ steps.destinations.outputs.branch }}
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.robot-token }}
REPO: ${{ steps.destinations.outputs.repo }}
DEST_BRANCH: ${{ steps.destinations.outputs.destination }}
SRC_BRANCH: ${{ steps.destinations.outputs.branch }}
run: |
# Remove "cross" remote that we just added
# If we don't, `gh pr` will break as it will try to read commits from all remotes
git remote rm cross
gh pr create --base ${{ env.SRC_BRANCH }} --head ${{ env.DEST_BRANCH }} \
--title "Merge branch '${{ env.GITHUB_REF_SLUG }}' of ${{ github.repository }} into ${{ env.SRC_BRANCH }}" --body "Cross merge PR" \
-R ${{ env.REPO }}