Skip to content

Deploy to Blogger #5186

Deploy to Blogger

Deploy to Blogger #5186

name: Deploy to Blogger
on:
schedule:
- cron: "0 * * * *" # каждый час в начале часа
workflow_dispatch:
concurrency:
group: "blog-deploy"
cancel-in-progress: false
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib markdown markdown2
- name: Fetch published_posts.json from gh-blogs (or init)
run: |
# Проверяем, существует ли ветка gh-blogs
if git ls-remote --exit-code origin gh-blogs; then
echo "Branch gh-blogs exists, fetching published_posts.json..."
git fetch origin gh-blogs
git checkout origin/gh-blogs -- published_posts.json
else
echo "Branch gh-blogs does not exist, creating initial JSON..."
echo "{}" > published_posts.json
fi
- name: Select random token
run: |
TOKENS=("TOKEN_JSON")
SELECTED=${TOKENS[$((RANDOM % ${#TOKENS[@]}))]}
echo "SELECTED=$SELECTED" >> $GITHUB_ENV
- name: Write token.json
run: echo "${{ secrets[env.SELECTED] }}" | base64 --decode > token.json
- name: Publish to Blogger
run: python scripts/publish_to_blogger.py
env:
BLOG_ID: ${{ secrets.BLOGGER_BLOG_ID }}
TOKEN_FILE: token.json
- name: Push updated published_posts.json to gh-blogs
run: |
TMP_DIR=$(mktemp -d)
git clone https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git "$TMP_DIR"
cd "$TMP_DIR"
# Проверяем, есть ли ветка gh-blogs
if git show-ref --quiet refs/heads/gh-blogs; then
git checkout gh-blogs
else
git checkout --orphan gh-blogs
git rm -rf .
fi
# Копируем JSON из рабочего каталога Actions
cp $GITHUB_WORKSPACE/published_posts.json ./published_posts.json
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add published_posts.json
git commit -m "Update published_posts.json" --quiet || echo "No changes to commit"
git push origin gh-blogs --force --quiet