Skip to content

Commit 016bf56

Browse files
feat: action to deploy when new file is added
Signed-off-by: Tsung-Ju Lii <[email protected]>
1 parent 4bfd26a commit 016bf56

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

.github/workflows/deploy.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Deploy personal website
2+
3+
on:
4+
workflow_dispatch:
5+
push: # If there's anything new in `posts`, run this action to trigger the deployment.
6+
paths:
7+
- 'posts/**'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
environment: deployment
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: haskell-actions/[email protected]
17+
with:
18+
ghc-version: 9.8.4
19+
enable-stack: true
20+
stack-setup-ghc: true
21+
22+
- run: |
23+
stack build
24+
stack exec site build
25+
26+
- run: |
27+
if [[ $(git status --porcelain docs/) ]]; then
28+
git config --global user.name "github-actions[bot]"
29+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
30+
git add docs/
31+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
32+
git commit -m "Update site at $(date)"
33+
else
34+
new_post=$(git diff --name-only HEAD^ | grep 'posts/')
35+
git commit -m "Add new post: ${new_post}"
36+
fi
37+
git push origin main
38+
else
39+
echo "No changes in docs/ directory"
40+
fi
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Restructured and Added Some Automation for This Blog
3+
layout: post
4+
comments: false
5+
tags: about this blog
6+
---
7+
8+
I have been avoiding changing things up in this blog even though I really should have done this a long time ago. There were several things I did not like so much about it:
9+
10+
### Having to Have a Working Haskell Environment
11+
12+
To actually generate the site, I needed to do the following:
13+
14+
- `stack build` - this builds the executable called `site` that consumes content in `posts/` and churns out HTML files.
15+
- `stack exec site build` - this runs the `site` executable and builds the HTML files, which are stored in `_site/`.
16+
17+
Since everything is built offline, a working Haskell environment was necessary.
18+
19+
### Lots of Manual Steps
20+
21+
As stated above, since the generated HTML files are in `_site/`, I needed to find a way to get GH pages to host them. The way I did it was to have [another separate repo](https://github.com/usefulalgorithm/old-website), make sure `_site/` is pointing to that repo, then run `stack exec site build`, check that things are generated correctly in `_site`, and finally push to both this repo and the actual GH pages repo.
22+
23+
---
24+
25+
Now that I'm not employed and have some free time, I decided it was finally time to make it more usable and generally encourage myself to post more often. Here's what I did:
26+
27+
### Deprecate the Old GH Pages Repo and Just Use This One
28+
29+
This should be quite obvious - there's a [tutorial](https://jaspervdj.be/hakyll/tutorials/github-pages-tutorial.html) that tells you how to change your executable's target directory from `_site/` to `docs/`. I can just ditch the old repo, rename the Haskell repo to `usefulalgorithm.github.io`, and have its page deployed from `docs/` in the main branch. I'm pretty sure the directory has to be called `docs/` and not anything else though.
30+
31+
### Build & Deploy from GH Actions
32+
33+
I've done a bunch of GH actions in my previous job and found them to be a huge time saver. So what I wanted to do is just update Markdown files in `posts/`, and then trigger the Haskell commands from within the action runner.
34+
35+
## What Will Be Done (Hopefully in the Near Future)
36+
37+
### Post via PRs
38+
39+
Writing Markdown files is still a little annoying, especially when I'm on my phone and just want to post something to my blog. I want to find a way to create posts through pull requests, but I need to think about where to put things like tags and how to format the pull request message into a proper Markdown file.
40+
41+
### Repost to Threads (and Possibly Other Platforms)
42+
43+
More often than not, I would repost the published post to my socials. I know social media is like the worst thing that's happened in 20 years, but I still want people to read what I have to say.

0 commit comments

Comments
 (0)