1name: Build and test using platformio
2
3on:
4  workflow_dispatch:
5  workflow_call:
6  push:
7    paths:
8      - '**platformio**'
9  pull_request:
10    paths:
11      - '**platformio**'
12
13jobs:
14  platformio:
15    name: Build and run PlatformIO example
16    runs-on: ubuntu-latest
17    steps:
18      - name: Check out code from GitHub
19        uses: actions/checkout@v4
20        with:
21          path: nanopb
22
23      - name: Installing dependencies for local act
24        if: ${{ env.ACT }}
25        run: |
26          sudo apt update
27
28      - name: Installing common dependencies
29        run: |
30          sudo apt install -y python3-pip
31
32      - name: Install and setup PlatformIO
33        run: |
34          python3 -m venv venv
35          venv/bin/pip3 install -U platformio
36
37      - name: Build PlatformIO package
38        run: |
39          source venv/bin/activate
40          cd nanopb
41          pio package pack
42
43      - name: Example - Extract PlatformIO package to example dir
44        run: |
45          source venv/bin/activate
46          cp -R nanopb/examples/platformio example
47          mkdir -p example/lib/nanopb
48          tar -xzf nanopb/Nanopb-*.tar.gz -C example/lib/nanopb
49
50      - name: Example - Build
51        run: |
52          source venv/bin/activate
53          cd example
54          pio run
55
56      - name: Example - Run test without options
57        run: example/.pio/build/pio_without_options/program
58
59      - name: Example - Run test with options
60        run: example/.pio/build/pio_with_options/program
61
62      - name: Build in subdirectory with space characters
63        run: |
64          source venv/bin/activate
65          cp -R nanopb/examples/platformio "example with spaces"
66          mkdir -p "example with spaces/lib/nanopb"
67          tar -xzf nanopb/Nanopb-*.tar.gz -C "example with spaces/lib/nanopb"
68          cd "example with spaces"
69          pio run -e pio_with_options # ESP32 platform doesn't support spaces currently
70
71      - name: Build with default platformio.ini
72        run: |
73          source venv/bin/activate
74          mkdir -p test_default_pio_conf
75          cd test_default_pio_conf
76          pio project init
77          ln -s ../nanopb lib/nanopb
78          echo "[env:native]" >> platformio.ini
79          echo "platform = native" >> platformio.ini
80          echo "lib_deps = Nanopb" >> platformio.ini
81          echo "int main(int argc, char *argv[]){}" > src/main.cpp
82          pio run
83