Merge pull request #574 from bigbio/dev #230
This file contains hidden or 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: Auto update examples | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| setup: | |
| if: "! contains(github.event.head_commit.message, 'Update pmultiqc documentation and examples')" | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.10" | |
| - name: Generate matrix from config | |
| id: set-matrix | |
| run: | | |
| python << 'EOF' | |
| import json | |
| import os | |
| try: | |
| with open('docs/config.json', 'r') as f: | |
| config = json.load(f) | |
| projects = [{'accession': p['accession'], 'path': p['path']} for p in config.get('projects', [])] | |
| matrix = json.dumps({'include': projects}) | |
| with open(os.environ['GITHUB_OUTPUT'], 'a') as f: | |
| f.write(f'matrix={matrix}\n') | |
| except Exception as e: | |
| print(f"Error parsing config: {e}") | |
| exit(1) | |
| EOF | |
| update_examples: | |
| needs: setup | |
| if: "! contains(github.event.head_commit.message, 'Update pmultiqc documentation and examples')" | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJson(needs.setup.outputs.matrix) }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install . | |
| pip install pytest pytest-cov | |
| - name: Run update script for ${{ matrix.accession }} | |
| run: | | |
| python docs/update_examples.py --project "${{ matrix.accession }}" | |
| - name: Prepare artifact for upload | |
| run: | | |
| mkdir -p artifact_stage | |
| # Copy the entire docs directory structure maintaining relative paths | |
| rsync -avR "${{ matrix.path }}" artifact_stage/ | |
| # Ensure the parent directory structure exists | |
| mkdir -p artifact_stage/$(dirname "${{ matrix.path }}") | |
| - name: Upload changed files as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docs-changes-${{ matrix.accession }} | |
| path: artifact_stage/ | |
| retention-days: 1 | |
| create_pr: | |
| needs: [setup, update_examples] | |
| if: "! contains(github.event.head_commit.message, 'Update pmultiqc documentation and examples')" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: docs-changes-* | |
| merge-multiple: true | |
| path: . | |
| - name: Restore artifact files to correct location | |
| run: | | |
| # Move files from artifact_stage/ back to their original locations | |
| if [ -d "artifact_stage" ]; then | |
| echo "=== Restoring artifacts ===" | |
| # Copy all files from artifact_stage maintaining directory structure | |
| # rsync -R creates relative paths, so artifact_stage/docs/... should become docs/... | |
| if [ -d "artifact_stage/docs" ]; then | |
| cp -r artifact_stage/docs/* docs/ 2>/dev/null || true | |
| fi | |
| # Also handle direct paths if they exist | |
| find artifact_stage -mindepth 1 -maxdepth 1 -type d ! -name "docs" | while read dir; do | |
| dirname=$(basename "$dir") | |
| if [ -d "docs/$dirname" ]; then | |
| cp -r "$dir"/* "docs/$dirname/" 2>/dev/null || true | |
| fi | |
| done | |
| echo "=== Files restored ===" | |
| fi | |
| - name: Check if any changes were made | |
| id: check_changes | |
| run: | | |
| echo "=== Debug: Files in docs/ after download ===" | |
| ls -R docs/ 2>/dev/null || echo "docs/ directory not found or empty" | |
| echo "============================================" | |
| if [[ -n $(git status --porcelain docs/) ]]; then | |
| echo "changes_detected=true" >> $GITHUB_OUTPUT | |
| echo "Changes detected by git status" | |
| git status | |
| else | |
| echo "changes_detected=false" >> $GITHUB_OUTPUT | |
| echo "No changes detected." | |
| fi | |
| - name: Create Pull Request | |
| if: steps.check_changes.outputs.changes_detected == 'true' | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "Update pmultiqc documentation and examples" | |
| title: "Auto-update examples" | |
| body: "This PR updates the docs with the latest example output." | |
| base: main | |
| branch: dev-docs-update | |
| delete-branch: true |