-
Notifications
You must be signed in to change notification settings - Fork 14
86 lines (75 loc) · 2.57 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
###
#
# Creates a PR from the token branch whenever is has commits ahead of main.
#
###
name: Create Token PR
on:
push:
branches:
- tokens/*
jobs:
create_pr:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
- name: Configure GitHub User
run: |
git config user.name "Swiss Post Bot"
git config user.email "[email protected]"
# Check if a PR branch already exists
- name: Get PR Branch
id: pr-branch
run: |
PR_BRANCH="update-tokens"
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 PR branch does not exit, create it
- name: Create PR Branch
if: steps.pr-branch.outputs.exists == 'false'
run: |
git checkout -b ${{ steps.pr-branch.outputs.name }} origin/main
git push --set-upstream origin ${{ steps.pr-branch.outputs.name }}
# Check if there are token changes
- name: Get Token Changes
id: tokens
run: |
git checkout ${{ github.ref_name }} -- packages/tokens/tokensstudio-generated
git add .
if [[ -n $(git commit --dry-run --short) ]]; then
echo "haveChanged=true" >> $GITHUB_OUTPUT
else
echo "haveChanged=false" >> $GITHUB_OUTPUT
fi
# If there are token changes, commit them
- name: Commit Token Changes
if: steps.tokens.outputs.haveChanged == 'true'
run: |
git commit -m "chore(tokens): update generated files"
git push
# Check if a PR already exist
- name: Get PR
id: pr
run: |
if [[ -n $(gh pr list --head ${{ steps.pr-branch.outputs.name }}) ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}
# If the PR does not exit, create it
- name: Create PR
if: steps.pr.outputs.exists == 'false'
run: |
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 }}