Hexo Theme Auto Update on GitHub Actions
Due to the limitation of
git you cannot have a repository inside another with it both modified and uploaded but don’t affect the upstream. It happens that the inner repo does not belong to you but you want to keep it up-to-date with GitHub Actions but still maintain the ability to modify it, here is the solution.
It doesn’t mean we can skip or fix the limit of
git, but we can find a way to avoid that. Since there may be sensitive informations in your theme’s config, it is not recommended to directly fork the repo. Instead, create a new repo at GitHub and mirror the theme repo like below:
git clone --bare https://github.com/exampleuser/the-theme-repo.git
Now you have the full permissions to make modifications to it. With your changes all done, commit and push them to the cloud.
ssh-keygen -t ed25519 -b 4096 -C "$(git config user.email)" -f github-deploy-key to generate a key pair for the workflow to update the theme repo automatically, hit enters. Don’t put passphrases, or there can be problems for Actions to use it. Make sure you do not upload your key pair to the cloud.
Open your theme repo, paste the content of the public key
github-deploy-key.pub to its
Deploy keys section in settings:
Naming doesn’t matter, but you might want to give it a good name if you don’t want to mess it up in the future.
Since the theme is now saved in the cloud, we no longer need locally. Remove it, commit, add
.gitignore, commit again.
Add the private key you just created
github-deploy-key to the
Secrets section in settings of your blog repo:
THEME_UPDATE_PRIV_KEY here, you can use your own name, but remember to change the workflow accordingly.
Here comes the important part, let’s update the workflow to do the following things:
git cloneyour fork of the theme
- check for updates in the upstream
- update your fork on any changes
- build and upload your blog as we did in my previous post
Take the following workflow as a reference:
You can find the only changes happen is the new
Update Themes block, details have been added as comments. If the upstream changes do not affect your own changes, the workflow should finish by itself and everything’s fine. But if there is something wrong with you files, a merge failure will come up and fail the workflow as well. You will receive an email from GitHub notifying you about that, and you can fix the conflicts manually. Before that, nothing on your blog will be changed.