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@v2
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          pip3 install -U platformio
35          export PATH=~/.local/bin:$PATH
36
37      - name: Build PlatformIO package
38        run: |
39          cd nanopb
40          pio package pack
41
42      - name: Example - Extract PlatformIO package to example dir
43        run: |
44          cp -R nanopb/examples/platformio example
45          mkdir -p example/lib/nanopb
46          tar -xzf nanopb/Nanopb-*.tar.gz -C example/lib/nanopb
47
48      - name: Example - Build
49        run: |
50          cd example
51          pio run
52
53      - name: Example - Run test without options
54        run: example/.pio/build/pio_without_options/program
55
56      - name: Example - Run test with options
57        run: example/.pio/build/pio_with_options/program
58
59      - name: Build in subdirectory with space characters
60        run: |
61          cp -R nanopb/examples/platformio "example with spaces"
62          mkdir -p "example with spaces/lib/nanopb"
63          tar -xzf nanopb/Nanopb-*.tar.gz -C "example with spaces/lib/nanopb"
64          cd "example with spaces"
65          pio run -e pio_with_options # ESP32 platform doesn't support spaces currently
66
67      - name: Build with default platformio.ini
68        run: |
69          mkdir -p test_default_pio_conf
70          cd test_default_pio_conf
71          pio project init
72          ln -s ../nanopb lib/nanopb
73          echo "[env:native]" >> platformio.ini
74          echo "platform = native" >> platformio.ini
75          echo "lib_deps = Nanopb" >> platformio.ini
76          echo "int main(int argc, char *argv[]){}" > src/main.cpp
77          pio run
78