Skip to content

Testing commit rules and GH Workflow #17

Testing commit rules and GH Workflow

Testing commit rules and GH Workflow #17

Workflow file for this run

# 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:
build-and-version:
runs-on: ubuntu-latest
# Ensure we have permission to write back to the repository when needed
permissions:
contents: write
steps:
# Check out the repository code
- uses: actions/checkout@v3
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 required Python packages
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pyyaml semver
# 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 capabilities
- name: Verify SVG conversion tool
run: |
which rsvg-convert || echo "rsvg-convert not found"
rsvg-convert --version || echo "rsvg-convert not working"
# 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
# Get current date for documentation
CURRENT_DATE=$(date +"%Y-%m-%d")
echo "CURRENT_DATE=$CURRENT_DATE" >> $GITHUB_ENV
# Update _quarto.yml with new date
python -c '
import yaml
with open("_quarto.yml", "r") as f:
config = yaml.safe_load(f)
config["date"] = "'$CURRENT_DATE'"
with open("_quarto.yml", "w") as f:
yaml.dump(config, f)
'
# Handle PDF versioning - only runs on push to main
- name: Handle PDF Versioning
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
# Create pdfs directory if needed
mkdir -p docs/pdfs
# Version the PDF if it exists
if [ -f "docs/Trollip-s-Degen-Almanack.pdf" ]; then
# Create versioned copy
cp "docs/Trollip-s-Degen-Almanack.pdf" "docs/pdfs/Trollip-s-Degen-Almanack-v${NEW_VERSION}.pdf"
# 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
# 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'
# 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"
# 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