Update Posts #178
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: Update Posts | |
on: | |
schedule: | |
- cron: "0 * * * *" # Runs every hour | |
workflow_dispatch: # Allows manual triggering | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetch full history for git operations | |
# Set up Python environment | |
- name: Set up Python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.x' | |
# Install Python dependencies if required | |
- name: Install dependencies | |
run: pip install -r requirements.txt | |
# Run your update script | |
- name: Run update script | |
run: python3 update.py _data/posts.yml | |
# Configure Git for commit | |
- name: Configure Git | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Commit and Push Changes | |
run: | | |
# Check if there are changes to stash | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Stashing local changes..." | |
git stash --include-untracked | |
stash_created=true | |
else | |
echo "No local changes to stash." | |
stash_created=false | |
fi | |
# Pull latest changes and rebase | |
git pull --rebase origin master || git rebase --abort | |
# Reapply stashed changes if any | |
if [ "$stash_created" = true ]; then | |
echo "Applying stashed changes..." | |
git stash pop || echo "No stash entries to apply." | |
fi | |
# Stage, commit, and push changes | |
git add _data/posts.yml | |
git add _data/posts_preformatted_text.yml | |
if ! git diff --cached --quiet; then | |
git commit -m "[skip update] Automated update: $(date)" | |
git push origin master | |
else | |
echo "No changes to commit." | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |