From b77f93ba18a8d11ff20cbfd89b3a04e53d76664f Mon Sep 17 00:00:00 2001 From: gretzke Date: Fri, 3 Nov 2023 06:11:39 +0100 Subject: [PATCH] Run tests on PRs, only trigger docs when content changed --- .github/workflows/test.yaml | 4 +++- .pre-commit-config.yaml | 3 ++- script/util/doc_gen.sh | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 script/util/doc_gen.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 09880b1..78a2ed5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,8 @@ name: test -on: workflow_dispatch +on: + pull_request: + branches: [master, staging, dev, feat/**, fix/**] env: FOUNDRY_PROFILE: ci diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 43394ee..75613ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,8 @@ repos: name: Generate documentation description: Generate docs with `forge doc` language: system - entry: forge doc -b -o docs/html + # generates docs and unstages files if only the commit hash changed within the file, this way only when the documentation is updated, the documentation needs to be regenerated and only the changed files are pushed + entry: "script/util/doc_gen.sh" pass_filenames: false - repo: https://github.com/pre-commit/mirrors-prettier rev: "v3.0.3" diff --git a/script/util/doc_gen.sh b/script/util/doc_gen.sh new file mode 100755 index 0000000..1010390 --- /dev/null +++ b/script/util/doc_gen.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# generate docs +forge doc -b -o docs/html + +# Unstage all docs where only the commit hash changed +# Get a list of all unstaged files in the directory +files=$(git diff --name-only -- 'docs/html/*') + +# Loop over each file +for file in $files; do + # Get the diff for the file, only lines that start with - or + + diff=$(git diff $file | grep '^[+-][^+-]') + echo $file + echo "$diff" | wc -l + # Check if there are any other changes in the diff besides the commit hash (in that case the file has more than 1 line that changed, one minus one plus) + if [[ $(echo "$diff" | wc -l) -eq 2 ]]; then + # If there are no other changes, discard the changes for the file + git reset HEAD $file + git checkout -- $file + fi +done \ No newline at end of file