name: PlatformIO CI

permissions:
    pages: write
    id-token: write

on:
  push:
    branches:
      - '*'
    tags-ignore:
      - '*'
  pull_request:
  workflow_dispatch:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
          
      #- uses: actions/cache@v3
      #  with:
      #    path: |
      #      ~/.cache/pip
      #      ~/.platformio/.cache
      #    key: ${{ runner.os }}-pio-cyd-klipper

      - uses: actions/setup-python@v4
        with:
          python-version: '3.9'

      - name: Install PlatformIO Core
        run: pip install --upgrade platformio esptool

      - name: Build PlatformIO Project
        run: |
          python3 ci.py

      - name: Upload artifact 
        uses: actions/upload-artifact@v3
        with:
          name: firmware
          path: ./out 

      - name: Upload GitHub Page Artifact
        uses: actions/upload-pages-artifact@v2

  deploy:
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    needs: build
    if: github.event_name == 'release' && github.event.action == 'created'
    steps:
      - name: Print GitHub event name
        run: |
          echo "${{ github.event_name }}"

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v2
  