Now that I have customised Jekyll I want to simplify my workflow.
Although I am starting this with a bunch of actual posts, most of my content will be links. I usually share these as soon as I’ve followed the link and read the content, usually straight from my phone while browsing in the evening.
I therefore need the ability to generate links entries on my site as easily as possible, from my phone.
My plan is to use GitHub actions with a manual trigger to generate the markdown files, with action inputs matched to the required front-matter variables.
Generate files with GitHub actions
First of all, what do I need to generate files in my repository from a GitHub action?
We’ll the Write File Action, as echoing echo
each line in a run
step looks like a pain.
The content of the file is easier to define as a multiline string, indicated wth a pipe |
.
I also need to set the date in the filename.
I’ll do it as per this SO answer, which uses the ::set-output::
workflow command.
Finally, we need to commit the file back to main. Unfortunately this doesn’t trigger our jekyll build action, as explained here :sad:
At this stage I have not figured out why using a personal token hasn’t worked around this issue…. To be continued
Plan B is to use a repository_dispatch
event trigger as per this article.
Which works!!
Final workflow definition looks like this (check the repo for the latest definition)
name: Generate a new file in the _links folder
on:
workflow_dispatch:
inputs:
title:
description: 'A user friendly name/description for the URL we are sharing'
required: true
target:
description: 'The URL we are sharing'
required: true
default: ''
source:
description: 'Where (free text) did we find out about the URL we are sharing'
required: true
default: 'the internet'
source_url:
description: 'Where (URL) did we find out about the URL we are sharing'
required: false
tags:
description: 'Space separated list of tags'
required: true
blurb:
description: 'Some text to explain why you are sharing'
required: true
default: 'This looks interesting...'
jobs:
newlink:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Generate the filename
id: filename
run: |
date="$(date +'%Y-%m-%d')"
filename="${date}-$.md"
echo "filename = ${filename}"
echo "::set-output name=filename::${filename}"
- name: Generate new link file
uses: DamianReeves/write-file-action@v1.0
with:
path: _links/$
write-mode: append
contents: |
---
title: $
target : $
source : $
source_url : $
tags: $
---
$
- name: Commit and push files
run: |
git config user.name "NewLink GitHub Action"
git config user.email "<>"
git add _links/$
git commit -m "New link: $"
git push https://$@github.com/$.git main
- name: Trigger jekyll build
run: |
curl -X POST https://api.github.com/repos/$/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-u $ \
--data '{"event_type": "New link: $", "client_payload": { "customField": "customValue" }}'