From 5c92ad08e672c6ae9fe281935289fea0e417faba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 30 Oct 2024 10:07:12 +0100 Subject: [PATCH] Add regenerate example files mode --- .github/workflows/main.yaml | 11 ++++++++++- Makefile | 3 ++- buildtools/check-example | 13 ++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 108253cf5dc8..7591766de4b5 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -34,6 +34,7 @@ jobs: env: PATH: /bin:/usr/bin:/usr/local/bin:/home/runner/.local/bin + REGENERATE_EXAMPLES: true steps: - name: GitHub event @@ -115,7 +116,10 @@ jobs: NODE_OPTIONS: --openssl-legacy-provider if: github.event_name != 'pull_request_target' - run: make check-examples-checker - if: github.event_name != 'pull_request_target' + if: | + github.event_name != 'pull_request_target' + && env.REGENERATE_EXAMPLES == 'false' + # Cypress tests - run: make serve-gmf-apps & if: github.event_name != 'pull_request_target' @@ -133,6 +137,11 @@ jobs: NODE_OPTIONS: --openssl-legacy-provider - run: make check-examples if: github.event_name != 'pull_request_target' + - run: | + rm examples/error-ref.png + find . ! -name *-ref.png -type f -exec rm {} \; + if: env.REGENERATE_EXAMPLES == 'true' + - run: '[ ${REGENERATE_EXAMPLES} == false ]' - uses: actions/upload-artifact@v4 with: name: Examples diff --git a/Makefile b/Makefile index 0e614efde42d..2c1bea81eef8 100644 --- a/Makefile +++ b/Makefile @@ -303,7 +303,8 @@ contribs/dist: .build/build-dll.timestamp mkdir -p $(dir $@) CI=true LANGUAGE=en_US buildtools/retry node buildtools/check-example.js \ .build/examples-hosted/error.html - ! buildtools/check-example .build/examples-hosted/error.html.png examples/error-ref.png + # Only if REGENERATE_EXAMPLES is not true + ! ( [ ${REGENERATE_EXAMPLES} != true ] && buildtools/check-example .build/examples-hosted/error.html.png examples/error-ref.png ) touch $@ # Add --generate as argument to buildtools/check-example to regenerate the reference images diff --git a/buildtools/check-example b/buildtools/check-example index 3e34eb37be2d..1fffe4c7a2cc 100755 --- a/buildtools/check-example +++ b/buildtools/check-example @@ -84,9 +84,16 @@ def main(): stdout=subprocess.PIPE, ) result = float(result.stdout.decode().splitlines()[-1].split()[1]) - if result > 0.01: - print(f"{result} > 0.01 => {diff}") - sys.exit(1) + if os.environ.get("REGENERATE_EXAMPLES") == "true": + if result > 0: + shutil.copyfile(current, old_ref) + print(f"::error file={old_ref}:: Regenerate the ref image: {old_ref}") + else: + os.remove(old_ref) + else: + if result > 0.01: + print(f"{result} > 0.01 => {diff}") + sys.exit(1) if __name__ == "__main__":