Build static API #32
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: Build static API | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: pages | |
| cancel-in-progress: false | |
| on: | |
| push: | |
| branches: [ main, master ] | |
| paths: | |
| - 'scripts/**' | |
| - 'data/**' | |
| - 'public/**' | |
| - 'docs/**' | |
| - 'mkdocs.yml' | |
| - 'requirements.txt' | |
| - 'package.json' | |
| - '.github/workflows/build.yml' | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: 'Force rebuild (ignore auto flags)' | |
| required: false | |
| default: 'false' | |
| schedule: | |
| - cron: '0 */6 * * *' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Setup Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: '3.x' | |
| - name: Install MkDocs and dependencies | |
| run: | | |
| pip install -r requirements.txt | |
| - name: Build (check changes) | |
| id: check | |
| run: | | |
| npm run check || echo "CHANGED=$?" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - name: Generate docs markdown from API | |
| if: ${{ steps.check.outputs.CHANGED == '2' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }} | |
| run: | | |
| node scripts/build.js --docs-md-only | |
| - name: Build MkDocs documentation | |
| if: ${{ steps.check.outputs.CHANGED == '2' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }} | |
| run: | | |
| npm run docs:build | |
| - name: Build API data | |
| if: ${{ steps.check.outputs.CHANGED == '2' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }} | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.force }}" = "true" ]; then | |
| node scripts/build.js --api-only --force | |
| else | |
| node scripts/build.js --api-only | |
| fi | |
| - name: Commit and push changes | |
| if: ${{ steps.check.outputs.CHANGED == '2' || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }} | |
| id: commit | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add dist | |
| DT=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
| # Set commit message based on trigger event | |
| if [ "${{ github.event_name }}" = "push" ]; then | |
| TRIGGER_MSG="triggered by push to ${{ github.ref_name }}" | |
| elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| if [ "${{ inputs.force }}" = "true" ]; then | |
| TRIGGER_MSG="triggered by manual dispatch (force rebuild)" | |
| else | |
| TRIGGER_MSG="triggered by manual dispatch" | |
| fi | |
| elif [ "${{ github.event_name }}" = "schedule" ]; then | |
| TRIGGER_MSG="triggered by scheduled run" | |
| else | |
| TRIGGER_MSG="triggered by ${{ github.event_name }}" | |
| fi | |
| COMMIT_MSG="📦 chore(dist): update static API - ${TRIGGER_MSG} [${DT}]" | |
| git commit -m "${COMMIT_MSG}" | |
| git push | |
| echo "COMMITTED=true" >> $GITHUB_OUTPUT | |
| echo "COMMIT_MESSAGE=${COMMIT_MSG}" >> $GITHUB_OUTPUT | |
| else | |
| echo "No changes to commit" | |
| echo "COMMITTED=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check for release trigger in commit message | |
| if: ${{ steps.commit.outputs.COMMITTED == 'true' }} | |
| id: release_check | |
| run: | | |
| # Check if the latest commit message contains release keywords | |
| LATEST_COMMIT_MSG=$(git log -1 --pretty=format:"%s") | |
| echo "Latest commit: $LATEST_COMMIT_MSG" | |
| if echo "$LATEST_COMMIT_MSG" | grep -iE '\[release\]|release:|🚀.*release' > /dev/null; then | |
| echo "Release trigger found in commit message" | |
| echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No release trigger found in commit message" | |
| echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate version and create release | |
| if: ${{ steps.commit.outputs.COMMITTED == 'true' && steps.release_check.outputs.SHOULD_RELEASE == 'true' }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Generate timestamp-based version number | |
| VERSION="v$(date -u +"%Y.%m.%d.%H%M")" | |
| echo "Generated version: $VERSION" | |
| # Create git tag | |
| git tag $VERSION | |
| git push origin $VERSION | |
| # Get recent commit messages for release notes | |
| RECENT_COMMITS=$(git log --oneline -10 --pretty=format:"- %s" | head -20) | |
| # Create release notes | |
| cat > release_notes.md << EOF | |
| ## 🚀 Automated Release $VERSION | |
| **Build Time:** $(date -u +"%Y-%m-%d %H:%M:%S UTC") | |
| **Triggered By:** ${{ github.event_name }} | |
| ### 📋 Recent Changes | |
| $RECENT_COMMITS | |
| ### 🔗 Usage | |
| For complete API documentation and endpoints, visit: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }} | |
| > This version is automatically built and released via GitHub Actions | |
| EOF | |
| # Create release using GitHub CLI | |
| gh release create $VERSION \ | |
| --title "🚀 LLM Metadata API $VERSION" \ | |
| --notes-file release_notes.md \ | |
| --latest | |
| - name: Upload Pages artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: dist | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| permissions: | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |