diff --git a/.github/workflows/create-token-pr.yaml b/.github/workflows/create-token-pr.yaml index 9f6c226966..54d78733ff 100644 --- a/.github/workflows/create-token-pr.yaml +++ b/.github/workflows/create-token-pr.yaml @@ -19,6 +19,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 + token: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }} - name: Configure GitHub User run: | @@ -42,33 +43,33 @@ jobs: - name: Create PR Branch if: steps.pr-branch.outputs.exists == 'false' run: | - git checkout -b ${{ steps.pr-branch.outputs.name }} ${{ github.ref_name }} + git checkout -b ${{ steps.pr-branch.outputs.name }} origin/main git push --set-upstream origin ${{ steps.pr-branch.outputs.name }} - env: - GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }} - # If the PR branch exits, update it with the tokens branch - - name: Update PR Branch with Tokens Branch - if: steps.pr-branch.outputs.exists == 'true' + # Check if there are token changes + - name: Get Token Changes + id: tokens run: | - git checkout ${{ steps.pr-branch.outputs.name }} - git merge ${{ github.ref_name }} -X theirs --no-edit - env: - GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }} + 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 - # Always update the PR branch with the main branch - - name: Update PR Branch with main + # If there are token changes, commit them + - name: Commit Token Changes + if: steps.tokens.outputs.haveChanged == 'true' run: | - git merge origin/main -X ours --no-edit + git commit -m "chore(tokens): update generated files" git push - env: - GITHUB_TOKEN: ${{ secrets.SWISSPOSTDEVS_ACCESS_TOKEN }} # Check if a PR already exist - name: Get PR id: pr run: | - if [[ -n $(gh pr list --head "${{ steps.pr-branch.outputs.name }}") ]]; then + if [[ -n $(gh pr list --head ${{ steps.pr-branch.outputs.name }}) ]]; then echo "exists=true" >> $GITHUB_OUTPUT else echo "exists=false" >> $GITHUB_OUTPUT