In a previous post, I discussed a GitHub Action automation that I set up. In that post, I showcased how they could automate the concatenation of blog posts. But, as it turns out, ya boi is a little dumb. I made a mistake, and it didn’t work correctly, as the continuous integration I had set up was a little less continuous than I had planned—apologies about misleading y’all, mea culpa, mea maxima culpa.

This post is all about righting that terrible wrong.

The Issue with the Original Automation

Initially, the GitHub Action was designed to trigger upon each commit. It seemed seamless, but I recently realized it wasn’t functioning as I anticipated. The trigger was not triggering correctly, causing the concatenation action not to happen and defeating the original post’s whole purpose.

Rewriting the Automation

The solution? A minor overhaul. I shifted the automation trigger from commit-based to a more reliable, time-based approach. Now, the GitHub Action kicks off every hour, ensuring a consistent and timely update to the blog, irrespective of when I commit.

Updated GitHub Workflow YAML

The critical update is in the first couple of lines of the workflow YAML. Here’s a glimpse into the modification:

# Excerpt from concatenate_posts.yml
    - cron: '0 * * * *'

This snippet illustrates the shift to a cron schedule, triggering the Action hourly. It’s a simple yet effective change, enhancing the reliability of the automation process.

This process now runs every hour and creates an updated concatenated posts file.

The whole YAML file is as follows:

name: Hourly Check and Concatenate MD Files with Metadata

    - cron: '0 * * * *'
    runs-on: ubuntu-latest

    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Concatenate .md files with metadata
      run: |
        mkdir -p workflows_output
        > workflows_output/
        cd _posts
        for file in *.md; do
            echo "File: $file" >> ../workflows_output/
            echo "Creation Date: $(git log --format=\"%aD\" -n 1 -- $file)" >> ../workflows_output/
            cat "$file" >> ../workflows_output/
            echo "------------------------" >> ../workflows_output/

    - name: Commit and push if there are changes
      run: |
        git config --local ""
        git config --local "GitHub Action"
        git add -A
        git diff --quiet && git diff --staged --quiet || git commit -m "Concatenated .md files with metadata"
        git push

Go ÖN Home