|
| 1 | +--- |
| 2 | +name: Wokwi.com CI |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - '.github/workflows/wokwi_projects.yml' |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - '.github/workflows/wokwi_projects.yml' |
| 11 | + schedule: |
| 12 | + - cron: "50 7 * * *" |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + wokwi-check: |
| 17 | + name: ${{ matrix.project.name }} |
| 18 | + runs-on: ubuntu-latest |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + project: |
| 23 | + - name: "hardware-check" |
| 24 | + id: "360342886675214337" |
| 25 | + path: "intro/hardware-check" |
| 26 | + - name: http-client |
| 27 | + id: "333372159510446675" |
| 28 | + path: "intro/http-client" |
| 29 | + - name: button-interrupt |
| 30 | + id: "333374799393849940" |
| 31 | + path: "advanced/button-interrupt" |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout the repository |
| 35 | + uses: actions/checkout@v4 |
| 36 | + |
| 37 | + - name: Download project code |
| 38 | + run: | |
| 39 | + wget -q -O ${{ matrix.project.name }}.zip https://wokwi.com/api/projects/${{ matrix.project.id }}/zip |
| 40 | + unzip ${{ matrix.project.name }}.zip -d ${{ matrix.project.name }} |
| 41 | + mkdir -p ${{ matrix.project.name }}/src |
| 42 | + rm -rf ${{ matrix.project.path }}/src/*.rs |
| 43 | + cp ${{ matrix.project.name }}/*.rs ${{ matrix.project.path }}/src/ |
| 44 | + rm -rf ${{ matrix.project.path }}/Cargo.toml |
| 45 | + cp ${{ matrix.project.name }}/Cargo.toml ${{ matrix.project.path }}/Cargo.toml |
| 46 | +
|
| 47 | + - name: Create wokwi.toml |
| 48 | + run: echo -e "[wokwi]\nversion = 1\nfirmware = '${{ matrix.project.name }}/${{ matrix.project.name }}'\nelf = '${{ matrix.project.name }}/${{ matrix.project.name }}'" > ${{ matrix.project.path }}/wokwi.toml |
| 49 | + |
| 50 | + - name: Update ownership |
| 51 | + run: | |
| 52 | + sudo chown 1000:1000 -R ${{ matrix.project.path }} |
| 53 | +
|
| 54 | + - name: Pull Docker image |
| 55 | + run: docker image pull espressif/rust-std-training |
| 56 | + |
| 57 | + - name: Test code example in Docker image |
| 58 | + uses: addnab/docker-run-action@v3 |
| 59 | + with: |
| 60 | + image: espressif/rust-std-training:latest |
| 61 | + options: -u esp -v ${{ github.workspace }}:/home/esp/workspace |
| 62 | + run: | |
| 63 | + cd /home/esp/workspace/${{ matrix.project.path }} |
| 64 | + if [ -f cfg.toml.example ]; then |
| 65 | + # Rename file to cfg.toml |
| 66 | + cp cfg.toml.example cfg.toml |
| 67 | + # Replace defaults |
| 68 | + sed -i 's/wifi_ssid = "FBI Surveillance Van"/wifi_ssid = "Wokwi-GUEST"/g' cfg.toml |
| 69 | + sed -i 's/wifi_psk = "hunter2"/wifi_psk = ""/g' cfg.toml |
| 70 | + fi |
| 71 | + /home/esp/.cargo/bin/cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.path }}/${{ matrix.project.name }} -Z unstable-options |
| 72 | + rm -rf /home/esp/workspace/${{ matrix.project.path }}/target |
| 73 | +
|
| 74 | + - run: cat ${{ matrix.project.path }}/wokwi.toml |
| 75 | + |
| 76 | + - name: Wokwi CI check |
| 77 | + uses: wokwi/wokwi-ci-action@v1 |
| 78 | + with: |
| 79 | + token: ${{ secrets.WOKWI_CLI_TOKEN }} |
| 80 | + path: ${{ matrix.project.path }} |
| 81 | + timeout: 30000 |
| 82 | + scenario: ${{ github.workspace }}/.github/${{ matrix.project.name }}.test.yaml |
| 83 | + fail_text: 'Error' |
| 84 | + |
| 85 | + - name: Upload source code |
| 86 | + if: success() || failure() |
| 87 | + uses: actions/upload-artifact@v3 |
| 88 | + with: |
| 89 | + name: ${{ matrix.project.name }}_${{ matrix.project.id }} |
| 90 | + path: ${{ matrix.project.path }} |
0 commit comments