Is there a way for a two way Repository <-> Wiki synchronization?

My goal is to setup two specific workflows in a Repository:

  • A workflow that will push changes to the Repository’s wiki whenever a push is made towards a specific folder of the Repository itself.
  • A workflow that in regular intervals checks, if the Wiki has changes not present in the aforementioned folder of the Repository and in such a case auto-updates accordingly.

The first one is fairly easy to implement. In fact do I actually have other Repositories that have a Wiki action doing this already.
The problem is the second workflow. I’m not sure what would be the best way to check if there is a difference between wiki and folder, to then pull the info and push into the right directory.

Because of that would I like to ask if someone here has any suggestions on how to implement this.

Just in case do I have this flowchart here to visualize what each action should do:

I think you can run a variant of git log command on the wiki/ directory and the wiki repository. Then compare the dates of the commits. If the date of the last commit in the wiki/ directory is after the last commit of the wiki repository, then you can copy the contents of the wiki/ folder to the wiki repo.

Here’s a command you can run on the main repo to get the last commit date:

git log -s  --format=%ci wiki | head -n1

Now…there’s a problem if both sides have a commit and there could be a conflict. That might have to be handled by manually fixing conflicts.

Thanks,

There is apparently an event called gollum which is triggered whenever a wiki page is created or updated (Weird name if you ask me…), so I could use this and the only remaining question would be how to push the content of the wiki to that specific folder in the repository in such a case?

You need to check out both the wiki and the repo in the workflow job. Then you would copy the wike contents (excluding the .git repository) into the appropriate folder of the repo.

At this point you can use the git cli to commit any changes. If you want to go YOLO, then you can push these changes directly to master/main without making a pull request.

If you want to be more careful (recommended) you can then use git to check out a new branch. And then you can use the gh cli to create a pull request for these changes.

1 Like