Skip to content

Create Article Markdown #15

Create Article Markdown

Create Article Markdown #15

name: Create Article Markdown
on:
workflow_dispatch:
inputs:
title:
default: "draft article"
type: string
description:
default: "draft article"
type: string
jobs:
create-draft-markdown-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Create Meta Data
id: create-meta-data
run: |
echo "dateHyphen=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "dateISO=$(date '+%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
TITLE="${{ inputs.title }}"
BRANCH_NAME=${TITLE//" "/"-"}
echo "titleHyphen=${BRANCH_NAME}" >> "${GITHUB_OUTPUT}"
echo "title=${{ inputs.title }}" >> "${GITHUB_OUTPUT}"
echo "description=${{ inputs.description }}" >> "${GITHUB_OUTPUT}"
echo "label=netlify-cms/draft" >> "${GITHUB_OUTPUT}"
- name: Setup git
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
run: |
git config --local user.name GitHubActions
git remote set-url origin https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
- name: Create new draft articles
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cp template/article_template.md src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
sed -i 's/{{ dateHyphen }}/${{ steps.create-meta-data.outputs.dateHyphen }}/g' src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
sed -i 's/{{ titleHyphen }}/${{ steps.create-meta-data.outputs.titleHyphen }}/g' src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
sed -i 's/{{ dateISO }}/${{ steps.create-meta-data.outputs.dateISO }}/g' src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
sed -i 's/{{ title }}/${{ steps.create-meta-data.outputs.title }}/g' src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
sed -i 's/{{ description }}/${{ steps.create-meta-data.outputs.description }}/g' src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
cat src/content/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}.md
- name: Show GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
shell: bash
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
draft: true
branch: cms/blog/${{ steps.create-meta-data.outputs.dateHyphen }}-${{ steps.create-meta-data.outputs.titleHyphen }}
title: ${{ steps.create-meta-data.outputs.title }}
labels: ${{ steps.create-meta-data.outputs.label }}
assignees: ${{ github.triggering_actor }}
body: Automated changes by [create_article_md](https://github.com/tubone24/blog/actions/workflows/create_article_md.yml) GitHub action