Update create-token-pr.yaml #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
# | |
# 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 | |
uses: actions/checkout@v4 | |
# 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: Update PR | |
if: steps.pr-branch.outputs.exists == 'true' | |
run: | | |
gh pr edit ${{ steps.pr-branch.outputs.name }} --base ${{ github.ref_name }} | |
gh pr update-branch ${{ steps.pr-branch.outputs.name }} | |
gh pr edit ${{ steps.pr-branch.outputs.name }} --base main | |
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 }} |