Skip to content

Commit

Permalink
Fixing dodgy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
HariSeldon23 committed Dec 5, 2024
1 parent 945ee82 commit b849e65
Showing 1 changed file with 64 additions and 55 deletions.
119 changes: 64 additions & 55 deletions .github/workflows/auto-version.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,83 @@
name: Auto Version and Deploy
# This workflow handles both PR verification and main branch versioning
# It runs build checks on PRs and only performs versioning after successful merge to main
name: Build and Version Management

# Trigger on both pull requests and pushes to main
# This ensures we verify builds before merging and handle versioning after merge
on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
version-and-deploy:
build-and-version:
runs-on: ubuntu-latest

# GitHub Actions needs explicit permission to write back to the repository
# Ensure we have permission to write back to the repository when needed
permissions:
contents: write

steps:
# Check out the repository code. Using v3 for stability and features
# Check out the repository code
- uses: actions/checkout@v3

# Set up Python environment - we need this for version management and YAML handling
with:
# Fetch complete history for versioning
fetch-depth: 0

# Set up Python environment for version management and YAML handling
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: '3.x'

# Install Python packages needed for version management and YAML processing
- name: Install dependencies
# Install required Python packages
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml semver
# Install system packages required for PDF generation and SVG handling
# Install system packages needed for PDF generation
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y librsvg2-bin texlive-xetex texlive-fonts-recommended texlive-extra-utils
# Verify SVG conversion tool is properly installed and working
# Verify SVG conversion capabilities
- name: Verify SVG conversion tool
run: |
which rsvg-convert || echo "rsvg-convert not found"
rsvg-convert --version || echo "rsvg-convert not working"
# Increment version number and store it for later use
- name: Bump version
id: bump-version
# Set up Quarto for document generation
- name: Setup Quarto
uses: quarto-dev/quarto-actions/setup@v2

# Install TinyTeX for PDF generation
- name: Install TinyTeX
run: |
quarto install tinytex
# Always perform the build check, regardless of PR or push
- name: Build Check
run: |
quarto render
# Version management - only runs on push to main, not on PRs
- name: Version Management
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
# Bump version and store for later use
python .github/scripts/bump_version.py minor
echo "NEW_VERSION=$(cat version.txt)" >> $GITHUB_ENV
# Set up the current date and update _quarto.yml
- name: Set date and version
id: set-variables
run: |
# Get current date in desired format
# Get current date for documentation
CURRENT_DATE=$(date +"%Y-%m-%d")
echo "CURRENT_DATE=$CURRENT_DATE" >> $GITHUB_ENV
# Update _quarto.yml with correct date
# Update _quarto.yml with new date
python -c '
import yaml
with open("_quarto.yml", "r") as f:
Expand All @@ -65,59 +87,46 @@ jobs:
yaml.dump(config, f)
'
# Install Quarto publishing system
- name: Setup Quarto
uses: quarto-dev/quarto-actions/setup@v2

# Install TinyTeX for PDF generation
- name: Install TinyTeX
run: |
quarto install tinytex
# Generate the book using Quarto
- name: Render Book
# Handle PDF versioning - only runs on push to main
- name: Handle PDF Versioning
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
quarto render
# Handle PDF file management - versioning and storage
- name: Handle PDF
run: |
# Create pdfs directory if it doesn't exist
# Create pdfs directory if needed
mkdir -p docs/pdfs
# Move the newly generated PDF to versioned location
# Version the PDF if it exists
if [ -f "docs/Trollip-s-Degen-Almanack.pdf" ]; then
# Copy to versioned filename
# Create versioned copy
cp "docs/Trollip-s-Degen-Almanack.pdf" "docs/pdfs/Trollip-s-Degen-Almanack-v${NEW_VERSION}.pdf"
# Create/update symbolic link for latest version
# Update latest version symlink
ln -sf "pdfs/Trollip-s-Degen-Almanack-v${NEW_VERSION}.pdf" "docs/Trollip-s-Degen-Almanack-latest.pdf"
else
echo "PDF files in docs:"
find docs -name "*.pdf"
exit 1
fi
# Set up git configuration for committing changes
- name: Prepare git credentials
# Commit changes - only runs on push to main
- name: Commit Version Updates
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.degen_almanack_version_publish }}
run: |
# Configure git
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
echo "https://[email protected]" > ~/.git-credentials
git config --global credential.helper store
# Commit and push all changes back to the repository
- name: Commit and push changes
env:
GITHUB_TOKEN: ${{ secrets.degen_almanack_version_publish }}
run: |
# Add all changes including new PDFs and version updates
git add version.txt _quarto.yml docs/
# Create commit with [skip ci] to prevent infinite loops
git commit -m "Auto version bump and build [skip ci]"
# Stage only specific files that should be versioned
git add version.txt
git add _quarto.yml
git add "docs/pdfs/Trollip-s-Degen-Almanack-v${NEW_VERSION}.pdf"
git add "docs/Trollip-s-Degen-Almanack-latest.pdf"
# Push changes back to main branch
git push origin HEAD:main
# Only commit if there are changes
if ! git diff --staged --quiet; then
git commit -m "Auto version bump to ${NEW_VERSION} [skip ci]"
git push origin HEAD:main
else
echo "No changes to commit"
fi

0 comments on commit b849e65

Please sign in to comment.