Skip to content

Mc lab 3 v14 #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/.gitignore

This file was deleted.

18 changes: 18 additions & 0 deletions .github/actions/avr_setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Get changed files list"
description: "Setup Node with caching for dependencies"
runs:
using: "composite"
steps:
- name: Set up Arduino CLI
uses: arduino/setup-arduino-cli@v2

- name: Install platform
run: |
arduino-cli core update-index
arduino-cli core install ${{ env.platform }}
shell: bash

- name: Install popular libs
run: |
arduino-cli lib install LiquidCrystal
shell: bash
13 changes: 13 additions & 0 deletions .github/actions/get_changed_files/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Get changed files list"
description: "Setup Node with caching for dependencies"
runs:
using: "composite"
steps:
- name: Get changed files list
id: get_changed_files
run: |
echo "Changed files:"
git diff --name-only ${{ github.event.pull_request.base.sha }} > changed_files.txt
cat changed_files.txt
echo "The list is saved to changed_files.txt"
shell: bash
37 changes: 0 additions & 37 deletions .github/workflows/Lab_01_CI.yml

This file was deleted.

174 changes: 174 additions & 0 deletions .github/workflows/lab-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
name: Cheking of compile Arduino sketch for AVR/AtMega

on:
pull_request:
branches: [main, master]

env:
platform: "arduino:avr"
fqbn_master: "arduino:avr:mega"
COMMIT_COUNT: $(( ${{ github.event_name == 'pull_request' && github.event.pull_request.commits || 0 }} + 1 ))

jobs:
handle_bad_branch_name:
runs-on: ubuntu-22.04
if: (contains(github.head_ref, 'mc_lab_1') || contains(github.head_ref, 'mc_lab_2') || contains(github.head_ref, 'mc_lab_3') || contains(github.head_ref, 'mc_lab_4') || contains(github.head_ref, 'mc_lab_5') || contains(github.head_ref, 'mc_lab_6') || contains(github.head_ref, 'mc_lab_7')) == false
steps:
- name: Fail the build
run: |
echo "The branch name is not correct. It should contain 'mc_lab_' prefix"
exit 1
build_labs_1_to_4:
runs-on: ubuntu-22.04
if: contains(github.head_ref, 'mc_lab_1') || contains(github.head_ref, 'mc_lab_2') || contains(github.head_ref, 'mc_lab_3') || contains(github.head_ref, 'mc_lab_4')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.COMMIT_COUNT }}

- name: Get changed files list
uses: ./.github/actions/get_changed_files

- name: Set up Arduino CLI
uses: ./.github/actions/avr_setup

- name: Compile Sketch
run: arduino-cli compile --fqbn ${{ env.fqbn_master }} --output-dir build $(grep -E '\.ino$' changed_files.txt | tail -n 1 | xargs)
# TODO: remove tail -n 1

- name: Uploud artifact
uses: actions/upload-artifact@v4
with:
name: build-artifact
path: build

build_lab_5:
runs-on: ubuntu-22.04
if: contains(github.head_ref, 'mc_lab_5')
env:
fqbn_slave: "arduino:avr:nano"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.COMMIT_COUNT }}

- name: Get changed files list
uses: ./.github/actions/get_changed_files

- name: Get master folder
run: |
cat changed_files.txt | xargs dirname | grep 'master' | grep -m 1 -vE '/(.*master.*|.*slave.*)/' > master_project.txt
echo "Master project:"
cat master_project.txt

- name: Get slave folders
run: |
cat changed_files.txt | xargs dirname | grep 'slave' | grep -vE '/(.*master.*|.*slave.*)/' > slave_projects.txt
echo "Slave projects:"
cat slave_projects.txt

- name: Check if there is at least one master and one slave project
run: |
if [ ! -s master_project.txt ] || [ ! -s slave_projects.txt ]; then
echo "There is no master or slave project"
exit 1
fi

- name: Set up Arduino CLI
uses: ./.github/actions/avr_setup

- name: Compile master
run: while read master_folder; do arduino-cli compile --fqbn ${{ env.fqbn_master }} $master_folder/*.ino; done < master_project.txt

- name: Compile slaves
run: while read slave_folder; do arduino-cli compile --fqbn ${{ env.fqbn_slave }} $slave_folder/*.ino; done < slave_projects.txt
build_lab_6:
runs-on: ubuntu-22.04
if: contains(github.head_ref, 'mc_lab_6')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.COMMIT_COUNT }}

- name: It just passes
run: echo "It just passes. It's too complex"
build_lab_7:
runs-on: ubuntu-22.04
if: contains(github.head_ref, 'mc_lab_7')
env:
register-bindings: "m2560def.inc"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.COMMIT_COUNT }}

- name: Get changed files list
uses: ./.github/actions/get_changed_files

- name: Setup AVRA Assembler
run: |
git clone https://github.com/Ro5bert/avra.git
cd avra
sudo make install

- name: Preprocess sketch - append register bindings to the top of the file
run: printf ".include \"${{ env.register-bindings }}\"\n\n" | cat - $(grep -m 1 -E '\.(asm|S)$' changed_files.txt | xargs) > pipeline_main_assembly_source_file.asm

- name: Compile Sketch
run: avra pipeline_main_assembly_source_file.asm


test_lab_1:
runs-on: ubuntu-22.04
needs: build_labs_1_to_4
if: contains(github.head_ref, 'mc_lab_1')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.COMMIT_COUNT }}

- name: Download artifact
uses: actions/download-artifact@v4
with:
name: build-artifact
path: mc_labs/mc_lab_01/build

- name: Extract Variant Number
id: extract_variant
run: |
variant=
echo "variant='$(echo "${{ github.head_ref }}" | sed -n 's/.*v\([0-9]\+\).*/\1/p')'" >> "$GITHUB_OUTPUT"

- name: Generate Test Scenario
id: generate_scenario
uses: OleksiuDatsko/get-lab-test-scenario-action@main
with:
lab_number: 1
variant_number: ${{ steps.extract_variant.outputs.variant }}
wokwi_toml_path: mc_labs/mc_lab_01/wokwi.toml
output: ${{ github.workspace }}/test_scenario.yml

- name: Run a Wokwi CI server
uses: wokwi/wokwi-ci-server-action@v1

- name: Test on Wokwi
id: test
uses: wokwi/wokwi-ci-action@v1
continue-on-error: true
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: mc_labs/mc_lab_01/
scenario: ${{ github.workspace }}/test_scenario.yml

- name: Rerun test on Wokwi
uses: wokwi/wokwi-ci-action@v1
if: steps.test.outcome == 'failure'
with:
token: ${{ secrets.WOKWI_CLI_TOKEN }}
path: mc_labs/mc_lab_01/
scenario: ${{ github.workspace }}/test_scenario.yml
Loading