diff options
Diffstat (limited to 'content/posts/2024-03-10-using-custom-software-with-github-actions-to-deploy-a-site.md')
| -rw-r--r-- | content/posts/2024-03-10-using-custom-software-with-github-actions-to-deploy-a-site.md | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/content/posts/2024-03-10-using-custom-software-with-github-actions-to-deploy-a-site.md b/content/posts/2024-03-10-using-custom-software-with-github-actions-to-deploy-a-site.md new file mode 100644 index 0000000..bbf74fd --- /dev/null +++ b/content/posts/2024-03-10-using-custom-software-with-github-actions-to-deploy-a-site.md | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | --- | ||
| 2 | title: "Using custom software with Github Actions to deploy a site" | ||
| 3 | url: using-custom-software-with-github-actions-to-deploy-a-site.html | ||
| 4 | date: 2024-03-10T15:30:11+01:00 | ||
| 5 | type: post | ||
| 6 | draft: false | ||
| 7 | --- | ||
| 8 | |||
| 9 | By default, GitHub uses Jekyll for their site generator which is fine, | ||
| 10 | but it has some issues and the complexity is not really worth it for me. | ||
| 11 | |||
| 12 | You could argue that Jekyll is simple, which it is to some degree, | ||
| 13 | but it can become complicated quite quickly if you start adding your | ||
| 14 | own spin on things. | ||
| 15 | |||
| 16 | A while ago I wrote a simple static site generator called "[jbmafp - | ||
| 17 | Just Build Me A Fucking Page](https://github.com/mitjafelicijan/jbmafp)" | ||
| 18 | which was a protest against [Hugo](https://gohugo.io). Hugo is fine but | ||
| 19 | again, if you try doing something that conflicts with the dogma they | ||
| 20 | prescribe you are in trouble. | ||
| 21 | |||
| 22 | I also moved this blog from self-hosted virtual machine to just GitHub | ||
| 23 | Pages. I didn't want to bother myself managing that server anymore. And | ||
| 24 | this presented a slight problem because I didn't want to use the default | ||
| 25 | `_docs` folder GitHub wants you to use, and I also didn't want to upload | ||
| 26 | `public` folder that gets generated to GitHub. | ||
| 27 | |||
| 28 | Thankfully, there is a way to use custom software to generate your site | ||
| 29 | like `jbmafp`. | ||
| 30 | |||
| 31 | To achieve this you need to create a file `.github/workflows/deploy.yaml` | ||
| 32 | in the root of your repository. | ||
| 33 | |||
| 34 | ```yaml | ||
| 35 | name: Build and Deploy to Pages | ||
| 36 | |||
| 37 | on: | ||
| 38 | push: | ||
| 39 | branches: ["master"] | ||
| 40 | workflow_dispatch: | ||
| 41 | |||
| 42 | permissions: | ||
| 43 | contents: read | ||
| 44 | pages: write | ||
| 45 | id-token: write | ||
| 46 | |||
| 47 | concurrency: | ||
| 48 | group: "pages" | ||
| 49 | cancel-in-progress: false | ||
| 50 | |||
| 51 | jobs: | ||
| 52 | deploy: | ||
| 53 | environment: | ||
| 54 | name: github-pages | ||
| 55 | url: ${{ steps.deployment.outputs.page_url }} | ||
| 56 | runs-on: ubuntu-latest | ||
| 57 | steps: | ||
| 58 | - name: Checkout | ||
| 59 | uses: actions/checkout@v3 | ||
| 60 | - name: Setup Pages | ||
| 61 | uses: actions/configure-pages@v3 | ||
| 62 | - name: Run a multi-line script | ||
| 63 | run: | | ||
| 64 | wget https://github.com/mitjafelicijan/jbmafp/releases/download/v0.1/jbmafp.zip | ||
| 65 | unzip jbmafp.zip | ||
| 66 | chmod +x jbmafp | ||
| 67 | ./jbmafp -b | ||
| 68 | - name: Upload artifact | ||
| 69 | uses: actions/upload-pages-artifact@v2 | ||
| 70 | with: | ||
| 71 | path: './public' | ||
| 72 | - name: Deploy to GitHub Pages | ||
| 73 | id: deployment | ||
| 74 | uses: actions/deploy-pages@v2 | ||
| 75 | ``` | ||
| 76 | |||
| 77 | This is an example for `jbmafp`. When I execute `./jbmafp -b` the program | ||
| 78 | creates `public` folder and puts all content there. And the directive | ||
| 79 | `with: path: './public'` tells `actions/deploy-pages@v2` to look for | ||
| 80 | `public` folder instead of `docs` folder. | ||
| 81 | |||
| 82 | This can be used with anything, actually. Hugo, Gatsby, Astro, you | ||
| 83 | name it. | ||
