Skip to content

Commit

Permalink
Run tests on PRs, only trigger docs when content changed
Browse files Browse the repository at this point in the history
  • Loading branch information
gretzke committed Nov 3, 2023
1 parent 97cb875 commit b77f93b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: test

on: workflow_dispatch
on:
pull_request:
branches: [master, staging, dev, feat/**, fix/**]

env:
FOUNDRY_PROFILE: ci
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions script/util/doc_gen.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b77f93b

Please sign in to comment.