build_pages #141
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: Deploy Documentation | |
| on: | |
| push: | |
| branches: | |
| - main # ηε¬δΈ»εζ―ζ¨ι | |
| workflow_dispatch: # ζε¨θ§¦ε | |
| repository_dispatch: | |
| types: [build_pages] | |
| permissions: | |
| contents: write | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # 2. δ½Ώη¨ GH_TOKEN ζεη§ζδ»εΊ TROLLSTORE | |
| - name: Checkout Private TrollScript Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ secrets.TROLLSTORE }} | |
| token: ${{ secrets.GH_TOKEN }} | |
| path: TrollScript-Private | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: 3.x | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| registry-url: 'https://registry.npmjs.org' | |
| # 3. ηζ API ζζ‘£ε NPM ε | |
| - name: Generate API Documentation and NPM Package | |
| run: | | |
| echo "π Generating API documentation..." | |
| if [ -d "TrollScript-Private/JSModulesAPI" ]; then | |
| # Generate API.md from split module directories | |
| python3 TrollScript-Private/scripts/generate_api_docs.py TrollScript-Private/JSModulesAPI/zh ./API.md | |
| python3 TrollScript-Private/scripts/generate_api_docs.py TrollScript-Private/JSModulesAPI/en ./API.en.md | |
| echo "β Generated API.md and API.en.md" | |
| # Generate NPM Package with auto-incrementing version | |
| mkdir -p npm | |
| # θ·εε½ε NPM ε ηζζ°ηζ¬ | |
| CURRENT_VERSION=$(npm view @dompling/trollscript-types version 2>/dev/null || echo "1.0.0") | |
| echo "π Current NPM version: $CURRENT_VERSION" | |
| # ζε patch ηζ¬ε·εΉΆιε’ | |
| PATCH_VERSION=$(echo $CURRENT_VERSION | cut -d. -f3) | |
| NEW_PATCH=$((PATCH_VERSION + 1)) | |
| PACKAGE_VERSION="1.0.$NEW_PATCH" | |
| echo "π New version: $PACKAGE_VERSION" | |
| python3 TrollScript-Private/scripts/generate_npm_package.py TrollScript-Private/JSModulesAPI/zh ./npm $PACKAGE_VERSION | |
| echo "β Generated NPM package (v$PACKAGE_VERSION) in npm/" | |
| else | |
| echo "β οΈ JSModulesAPI directory not found" | |
| fi | |
| # ζ£ζ₯ API ζ―ε¦ζεε | |
| - name: Check if API changed | |
| id: check_api | |
| run: | | |
| API_CHANGED="false" | |
| # Check if API.md exists and has changes | |
| if [ -f "API.md" ]; then | |
| # Compare with git to see if there are changes | |
| if ! git diff --quiet API.md 2>/dev/null; then | |
| API_CHANGED="true" | |
| fi | |
| else | |
| # If API.md doesn't exist yet, consider it as changed | |
| API_CHANGED="true" | |
| fi | |
| echo "api_changed=$API_CHANGED" >> $GITHUB_OUTPUT | |
| echo "π API changed: $API_CHANGED" | |
| # εεΈ NPM ε οΌδ» ε¨ API ζεεζΆοΌ | |
| - name: Publish NPM Package | |
| if: success() && steps.check_api.outputs.api_changed == 'true' | |
| continue-on-error: true | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| if [ ! -d "npm" ]; then | |
| echo "β οΈ Skipping NPM publish: Directory npm/ not found" | |
| exit 0 | |
| fi | |
| if [ -z "$NODE_AUTH_TOKEN" ]; then | |
| echo "β οΈ Skipping NPM publish: NODE_AUTH_TOKEN is empty. Please check if NPM_TOKEN secret is set correctly." | |
| exit 0 | |
| fi | |
| cd npm | |
| echo "π¦ Publishing to NPM..." | |
| # ε°θ―εεΈοΌζθ·ιθ――δ½δΈδΈζε·₯δ½ζ΅ | |
| if npm publish --access public 2>&1; then | |
| echo "β Published successfully" | |
| else | |
| echo "β οΈ NPM publish failed (version may already exist or token issue)" | |
| echo "βΉοΈ Continuing workflow..." | |
| exit 0 | |
| fi | |
| # 4. ε€εΆη§ζδ»εΊηζδ»Άε°ε½εδ»εΊ | |
| - name: Copy files from Private Repository | |
| run: | | |
| echo "π Starting file sync from private repository..." | |
| # Sync templates directory | |
| if [ -d "TrollScript-Private/templates" ]; then | |
| rm -rf templates | |
| cp -r TrollScript-Private/templates ./ | |
| echo "β Synced templates/" | |
| else | |
| echo "β οΈ templates/ not found in private repository" | |
| fi | |
| # Sync README.md | |
| if [ -f "TrollScript-Private/templates/README.md" ]; then | |
| cp TrollScript-Private/templates/README.md ./ | |
| echo "β Synced README.md" | |
| else | |
| echo "β οΈ README.md not found in private repository" | |
| fi | |
| # 5. ζδΊ€ζ΄ζΉε°ε½εδ»εΊ | |
| - name: Commit and Push changes | |
| if: success() | |
| run: | | |
| echo "π Checking for changes..." | |
| # Check if there are changes | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git add -A | |
| git commit -m "π Sync from private repository - $(date '+%Y-%m-%d %H:%M:%S')" | |
| git push | |
| echo "β Changes committed and pushed" | |
| else | |
| echo "βΉοΈ No changes to commit" | |
| fi | |
| - name: Install dependencies | |
| run: | | |
| pip install mkdocs-material | |
| - name: Prepare Workspace | |
| run: | | |
| mkdir -p docs | |
| cp *.md docs/ | |
| cp templates/*.md docs/ | |
| cp templates/API/*.md docs/ | |
| cp -r AppIcon.png docs/ | |
| cp -r images docs/ | |
| cp -r CNAME docs/ | |
| - name: Build and Deploy | |
| run: mkdocs gh-deploy --force |