diff --git a/.github/workflows/preview_build.yml b/.github/workflows/preview_build.yml index fe37eb8c..4d644735 100644 --- a/.github/workflows/preview_build.yml +++ b/.github/workflows/preview_build.yml @@ -17,6 +17,20 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 steps: + + - name: Comment PR + uses: thollander/actions-comment-pull-request@v2 + env: + URL_SLUG: ${{ github.event.number }}-${{ github.head_ref }} + with: + message: | + Preview is being built... + + Preview will be available at https://egui-pr-preview.github.io/pr/${{ env.URL_SLUG }} + + View snapshot changes at [kitdiff](https://rerun-io.github.io/kitdiff/?url=${{ github.event.pull_request.html_url }}) + comment_tag: 'egui-preview' + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable with: diff --git a/.github/workflows/preview_deploy.yml b/.github/workflows/preview_deploy.yml index 5a97658c..8fbe8bae 100644 --- a/.github/workflows/preview_deploy.yml +++ b/.github/workflows/preview_deploy.yml @@ -61,5 +61,7 @@ jobs: message: | Preview available at https://egui-pr-preview.github.io/pr/${{ env.URL_SLUG }} Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed. + + View snapshot changes at [kitdiff](https://rerun-io.github.io/kitdiff/?url=${{ github.event.pull_request.html_url }}) pr_number: ${{ env.PR_NUMBER }} comment_tag: 'egui-preview' diff --git a/.github/workflows/update_kittest_snapshots.yml b/.github/workflows/update_kittest_snapshots.yml new file mode 100644 index 00000000..e0638238 --- /dev/null +++ b/.github/workflows/update_kittest_snapshots.yml @@ -0,0 +1,40 @@ +on: + workflow_dispatch: + inputs: + run_id: + description: 'The run ID that produced the artifact' + required: true + type: string + +permissions: + actions: read + +name: Update kittest snapshots +jobs: + update-snapshots: + name: Update snapshots from artifact + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + with: + lfs: true + # We can't use the workflow token since that would prevent our commit to cause further workflows. + # See https://github.com/stefanzweifel/git-auto-commit-action#commits-made-by-this-action-do-not-trigger-new-workflow-runs + token: '${{ secrets.GITHUB_TOKEN }}' + + - name: Accept snapshots + env: + GH_TOKEN: ${{ github.token }} + RUN_ID: ${{ github.event.inputs.run_id }} + run: ./scripts/update_snapshots_from_ci.sh + + - name: Git status + run: git status + + - uses: stefanzweifel/git-auto-commit-action@v6 + with: + commit_message: 'Update snapshot images' + diff --git a/scripts/accept_snapshots.sh b/scripts/accept_snapshots.sh new file mode 100755 index 00000000..9e02eadb --- /dev/null +++ b/scripts/accept_snapshots.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# This script moves all {name}.new.png files to {name}.png. +# Its main use is in the update_kittest_snapshots CI job, but you can also use it locally. + +set -eu + +# rename the .new.png files to .png +find . -type d -path "*/tests/snapshots*" | while read dir; do + find "$dir" -type f -name "*.new.png" | while read file; do + mv -f "$file" "${file%.new.png}.png" + done +done + +echo "Done!" diff --git a/scripts/update_snapshots_from_ci.sh b/scripts/update_snapshots_from_ci.sh index c1536036..46262d72 100755 --- a/scripts/update_snapshots_from_ci.sh +++ b/scripts/update_snapshots_from_ci.sh @@ -8,9 +8,12 @@ set -eu BRANCH=$(git rev-parse --abbrev-ref HEAD) -RUN_ID=$(gh run list --branch "$BRANCH" --workflow "Rust" --json databaseId -q '.[0].databaseId') - -echo "Downloading test results from run $RUN_ID from branch $BRANCH" +if [ -z "${RUN_ID:-}" ]; then + RUN_ID=$(gh run list --branch "$BRANCH" --workflow "Rust" --json databaseId -q '.[0].databaseId') + echo "Downloading test results from run $RUN_ID from branch $BRANCH" +else + echo "Using provided RUN_ID: $RUN_ID" +fi # remove any existing .new.png that might have been left behind find . -type d -path "*/tests/snapshots*" | while read dir; do @@ -27,11 +30,4 @@ rsync -a tmp_artefacts/ . rm -r tmp_artefacts -# rename the .new.png files to .png -find . -type d -path "*/tests/snapshots*" | while read dir; do - find "$dir" -type f -name "*.new.png" | while read file; do - mv -f "$file" "${file%.new.png}.png" - done -done - -echo "Done!" +./scripts/accept_snapshots.sh