-
Notifications
You must be signed in to change notification settings - Fork 14
63 lines (55 loc) · 2 KB
/
create-token-pr.yaml
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
###
#
# Creates a PR from the token branch whenever is has commits ahead of main.
#
###
name: Create Token PR
on:
push:
branches:
- tokens/v*
jobs:
create_pr:
runs-on: ubuntu-latest
steps:
# Checkout the token branch which was pushed
- name: Checkout Token Branch
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
# Check if the PR branch corresponding to the token branch exists
- name: Get PR Branch
id: pr-branch
run: |
PR_BRANCH="merge-tokens-${GITHUB_REF##*/}"
echo "name=${PR_BRANCH}" >> $GITHUB_OUTPUT
if [[ -n $(git ls-remote origin "${PR_BRANCH}") ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
# if the branch exits, update the PR
- name: Checkout PR Branch
if: steps.pr-branch.outputs.exists == 'true'
uses: actions/checkout@v4
with:
ref: ${{ steps.pr-branch.outputs.name }}
clean: false
- name: Update PR Branch
if: steps.pr-branch.outputs.exists == 'true'
run: |
git config user.name "Swiss Post Bot"
git config user.email "[email protected]"
git merge ${{ github.ref_name }} -X theirs --no-edit
git push origin ${{ steps.pr-branch.outputs.name }}
env:
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
# if the branch does not exit, create the PR
- name: Create PR
if: steps.pr-branch.outputs.exists == 'false'
run: |
git checkout -b ${{ steps.pr-branch.outputs.name }} ${{ github.ref_name }}
git push --set-upstream origin ${{ steps.pr-branch.outputs.name }}
gh pr create --title "chore(tokens): :art: update tokens" --body "Merge this PR to update the tokens in the main branch." --base main
env:
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}