Daily Build and Deploy #375
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: Daily Build and Deploy | |
on: | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
- cron: "30 10 * * *" # This corresponds to 6:30ET assuming the server timezone is UTC | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Set environment variable from secret | |
- name: Set OPENAI_API_KEY environment variable | |
env: | |
OPENAI_API_SECRET: ${{ secrets.OPENAI_API_KEY }} | |
GCP_CREDENTIALS_JSON: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} | |
run: | | |
echo $GCP_CREDENTIALS_JSON > /tmp/credentials.json | |
echo "OPENAI_API_KEY=$OPENAI_API_SECRET" >> $GITHUB_ENV | |
echo "GOOGLE_APPLICATION_CREDENTIALS=/tmp/credentials.json" >> $GITHUB_ENV | |
# Step 2: Checkout repo recursively | |
- name: Checkout repository | |
if: github.event_name == 'pull_request' | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref }} | |
- name: Checkout repository | |
if: github.event_name != 'pull_request' | |
uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
# Step 3: Install Hugo, Python 3.11 and Poetry | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v3 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
# Step 4: Run poetry command | |
- name: Run poetry command | |
run: | | |
poetry install | |
poetry run add | |
# Step 5: Build the site and push to GitHub Pages | |
- name: Build Hugo Site | |
run: | | |
cd maiasahi | |
hugo --minify | |
cd .. | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./maiasahi/public | |
# Step 6: Add all files, commit, and push | |
- name: Commit and push changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "Automated update from GitHub Actions" || echo "No changes to commit" | |
git push | |
# Build job |