Skip to content

Commit

Permalink
fix: docs github mirror action (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludamad authored Jul 22, 2023
1 parent 4db1345 commit b753ae7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/mirror_docs_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ jobs:

- name: Push to branch
run: |
./scripts/git_subrepo.sh push docs --branch=main
# we push using git subrepo (https://github.com/ingydotnet/git-subrepo)
# with some logic to recover from squashed parent commits
SUBREPO_PATH=docs
# identify ourselves, needed to commit
git config --global user.email "tech@aztecprotocol.com"
git config --global user.name "AztecBot"
# push to subrepo, commit locally
./scripts/git_subrepo.sh push $SUBREPO_PATH --branch=main
39 changes: 38 additions & 1 deletion scripts/git_subrepo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,42 @@
set -eu

SCRIPT_DIR=$(dirname "$(realpath "$0")")
"$SCRIPT_DIR"/git-subrepo/lib/git-subrepo $@

# Check for unstaged changes
if ! git diff-index --quiet HEAD --; then
echo "Error: You have unstaged changes. Please commit or stash them before running git_subrepo.sh."
exit 1
fi

# git subrepo is quite nice, but has one flaw in our workflow:
# We frequently squash commits in PRs, and we might update the .gitrepo file
# with a parent commit that later does not exist.
# A backup heuristic is used to later find the squashed commit's parent
# using the .gitrepo file's git history. This might be brittle
# in the face of e.g. a .gitrepo whitespace change, but it's a fallback,
# we only have this issue in master, and the file should only be edited
# generally by subrepo commands.
SUBREPO_PATH="${2:-}"
if [ -d "$SUBREPO_PATH" ] ; then
# Read parent commit from .gitrepo file
parent_commit=$(awk -F'= ' '/parent =/{print $2}' $SUBREPO_PATH/.gitrepo)
# Check if the parent commit exists in this branch
if ! git branch --contains $parent_commit | grep -q '\*'; then
echo "Auto-fixing squashed parent in $SUBREPO_PATH/.gitrepo."

# Get the commit that last wrote to .gitrepo
last_commit=$(git log -1 --pretty=format:%H -- "$SUBREPO_PATH/.gitrepo")
# Get parent of the last commit
new_parent=$(git log --pretty=%P -n 1 $last_commit)

# Update parent in .gitrepo file using perl
perl -pi -e "s/${parent_commit}/${new_parent}/g" "$SUBREPO_PATH/.gitrepo"

# Commit this change
git add "$SUBREPO_PATH/.gitrepo"
# This commit should only go into squashed PRs
git commit -m "git_subrepo.sh: Fix parent in .gitrepo file."
fi
fi
"$SCRIPT_DIR"/git-subrepo/lib/git-subrepo -x $@

0 comments on commit b753ae7

Please # to comment.