From bb66b8c85dc56e4a21218bdb8a04f3ad038b6cf5 Mon Sep 17 00:00:00 2001 From: Chintan Kavathia Date: Tue, 26 Nov 2024 14:41:47 +0530 Subject: [PATCH] ci: workflow to update snapshots --- .github/workflows/update_snapshots.yml | 76 ++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/update_snapshots.yml diff --git a/.github/workflows/update_snapshots.yml b/.github/workflows/update_snapshots.yml new file mode 100644 index 000000000..14809df91 --- /dev/null +++ b/.github/workflows/update_snapshots.yml @@ -0,0 +1,76 @@ +name: Generate Playwright Snapshots and Create PR + +on: + workflow_dispatch: # Manual trigger, but inputs are auto-generated below + +jobs: + generate-snapshots: + name: Generate Snapshots + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install dependencies + run: | + npm ci + + - name: Build + run: | + npm run build --if-present + env: + CI: true + + - name: E2E Prepare + run: | + npm run e2e:prepare --if-present + env: + CI: true + + - name: Generate Playwright snapshots + run: | + npm run vrt:update --if-present + env: + CI: true + + - name: Clone snapshot repository + env: + SNAPSHOT_REPO_TOKEN: ${{ secrets.SNAPSHOT_REPO_TOKEN }} + run: | + git clone https://${SNAPSHOT_REPO_TOKEN}@github.com/chintankavathia/ngx-datatable-snapshots.git snapshot-repo + cd snapshot-repo + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + # Automatically generate branch name + BRANCH_NAME="snapshot-update-${{ github.run_id }}" + git checkout -b $BRANCH_NAME + + - name: Copy generated snapshots + run: | + rsync -av --delete playwright/snapshots/ snapshot-repo/ + + - name: Commit and push changes + 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 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 }}