Skip to content

Commit

Permalink
Download code from Wokwi projects (#7)
Browse files Browse the repository at this point in the history
* ci: Download code from wokwi projects

* ci: Donwload templates from Wokwi

* ci: Generate wokwi.toml files

* ci: Unifiy into single job
  • Loading branch information
SergioGasquez authored Aug 1, 2023
1 parent 17a37de commit 7b2ad99
Show file tree
Hide file tree
Showing 66 changed files with 75 additions and 1,391 deletions.
169 changes: 75 additions & 94 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,92 +14,56 @@ on:
workflow_dispatch:

jobs:
templates:
name: Template | ${{ matrix.target.name }}-${{ matrix.env }}
projects:
name: "${{ matrix.project.name }} | ${{ matrix.project.mcu }} | ${{ matrix.project.env }} | ${{ matrix.project.id }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
env: ["std", "nostd"]
target:
- mcu: "esp32"
name: "esp32"
- mcu: "esp32s2"
name: "esp32-s2"
- mcu: "esp32s3"
name: "esp32-s3"
- mcu: "esp32c3"
name: "esp32-c3"
- mcu: "esp32c3"
name: "esp32-rust-board"
steps:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Update ownership
run: |
sudo chown 1000:1000 -R templates
- name: Pull Docker image
run: docker image pull wokwi/builder-rust-${{ matrix.env }}-esp

- name: Test code example in Docker image (std)
if: matrix.env == 'std'
uses: addnab/docker-run-action@v3
with:
image: wokwi/builder-rust-${{ matrix.env }}-esp
options: -u esp -v ${{ github.workspace }}:/home/esp/workspace
run: |
. /home/esp/export-esp.sh
export CARGO_INCREMENTAL=0
export RUSTC_WRAPPER=$(which sccache)
cp /home/esp/workspace/templates/rust-${{ matrix.target.name }}/*.rs rust-project-${{ matrix.target.mcu }}/src/
cat /home/esp/workspace/templates/rust-${{ matrix.target.name }}/Cargo.toml > rust-project-${{ matrix.target.mcu }}/Cargo.toml
cd rust-project-${{ matrix.target.mcu }}
cargo build --release --out-dir /home/esp/workspace/templates/rust-${{ matrix.target.name }} -Z unstable-options
- name: Test code example in Docker image (nostd)
if: matrix.env == 'nostd'
uses: addnab/docker-run-action@v3
with:
image: wokwi/builder-rust-nostd-esp
options: -u esp -v ${{ github.workspace }}:/home/esp/workspace
run: |
. /home/esp/export-esp.sh
export CARGO_INCREMENTAL=0
export RUSTC_WRAPPER=$(which sccache)
cp /home/esp/workspace/templates/rust-nostd-${{ matrix.target.name }}/*.rs rust-project-${{ matrix.target.mcu }}/src/
cat /home/esp/workspace/templates/rust-nostd-${{ matrix.target.name }}/Cargo.toml > rust-project-${{ matrix.target.mcu }}/Cargo.toml
cd rust-project-${{ matrix.target.mcu }}
cargo build --release --out-dir /home/esp/workspace/templates/rust-nostd-${{ matrix.target.name }} -Z unstable-options
- name: Wokwi CI check (std)
if: matrix.env == 'std'
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: templates/rust-${{ matrix.target.name }}
timeout: 10000
expect_text: 'Hello world!'
fail_text: 'Error'

- name: Wokwi CI check (nostd)
if: matrix.env == 'nostd'
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: templates/rust-nostd-${{ matrix.target.name }}
timeout: 10000
expect_text: 'Hello world!'
fail_text: 'Error'

examples:
name: Example | ${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
example:
project:
# Templates
- name: template
id: "341952531613614675"
env: nostd
mcu: esp32
- name: template
id: "338154815612781140"
env: std
mcu: esp32
- name: template
id: "341956530834244180"
env: nostd
mcu: esp32c3
- name: template
id: "338322025101656660"
env: std
mcu: esp32c3
## Rust Board
- name: template
id: "341957109819114067"
env: nostd
mcu: esp32c3
- name: template
id: "338322111264195156"
env: std
mcu: esp32c3
- name: template
id: "341955277702038100"
env: nostd
mcu: esp32s2
- name: template
id: "338154940543271506"
env: std
mcu: esp32s2
- name: template
id: "349566517066596948"
env: nostd
mcu: esp32s3
- name: template
id: "345144250522927698"
env: std
mcu: esp32s3
# Examples
- name: blinky
id: "341952826535051858"
env: nostd
Expand Down Expand Up @@ -136,35 +100,52 @@ jobs:
- name: Checkout the repository
uses: actions/checkout@v3

- name: Get diagram
run: wget -q -O examples/${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }}/diagram.json https://wokwi.com/api/projects/${{ matrix.example.id }}/diagram.json
- name: Download project code
run: |
wget -q -O ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}.zip https://wokwi.com/api/projects/${{ matrix.project.id }}/zip
unzip ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}.zip -d ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}
- name: Create wokwi.toml (nostd)
if: matrix.project.env == 'nostd'
run: echo -e "[wokwi]\nversion = 1\nfirmware = 'rust_project_${{ matrix.project.mcu }}'\nelf = 'rust_project_${{ matrix.project.mcu }}'" > ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}/wokwi.toml
- name: Create wokwi.toml (std)
if: matrix.project.env == 'std'
run: echo -e "[wokwi]\nversion = 1\nfirmware = 'rust-project-${{ matrix.project.mcu }}'\nelf = 'rust-project-${{ matrix.project.mcu }}'" > ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}/wokwi.toml

- name: Update ownership
run: |
sudo chown 1000:1000 -R examples/${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }}
sudo chown 1000:1000 -R ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}
- name: Pull Docker image
run: docker image pull wokwi/builder-rust-${{ matrix.example.env }}-esp
run: docker image pull wokwi/builder-rust-${{ matrix.project.env }}-esp

- name: Test code example in Docker image
uses: addnab/docker-run-action@v3
with:
image: wokwi/builder-rust-${{ matrix.example.env }}-esp
image: wokwi/builder-rust-${{ matrix.project.env }}-esp
options: -u esp -v ${{ github.workspace }}:/home/esp/workspace
run: |
. /home/esp/export-esp.sh
export CARGO_INCREMENTAL=0
export RUSTC_WRAPPER=$(which sccache)
cp /home/esp/workspace/examples/${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }}/*.rs rust-project-${{ matrix.example.mcu }}/src/
cat /home/esp/workspace/examples/${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }}/Cargo.toml > rust-project-${{ matrix.example.mcu }}/Cargo.toml
cd rust-project-${{ matrix.example.mcu }}
cargo build --release --out-dir /home/esp/workspace/examples/${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }} -Z unstable-options
cp /home/esp/workspace/${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}/*.rs rust-project-${{ matrix.project.mcu }}/src/
cat /home/esp/workspace/${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}/Cargo.toml > rust-project-${{ matrix.project.mcu }}/Cargo.toml
cd rust-project-${{ matrix.project.mcu }}
cargo build --release --out-dir /home/esp/workspace/${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }} -Z unstable-options
- name: Wokwi CI check
if: matrix.project.name == 'template'
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}
timeout: 10000
expect_text: 'Hello world!'
fail_text: 'Error'

- name: Wokwi CI check
if: matrix.project.name == 'blinky'
uses: wokwi/wokwi-ci-action@v1
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: examples/${{ matrix.example.mcu }}-${{ matrix.example.env }}-${{ matrix.example.name }}_${{ matrix.example.id }}
path: ${{ matrix.project.mcu }}-${{ matrix.project.env }}_${{ matrix.project.id }}
timeout: 10000
scenario: ../blinky.test.yaml
fail_text: 'Error'
File renamed without changes.
16 changes: 0 additions & 16 deletions examples/esp32-nostd-blinky_341952826535051858/Cargo.toml

This file was deleted.

47 changes: 0 additions & 47 deletions examples/esp32-nostd-blinky_341952826535051858/main.rs

This file was deleted.

4 changes: 0 additions & 4 deletions examples/esp32-nostd-blinky_341952826535051858/wokwi.toml

This file was deleted.

25 changes: 0 additions & 25 deletions examples/esp32-std-blinky_333363577816613460/Cargo.toml

This file was deleted.

27 changes: 0 additions & 27 deletions examples/esp32-std-blinky_333363577816613460/main.rs

This file was deleted.

4 changes: 0 additions & 4 deletions examples/esp32-std-blinky_333363577816613460/wokwi.toml

This file was deleted.

16 changes: 0 additions & 16 deletions examples/esp32c3-nostd-blinky_341956526159692371/Cargo.toml

This file was deleted.

Loading

1 comment on commit 7b2ad99

@urish
Copy link
Contributor

@urish urish commented on 7b2ad99 Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Please sign in to comment.