Skip to content

[New Blog Post] Test blog post via Actions #14

[New Blog Post] Test blog post via Actions

[New Blog Post] Test blog post via Actions #14

Workflow file for this run

name: Create new micro-blog post and populate Hugo frontmatter
on:
issues:
types:
- labeled
permissions:
contents: write
jobs:
create-post:
# Restrict to my GitHub username to prevent the public from creating new blog posts
if: github.actor == 'stochastical' && github.event.label.name == 'new-blog-post'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Parse Issue
id: issue-parser
uses: issue-ops/parser@v4.0.0
with:
body: ${{ github.event.issue.body }}
issue-form-template: 'new-blog-post.yml'
- name: Set up Hugo Blog post YAML frontmatter
id: output-issue
env:
PARSED_ISSUE_JSON: ${{ steps.issue-parser.outputs.json }}
run: |
echo "$PARSED_ISSUE_JSON" > parsed_issue.json
cat parsed_issue.json
TITLE=$(jq '.title' parsed_issue.json)
DATE=$(jq -r '.date' parsed_issue.json)
DESCRIPTION=$(jq '.description' parsed_issue.json)
LINK=$(jq '.link' parsed_issue.json)
CONTENT=$(jq '.content' parsed_issue.json)
FILENAME=$(echo "$DATE-$TITLE.md" | tr ' ' '-' | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]-.\n')
echo "TITLE=$TITLE" >> $GITHUB_ENV
echo "DATE=$DATE" >> $GITHUB_ENV
echo "DESCRIPTION=$DESCRIPTION" >> $GITHUB_ENV
echo "LINK=$LINK" >> $GITHUB_ENV
echo "CONTENT=$CONTENT" >> $GITHUB_ENV
echo "FILENAME=$FILENAME" >> $GITHUB_ENV
- name: Create blog post file
run: |
{
# Extract everything except "content" and convert it to YAML-compatible format
echo "---"
jq 'del(.content)' "parsed_issue.json" | yq -P
echo "---"
echo ''
# Inline "content" key for the body
jq -r '.content' "parsed_issue.json"
} > content/micro-blog/"$FILENAME"
cat content/micro-blog/"$FILENAME"
- name: Switch to preview branch
run: |
git checkout -B preview
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add content/micro-blog/"$FILENAME"
git commit -m "Add new blog post (via Actions): "$FILENAME""
git push origin preview