diff --git a/.github/workflows/update_snapshots.yml b/.github/workflows/update_snapshots.yml index 1cca5ce14..1bd68b95a 100644 --- a/.github/workflows/update_snapshots.yml +++ b/.github/workflows/update_snapshots.yml @@ -44,33 +44,36 @@ jobs: cd snapshot-repo git config user.name "GitHub Actions" git config user.email "actions@github.com" - # Automatically generate branch name + + # Ensure remote is set up correctly + git remote set-url origin https://${SNAPSHOT_REPO_TOKEN}@github.com/chintankavathia/ngx-datatable-snapshots.git + + # Fetch remote branches to avoid the "no upstream branch" error + git fetch origin + BRANCH_NAME="snapshot-update-${{ github.run_id }}" git checkout -b $BRANCH_NAME + git push --set-upstream origin $BRANCH_NAME - name: Copy generated snapshots run: | - rsync -av --delete playwright/snapshots/ snapshot-repo/ + rsync -av --delete playwright/snapshots/ snapshot-repo/snapshots - - name: Commit and push changes + - name: Commit and push changes to snapshot repo working-directory: snapshot-repo run: | git add . - # Automatically generate commit message COMMIT_MESSAGE="Update Playwright snapshots (Run ID: ${{ github.run_id }})" - git commit -m "$COMMIT_MESSAGE" + git commit -m "$COMMIT_MESSAGE" || echo "No changes to commit" + + # Ensure remote is set up correctly + git remote set-url origin https://${{ secrets.SNAPSHOT_REPO_TOKEN }}@github.com/chintankavathia/ngx-datatable-snapshots.git + git push origin $BRANCH_NAME - - name: Create pull request - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.SNAPSHOT_REPO_TOKEN }} - repository: chintankavathia/ngx-datatable-snapshots.git - base: main - head: $BRANCH_NAME - # Automatically generate title and body - title: 'Update Playwright Snapshots (Run ID: ${{ github.run_id }})' - body: | - This PR updates the Playwright snapshots generated by workflow run ID: ${{ github.run_id }}. - - Base branch: ${{ github.ref_name }} - - Commit: ${{ github.sha }} + - name: Create a pull request + run: | + git remote set-url origin https://${{ secrets.SNAPSHOT_REPO_TOKEN }}@github.com/chintankavathia/ngx-datatable-snapshots.git + # We need to re-auth in order to create PR + echo "${{ secrets.SNAPSHOT_REPO_TOKEN }}" | gh auth login --with-token + gh pr create --base main --head snapshot-update-${{ github.run_id }} --title "Update Playwright snapshots" --body "Automated PR to update snapshots based on run ID ${{ github.run_id }}."