name: pcb_image on: push: branches: - dev # Trigger on push to 'dev' branch - main # Trigger on push to 'main' branch paths: - '.github/workflows/pcb_render.yml' # Trigger if this workflow file changes - 'KiCad/**' # Trigger if any file in the 'KiCad' directory changes jobs: render-image: name: render-image runs-on: ubuntu-latest steps: - name: Check out the repo uses: actions/checkout@v4 - name: Render PCB image uses: linalinn/kicad-render@main with: pcb_file: KiCad/RP2040-Decoder.kicad_pcb output_path: ${{ github.workspace }}/images - name: Upload images as artifact if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' uses: actions/upload-artifact@v4 with: name: pcb-images path: images/ deploy-pages-main: if: github.ref == 'refs/heads/main' # Only deploy on 'main' branch runs-on: ubuntu-latest needs: render-image permissions: pages: write id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: - name: Checkout the repository uses: actions/checkout@v4 - name: Set up git run: | git config --global user.name "github-actions" git config --global user.email "github-actions@github.com" - name: Download pcb-images artifact uses: actions/download-artifact@v4 with: name: pcb-images path: images/ - name: Stash changes before switching branches run: git stash - name: Deploy to gh-pages branch (main) run: | git fetch --all # Ensure all branches are fetched git checkout gh-pages || git checkout --orphan gh-pages # Create gh-pages if it doesn't exist git stash pop # Apply stashed changes cp -r images/* . # Copy the rendered images to the root directory git add --all git commit -m "Deploy PCB images to gh-pages" git push origin gh-pages --force # Force push to gh-pages deploy-pages-dev: if: github.ref == 'refs/heads/dev' # Only deploy on 'dev' branch runs-on: ubuntu-latest needs: render-image permissions: contents: write # To allow writing to the repository (needed for pushing changes) pages: write id-token: write environment: name: github-pages-dev url: ${{ steps.deployment.outputs.page_url }} steps: - name: Checkout the repository uses: actions/checkout@v4 - name: Set up git run: | git config --global user.name "github-actions" git config --global user.email "github-actions@github.com" - name: Checkout gh-pages-dev run: | git fetch --all # Ensure all branches are fetched git checkout gh-pages-dev - name: Download pcb-images artifact uses: actions/download-artifact@v4 with: name: pcb-images path: images/ - name: Deploy to gh-pages-dev branch (dev) run: | cp -r images/* . # Copy the rendered images to the root directory git add . git commit -m "Deploy PCB images to gh-pages-dev" git push origin gh-pages-dev --force # Force push to gh-pages-dev