diff --git a/.github/workflows/pcb_render.yaml b/.github/workflows/pcb_render.yaml new file mode 100644 index 0000000..4ae4145 --- /dev/null +++ b/.github/workflows/pcb_render.yaml @@ -0,0 +1,74 @@ +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: + output_path: ${{ github.workspace }}/images + + - name: Commit and push rendered images to the repository + if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/main' # Run on both dev and main branches + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git add images + git commit -m "Add rendered PCB images" + git push origin ${{ github.ref }} # Push to the same branch that triggered the workflow + + 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: Deploy to GitHub Pages (main) + id: deployment + uses: actions/deploy-pages@v2 + with: + branch: main # Ensure deployment is for the 'main' branch + folder: images # Specify the folder to deploy (can be images or any other folder) + + deploy-pages-dev: + if: github.ref == 'refs/heads/dev' # Only deploy on 'dev' branch + runs-on: ubuntu-latest + needs: render-image + + permissions: + pages: write + id-token: write + + environment: + name: github-pages-dev + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Deploy to GitHub Pages (dev) + id: deployment + uses: actions/deploy-pages@v2 + with: + branch: dev # Ensure deployment is for the 'dev' branch + folder: images # Specify the folder to deploy (can be images or any other folder) diff --git a/.github/workflows/render-pcbdraw.yml b/.github/workflows/render-pcbdraw.yml deleted file mode 100644 index a2d92ef..0000000 --- a/.github/workflows/render-pcbdraw.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: Render KiCad PCB with pcbdraw - -on: - push: - branches: - - dev - paths: - - '.github/workflows/render-pcbdraw.yml' # Trigger if workflow file changes - - 'KiCad/**' # Trigger if any file in KiCad directory changes - workflow_dispatch: - -jobs: - render-pcbdraw: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install KiCad 8.0.6 and Dependencies - run: | - # Install required tools - sudo apt-get update - sudo apt-get install -y xvfb xdotool inkscape librsvg2-bin # Add librsvg for compatibility - - # Start Xvfb with dynamic display if :99 is occupied - DISPLAY_NUMBER=99 - if [ -f /tmp/.X${DISPLAY_NUMBER}-lock ]; then - rm -f /tmp/.X${DISPLAY_NUMBER}-lock - fi - Xvfb :${DISPLAY_NUMBER} -screen 0 1024x768x16 & - echo "Started Xvfb on DISPLAY=:$DISPLAY_NUMBER" - - # Add KiCad PPA and install KiCad - sudo add-apt-repository --yes ppa:kicad/kicad-8.0-releases - sudo apt-get update - sudo apt-get install -y kicad=8.0.6-0* kicad-footprints kicad-packages3d kicad-symbols python3-wxgtk4.0 python3-pip - - # Install pcbdraw and fix mistune compatibility - pip install pcbdraw - pip install "mistune<3" - - - name: Render PCB Image - env: - PYTHONPATH: /usr/lib/kicad/lib/python3/dist-packages - DISPLAY: :99 # Use Xvfb DISPLAY - run: | - # Ensure required tools are in PATH - if ! command -v inkscape >/dev/null 2>&1 && ! command -v rsvg-convert >/dev/null 2>&1; then - echo "Error: Neither inkscape nor rsvg-convert found in PATH" - exit 1 - fi - - # Render the PCB - mkdir -p docs/images - pcbdraw render KiCad/RP2040-Decoder.kicad_pcb docs/images/pcb_render.png - - - name: Configure Git - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" - - - name: Commit and Push Rendered Image - run: | - git add docs/images/pcb_render.png - git commit -m "Update PCB render image" - git push origin dev - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}