Skip to content

Auto Upload Contents #19

Auto Upload Contents

Auto Upload Contents #19

name: Auto Upload Contents
on:
workflow_dispatch:
inputs:
n_content:
description: "Number of posts to generate and upload"
required: true
default: "1"
topic:
description: "Topic for content generation"
required: true
default: "Free Topic"
provider:
description: "LLM provider (e.g. openai, mistral)"
required: true
default: "mistral"
enable_langchain_tracing:
description: "Enable LangChain tracing (true/false)"
required: false
default: "false"
schedule:
- cron: "0 0 * * 1" # Run every Monday at 00:00 UTC
jobs:
generate-content:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'schedule' && vars.ENABLE_SCHEDULED_POSTING == 'true') }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.5.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Generate content
run: |
source $VENV
export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}
if [ "${{ github.event_name }}" = "schedule" ]; then
n_content="${{ vars.SCHEDULED_POST_COUNT || 5 }}"
topic="${{ vars.SCHEDULED_POST_TOPIC || 'Free Topic' }}"
provider="${{ vars.LANGUAGE_MODEL_PROVIDER || 'mistral' }}"
else
n_content="${{ github.event.inputs.n_content }}"
topic="${{ github.event.inputs.topic }}"
provider="${{ github.event.inputs.provider }}"
fi
python scripts/generate_content.py \
--n-content "$n_content" \
--topic "$topic" \
--provider "$provider"
env:
VENV: ${{ github.workspace }}/.venv/bin/activate
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
LANGCHAIN_TRACING_V2: ${{ github.event.inputs.enable_langchain_tracing }}
LANGCHAIN_API_KEY: ${{ secrets.LANGCHAIN_API_KEY }}
- name: Commit and push if changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git diff --quiet && git diff --staged --quiet || (git commit -m "📝 Add generated content for ${{ github.event.inputs.topic || vars.SCHEDULED_POST_TOPIC || 'Free Topic' }}" --no-verify && git push)