From ca81a1c139e925dae4db735467200d9d934032fa Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 14 Mar 2024 21:50:35 +0800 Subject: [PATCH 1/5] chore: cancel build on ReadTheDocs conditionally --- .github/workflows/readthedocs-preview.yml | 1 + .readthedocs.yaml | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/.github/workflows/readthedocs-preview.yml b/.github/workflows/readthedocs-preview.yml index 110b4887..4a7d39e4 100644 --- a/.github/workflows/readthedocs-preview.yml +++ b/.github/workflows/readthedocs-preview.yml @@ -18,5 +18,6 @@ on: - .readthedocs.yaml - README.md - docs/** + - pdm.lock permissions: pull-requests: write diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 929a6438..efd84d72 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -6,6 +6,18 @@ build: post_checkout: - env | sort - git fetch --unshallow || true + # Cancel building pull requests when there aren't changed in the related files and folders. + # If there are no changes (git diff exits with 0) we force the command to return with 183. + # This is a special exit code on Read the Docs that will cancel the build immediately. + # Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition + - | + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock; + then + exit 183; + fi + # Use `git log` to check if the latest commit contains "skip ci", + # in that case exit the command with 183 to cancel the build + - (git --no-pager log --pretty="tformat:%s -- %b" -1 | grep -viq "skip ci") || exit 183 post_install: - python -m pip install --upgrade --no-cache-dir pdm - PDM_NO_EDITABLE=true make dev-doc From e7282b28f153bc29535ae8f260df39736445025b Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 14 Mar 2024 21:57:41 +0800 Subject: [PATCH 2/5] update template --- template/.readthedocs.yaml | 12 ++++++++++++ .../workflows/readthedocs-preview.yml.jinja | 1 + 2 files changed, 13 insertions(+) diff --git a/template/.readthedocs.yaml b/template/.readthedocs.yaml index 929a6438..efd84d72 100644 --- a/template/.readthedocs.yaml +++ b/template/.readthedocs.yaml @@ -6,6 +6,18 @@ build: post_checkout: - env | sort - git fetch --unshallow || true + # Cancel building pull requests when there aren't changed in the related files and folders. + # If there are no changes (git diff exits with 0) we force the command to return with 183. + # This is a special exit code on Read the Docs that will cancel the build immediately. + # Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition + - | + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock; + then + exit 183; + fi + # Use `git log` to check if the latest commit contains "skip ci", + # in that case exit the command with 183 to cancel the build + - (git --no-pager log --pretty="tformat:%s -- %b" -1 | grep -viq "skip ci") || exit 183 post_install: - python -m pip install --upgrade --no-cache-dir pdm - PDM_NO_EDITABLE=true make dev-doc diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja index 3a4545f2..e1883529 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja @@ -18,5 +18,6 @@ on: - .readthedocs.yaml - README.md - docs/** + - pdm.lock permissions: pull-requests: write From 060a307da32b100c8311387a25b1c50650a78364 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 15 Mar 2024 15:19:44 +0800 Subject: [PATCH 3/5] remove skip ci check since we use pr title as commit message --- .readthedocs.yaml | 3 --- template/.readthedocs.yaml | 3 --- 2 files changed, 6 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index efd84d72..102c2794 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -15,9 +15,6 @@ build: then exit 183; fi - # Use `git log` to check if the latest commit contains "skip ci", - # in that case exit the command with 183 to cancel the build - - (git --no-pager log --pretty="tformat:%s -- %b" -1 | grep -viq "skip ci") || exit 183 post_install: - python -m pip install --upgrade --no-cache-dir pdm - PDM_NO_EDITABLE=true make dev-doc diff --git a/template/.readthedocs.yaml b/template/.readthedocs.yaml index efd84d72..102c2794 100644 --- a/template/.readthedocs.yaml +++ b/template/.readthedocs.yaml @@ -15,9 +15,6 @@ build: then exit 183; fi - # Use `git log` to check if the latest commit contains "skip ci", - # in that case exit the command with 183 to cancel the build - - (git --no-pager log --pretty="tformat:%s -- %b" -1 | grep -viq "skip ci") || exit 183 post_install: - python -m pip install --upgrade --no-cache-dir pdm - PDM_NO_EDITABLE=true make dev-doc From 88b52598869bd8bd0b53388a6984d5db8ff37176 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 15 Mar 2024 15:21:12 +0800 Subject: [PATCH 4/5] only check README.md for test, supposed to be revert later. --- .readthedocs.yaml | 2 +- template/.readthedocs.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 102c2794..5207554f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,7 +11,7 @@ build: # This is a special exit code on Read the Docs that will cancel the build immediately. # Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition - | - if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- README.md; then exit 183; fi diff --git a/template/.readthedocs.yaml b/template/.readthedocs.yaml index 102c2794..5207554f 100644 --- a/template/.readthedocs.yaml +++ b/template/.readthedocs.yaml @@ -11,7 +11,7 @@ build: # This is a special exit code on Read the Docs that will cancel the build immediately. # Ref: https://docs.readthedocs.io/en/stable/build-customization.html#cancel-build-based-on-a-condition - | - if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- .github/workflows/readthedocs-preview.yml .readthedocs.yaml README.md docs/ pdm.lock; + if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- README.md; then exit 183; fi From 338035bc520839ec48f6ec9e8dd6a9f4cfa67f95 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Fri, 15 Mar 2024 15:31:28 +0800 Subject: [PATCH 5/5] chore: test for no doc related changes --- copier.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copier.yaml b/copier.yaml index 0e08b316..45e5d83e 100644 --- a/copier.yaml +++ b/copier.yaml @@ -3,7 +3,7 @@ _envops: block_start_string: '[%' _subdirectory: template _message_before_copy: | - Thanks for generating a project using our template. + Thanks for generating a project using our template.1 You'll be asked a series of questions whose answers will be used to generate a tailored project for you.