Blog Post Management #114
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: Blog Post Management | |
on: | |
# Push trigger only queues posts | |
push: | |
paths: | |
- 'posts/*.md' | |
- 'posts/images/**' | |
# Schedule trigger publishes queued posts | |
schedule: | |
- cron: '0 13 * * 2,4' # 13:00 UTC Tuesday/Thursday | |
- cron: '0 15 * * 6' # 15:00 UTC Saturday | |
workflow_dispatch: | |
jobs: | |
manage-posts: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Create directory structure | |
shell: bash | |
run: | | |
mkdir -p scripts/utils | |
mkdir -p scripts/config | |
mkdir -p dist | |
mkdir -p .tracking | |
mkdir -p .queue | |
touch scripts/__init__.py | |
touch scripts/utils/__init__.py | |
touch scripts/config/__init__.py | |
if [ ! -f ".tracking/published_posts.json" ]; then | |
echo "{}" > .tracking/published_posts.json | |
fi | |
if [ ! -f ".queue/post_queue.json" ]; then | |
echo "{}" > .queue/post_queue.json | |
fi | |
chmod -R 755 scripts | |
chmod -R 755 dist | |
chmod -R 755 .tracking | |
chmod -R 755 .queue | |
- name: Determine action type | |
id: action-type | |
run: | | |
if [[ "${{ github.event_name }}" == "push" ]]; then | |
echo "action=queue" >> $GITHUB_OUTPUT | |
else | |
echo "action=publish" >> $GITHUB_OUTPUT | |
fi | |
- name: Run appropriate script | |
env: | |
MEDIUM_TOKEN: ${{ secrets.MEDIUM_TOKEN }} | |
DEVTO_API_KEY: ${{ secrets.DEVTO_API_KEY }} | |
MARKDOWN_DIR: ./posts | |
HTML_OUTPUT_DIR: ./dist | |
ACTION_TYPE: ${{ steps.action-type.outputs.action }} | |
PYTHONPATH: ${{ github.workspace }}/scripts:${{ github.workspace }} | |
run: | | |
if [[ "$ACTION_TYPE" == "queue" ]]; then | |
python scripts/queue_posts.py | |
else | |
python scripts/publish_posts.py | |
fi | |
- name: Commit tracking data | |
run: | | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
# Add all modified files explicitly | |
git add scripts/__init__.py | |
git add scripts/convert_markdown.py | |
git add scripts/post_tracker.py | |
git add scripts/publish_devto.py | |
git add scripts/publish_medium.py | |
git add scripts/publish_posts.py | |
git add scripts/queue_manager.py | |
git add scripts/queue_posts.py | |
git add scripts/test.py | |
git add .tracking/published_posts.json | |
git add .queue/post_queue.json | |
git status | |
# Only commit if there are changes | |
git diff --quiet && git diff --staged --quiet || (git commit -m "Update scripts and tracking data [skip ci]" && git push origin HEAD:${GITHUB_REF}) | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} |