Skip to content

Commit

Permalink
Update create-token-pr.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
alizedebray committed Oct 16, 2024
1 parent 46ab176 commit 99df8e8
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions .github/workflows/create-token-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,45 @@ jobs:

steps:
# Checkout the token branch which was pushed
- name: Checkout
- name: Checkout Token Branch
uses: actions/checkout@v4

# Get the name of the PR branch corresponding to the token branch
- name: Get Branch Name
id: branch-names
# Check if the PR branch corresponding to the token branch exists
- name: Get PR Branch
id: pr-branch
run: |
echo "pr-branch=merge-tokens-$(echo ${GITHUB_REF##*/})" >> $GITHUB_OUTPUT
PR_BRANCH="merge-tokens-${GITHUB_REF##*/}"
echo "name=${PR_BRANCH}" >> $GITHUB_OUTPUT
# Check if the PR branch already exists
- name: Check PR Branch
id: ls-remote
run: |
echo "pr_branch=$(git ls-remote origin $PR_BRANCH)" >> $GITHUB_OUTPUT
env:
PR_BRANCH: ${{ steps.branch-names.outputs.pr-branch }}
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 }}

# if the branch already exits, update the PR
- name: Update Branch
if: steps.ls-remote.outputs.pr_branch != ''
- name: Update PR Branch
if: steps.pr-branch.outputs.exists == 'true'
run: |
git checkout $PR_BRANCH
git config user.name "Swiss Post Bot"
git config user.email "[email protected]"
git merge ${{ github.ref_name }} -X theirs --no-edit
git push
git push origin ${{ steps.pr-branch.outputs.name }}
env:
PR_BRANCH: ${{ steps.branch-names.outputs.pr-branch }}
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}

# if the branch does not exit, create the PR
- name: Create PR
if: steps.ls-remote.outputs.pr_branch == ''
if: steps.pr-branch.outputs.exists == 'false'
run: |
git checkout -b $PR_BRANCH ${{ github.ref_name }}
git push --set-upstream origin merge-tokens-v2-24-10
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:
PR_BRANCH: ${{ steps.branch-names.outputs.pr-branch }}
GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}

0 comments on commit 99df8e8

Please sign in to comment.