[AUTO]: Publish scheduled articles #848
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "[AUTO]: Publish scheduled articles" | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '20 12 * * *' | |
jobs: | |
check-drafts: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Check for articles dated for today | |
id: move-drafts | |
working-directory: ${{ github.workspace }}/_drafts/ | |
run: | | |
today=$(date +%Y-%m-%d) | |
for file in *.md; do | |
if [[ "$file" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}.*.md ]]; then | |
date_of_post=$(echo "$file" | cut -c 1-10) | |
title_of_post=$(basename -s .md "$file" | cut -c 12-) | |
if [[ "$date_of_post" == "$today" ]] ; then | |
mv "$file" ${{ github.workspace }}/_posts/ | |
echo "::set-output name=new-post::true" | |
echo "::set-output name=new-post-title::$title_of_post" | |
fi | |
fi | |
done | |
- name: Push changes back to repo | |
if: steps.move-drafts.outputs.new-post | |
uses: EndBug/add-and-commit@v8 | |
with: | |
message: "Scheduled publish: ${{ steps.move-drafts.outputs.new-post-title }}" | |
- name: Run Publish Site workflow | |
if: steps.move-drafts.outputs.new-post | |
uses: benc-uk/workflow-dispatch@v1 | |
with: | |
workflow: Publish site | |
token: ${{ secrets.WORKFLOW_PAT }} | |
ref: master |