From 36f16261c6c388cffb78238d5b3e8e76a5578fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aliz=C3=A9=20Debray?= <33580481+alizedebray@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:26:53 +0200 Subject: [PATCH] chore: improve the token PR workflow (#3766) --- .github/workflows/create-token-pr.yaml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/create-token-pr.yaml b/.github/workflows/create-token-pr.yaml index 31b2c7315c..ad1f91ab67 100644 --- a/.github/workflows/create-token-pr.yaml +++ b/.github/workflows/create-token-pr.yaml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v4 # Get the name of the token branch which was pushed and the corresponding PR branch - - name: Get Branch + - name: Get Branch Name id: branch-names run: | echo "pr-branch=merge-tokens-$(echo ${GITHUB_REF##*/})" >> $GITHUB_OUTPUT @@ -29,14 +29,17 @@ jobs: - name: Check PR Branch id: git-branch run: | - GIT_BRANCH="$(git branch -l $PR_BRANCH)" - echo "pr_branch=${GIT_BRANCH}" >> $GITHUB_OUTPUT + if git branch --list "$PR_BRANCH"; then + echo "pr_branch=true" >> $GITHUB_OUTPUT + else + echo "pr_branch=false" >> $GITHUB_OUTPUT + fi env: PR_BRANCH: ${{ steps.branch-names.outputs.pr-branch }} # if the branch already exits, update the PR - name: Update Branch - if: steps.git-branch.outputs.pr_branch != '' + if: steps.git-branch.outputs.pr_branch == 'true' run: | git checkout $PR_BRANCH git merge ${{ github.ref_name }} -X theirs --no-edit @@ -47,10 +50,10 @@ jobs: # if the branch does not exit, create the PR - name: Create PR - if: steps.git-branch.outputs.pr_branch == '' + if: steps.git-branch.outputs.pr_branch == 'false' run: | git checkout -b $PR_BRANCH ${{ github.ref_name }} - gh pr create --title "chore(tokens): :art: update tokens" + gh pr create --title "chore(tokens): :art: update tokens" --body "Merge this PR to update the tokens in the main branch." --base main --head $PR_BRANCH env: PR_BRANCH: ${{ steps.branch-names.outputs.pr-branch }} GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }}