name: Deploy to GitHub Pages on: # Trigger the workflow every time you push to the `main` branch push: branches: [ main ] # Allows you to run this workflow manually from the Actions tab on GitHub. workflow_dispatch: # Allow this job to clone the repo and create a page deployment permissions: contents: read pages: write id-token: write jobs: build: runs-on: ubuntu-latest steps: - name: Checkout your repository using git uses: actions/checkout@v4 - name: Install Node.js uses: actions/setup-node@v4 with: node-version: '20' cache: 'npm' - name: Install dependencies run: npm ci - name: Determine base path id: base_path run: | # If BASE_PATH secret is set, use it # Otherwise, if repo name matches owner (username.github.io), use root # Otherwise, use /repo-name if [ -n "${{ secrets.BASE_PATH }}" ]; then echo "base_path=${{ secrets.BASE_PATH }}" >> $GITHUB_OUTPUT elif [ "${{ github.repository }}" == "${{ github.repository_owner }}/${{ github.repository_owner }}.github.io" ]; then echo "base_path=" >> $GITHUB_OUTPUT else echo "base_path=/${{ github.event.repository.name }}" >> $GITHUB_OUTPUT fi - name: Build Astro site run: npm run build env: BASE_PATH: ${{ steps.base_path.outputs.base_path }} GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }} # If you have other environment variables, set them here GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Copy build-time JSON files to dist run: | # Copy JSON files from public/ to dist/ (they're written during build but after public/ is copied) if [ -f "public/build-data-pr.json" ]; then cp public/build-data-pr.json dist/build-data-pr.json echo "✓ Copied build-data-pr.json to dist/" fi if [ -f "public/build-data-pypi.json" ]; then cp public/build-data-pypi.json dist/build-data-pypi.json echo "✓ Copied build-data-pypi.json to dist/" fi if [ -f "public/build-data-contributors.json" ]; then cp public/build-data-contributors.json dist/build-data-contributors.json echo "✓ Copied build-data-contributors.json to dist/" fi - name: Upload 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 }} steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4