action caching #9
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 to Azure App Service | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| env: | |
| AZURE_WEBAPP_NAME: static-docs-site | |
| NODE_VERSION: '20.x' | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| # Cache Docusaurus build artifacts | |
| - name: Cache Docusaurus build folder | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| .docusaurus | |
| node_modules/.cache | |
| key: ${{ runner.os }}-docusaurus-${{ hashFiles('docs/**/*.md', 'docs/**/*.mdx', 'sidebars/**/*.js', 'docusaurus.config.js', 'package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-docusaurus- | |
| # Cache build output for unchanged content | |
| - name: Restore build cache | |
| id: cache-build-restore | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: build | |
| key: ${{ runner.os }}-build-${{ hashFiles('docs/**', 'sidebars/**', 'src/**', 'static/**', 'docusaurus.config.js', 'package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build- | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build application | |
| if: steps.cache-build-restore.outputs.cache-hit != 'true' | |
| run: | | |
| echo "No build cache found, running full build..." | |
| npm run build | |
| echo "Build completed!" | |
| - name: Skip build (using cache) | |
| if: steps.cache-build-restore.outputs.cache-hit == 'true' | |
| run: | | |
| echo "Build cache found! Skipping build step." | |
| echo "Using cached build output from previous run." | |
| # Save the build output before modifying it | |
| - name: Save build cache | |
| if: steps.cache-build-restore.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: build | |
| key: ${{ runner.os }}-build-${{ hashFiles('docs/**', 'sidebars/**', 'src/**', 'static/**', 'docusaurus.config.js', 'package-lock.json') }} | |
| - name: Prepare deployment package | |
| run: | | |
| # Create a minimal package.json for production | |
| echo '{ | |
| "name": "docs-static", | |
| "version": "1.0.0", | |
| "private": true, | |
| "dependencies": { | |
| "serve": "^14.2.0" | |
| } | |
| }' > build/package.json | |
| # Create deployment archive | |
| cd build | |
| zip -r ../deploy.zip . | |
| - name: Deploy to Azure Web App | |
| uses: azure/webapps-deploy@v2 | |
| with: | |
| app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
| publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} | |
| package: deploy.zip | |
| # This is already configured and stays between deployments: | |
| # startup-file: "npx serve build -p 8080" |