Skip to content
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

Implement CI #12

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d3c99b7
In node.py: expanded the log information for some values ​​to make it…
Parsifal22 Jun 26, 2024
1429dee
Added test _unittest_raft_leader_changes for log_replication.py
Parsifal22 Jun 28, 2024
72a28f5
Create cyraft-test.yml
Parsifal22 Jun 28, 2024
2c03446
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
7e9a1a6
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
905bf5b
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
c528b48
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
1fc0d54
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
7c4ea56
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
aaad4e8
Update cyraft-test.yml
Parsifal22 Jun 28, 2024
54e9002
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
1b8e6ae
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
244a78a
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
bf2545f
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
25ead7e
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
2b7ebf9
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
6782c37
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
24996ba
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
7c04805
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
cc3124f
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
97185c4
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
ec89abd
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
dbf9b75
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
1588993
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
eec4337
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
5505bd3
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
f368816
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
8b8df67
Fail tests for testing CI
Parsifal22 Jul 1, 2024
688a9bf
All tests pass for testing CI
Parsifal22 Jul 1, 2024
71c2706
Update cyraft-test.yml
Parsifal22 Jul 1, 2024
cf18a37
In node.py: expanded the log information for some values ​​to make it…
Parsifal22 Jun 26, 2024
1956d83
Added test _unittest_raft_leader_changes for log_replication.py
Parsifal22 Jun 28, 2024
17774d1
Fix small issues with tests
Parsifal22 Jul 1, 2024
ef7a57b
Implement CI to the code
Parsifal22 Jul 1, 2024
10bb90d
implemented the Black Code Style
Parsifal22 Jul 3, 2024
c7ac672
Added command "black . -v"
Parsifal22 Jul 3, 2024
3da3864
Updated cyraft-test.yaml
Parsifal22 Jul 3, 2024
d4cf997
Deleted "black . -v"
Parsifal22 Jul 3, 2024
a30d97a
Rewrote line: "black . --check -v"
Parsifal22 Jul 3, 2024
acd7a77
Rewrote line: "black . --check --diff --color --verbose"
Parsifal22 Jul 3, 2024
0b07efb
Added flake8 for error lines detection
Parsifal22 Jul 3, 2024
987c79d
Removed the extra line
Parsifal22 Jul 3, 2024
bc2573f
Fix term: leader only increases term on election_timeout (#18)
Parsifal22 Jul 19, 2024
558f9ad
Complete with test _unittest_raft_leader_changes() (#11)
Parsifal22 Jul 29, 2024
4d535dd
Fix small issues with tests
Parsifal22 Jul 1, 2024
62340fb
implemented the Black Code Style
Parsifal22 Jul 3, 2024
cc622cc
add line with black
Parsifal22 Jul 29, 2024
bf86b62
Added black formater to CI
Parsifal22 Jul 29, 2024
cef8487
Merge branch 'main' into test_CI
Parsifal22 Jul 29, 2024
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
96 changes: 96 additions & 0 deletions .github/workflows/cyraft-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@


# Name of the workflow, which will be displayed in the GitHub Actions dashboard
name: Cyraft application

on: [ push, pull_request ]

# Ensures that only one workflow is running at a time
concurrency:
group: ${{ github.workflow_sha }}
cancel-in-progress: true

# Set permissions to read contents, which allows the workflow to access the repository's code
permissions:
contents: read

# Define a job called "build", which will execute the steps defined below
jobs:
build:

# Run the job on an ubuntu-latest environment, which provides a fresh Ubuntu installation
runs-on: ubuntu-latest

# Define the steps for the job, which will be executed in sequence
steps:
- uses: actions/checkout@v4
with:
submodules: true # Initialize submodules to ensure all code is available, including submodules in the repository

# Set up Python 3.10 environment, which will be used to run the tests and linting
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10" # Specify the version of Python to use

# Install dependencies required for the project, including flake8 and pytest
- name: Install dependencies
run: |
# Upgrade pip to the latest version, to ensure we have the latest package manager
python -m pip install --upgrade pip

# Install flake8, which is a Python linter that checks for syntax errors and coding standards
pip install flake8
# If a requirements.txt file exists in the repository, install the dependencies specified in it
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

# Set up environment variable CYPHAL_PATH, which is used by the Cyraft application
- name: Set up Environment Variable CYPHAL_PATH
run: |
# Set CYPHAL_PATH to include custom_data_types and public_regulated_data_types directories
echo "CYPHAL_PATH=$GITHUB_WORKSPACE/demo/custom_data_types:$GITHUB_WORKSPACE/demo/public_regulated_data_types" >> $GITHUB_ENV

# Verify CYPHAL_PATH is set correctly, by printing its value
- name: Verify CYPHAL_PATH
run: echo $CYPHAL_PATH

# Source and export environment variables from my_env.sh, which sets UAVCAN environment variables
- name: Source and export my_env.sh
run: |
# Source my_env.sh to set environment variables, such as UAVCAN__NODE__ID, UAVCAN__UDP__IFACE, etc.
source $GITHUB_WORKSPACE/my_env.sh
# Export UAVCAN environment variables, so they can be used in subsequent steps
echo "UAVCAN__NODE__ID=$UAVCAN__NODE__ID" >> $GITHUB_ENV
echo "UAVCAN__UDP__IFACE=$UAVCAN__UDP__IFACE" >> $GITHUB_ENV
echo "UAVCAN__SRV__REQUEST_VOTE__ID=$UAVCAN__SRV__REQUEST_VOTE__ID" >> $GITHUB_ENV
echo "UAVCAN__DIAGNOSTIC__SEVERITY=$UAVCAN__DIAGNOSTIC__SEVERITY" >> $GITHUB_ENV

# Debug environment variables, by printing their values
- name: Debug environment variables
run: |
# Print UAVCAN environment variables for debugging purposes
echo "UAVCAN__NODE__ID=$UAVCAN__NODE__ID"
echo "UAVCAN__UDP__IFACE=$UAVCAN__UDP__IFACE"
echo "UAVCAN__SRV__REQUEST_VOTE__ID=$UAVCAN__SRV__REQUEST_VOTE__ID"
echo "UAVCAN__DIAGNOSTIC__SEVERITY=$UAVCAN__DIAGNOSTIC__SEVERITY"

# List directory for debugging, to verify the file structure
- name: List directory for debugging
run: ls -R $GITHUB_WORKSPACE/demo

# Check DSDL directories, to verify the existence of custom_data_types and public_regulated_data_types directories
- name: Check DSDL directories
run: |
ls $GITHUB_WORKSPACE/demo/custom_data_types/sirius_cyber_corp
ls $GITHUB_WORKSPACE/demo/public_regulated_data_types/uavcan/primitive

# Lint with bleck, to check for Python syntax errors and coding standards
- name: Lint with black
run: |
# Run black to format the code
black --line-length 120 .
black . --check --diff --color --verbose && flake8 --select=E901,E999,F821,F822,F823 .

# Test with pytest, to run unit tests and verify the application's functionality
- name: Test with pytest
run: pytest tests/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This feature is significant because it enables Cyphal to serve as a communicatio
- [ ] [Add name resolution service](https://github.com/OpenCyphal-Garage/cyraft/issues/3)
- [ ] [Monitor the network for online nodes](https://github.com/OpenCyphal-Garage/cyraft/issues/4)
- [ ] `.env-variables` and `my_env.sh` should be combined?
- [ ] Implement Github CI
- [x] Implement Github CI
- [x] Refactor code into `cyraft`

Questions:
Expand Down
1 change: 1 addition & 0 deletions cyraft/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def _append_entries_processing(
if self._state == RaftState.FOLLOWER:
self._change_state(RaftState.FOLLOWER) # this will reset the election timeout as well
self._term = request.log_entry[0].term


async def _send_heartbeat(self, remote_node_index: int) -> None:
"""
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.black]
line-length = 120
target-version = ['py310']
include = '''
((cyraft|tests)/.*\.pyi?$)
|
(demo/[a-z0-9_]+\.py$)
'''
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ typing_extensions==4.12.2
urllib3==2.2.2
wrapt==1.16.0
yakut==0.13.0
pylint~=2.6
black==23.1.0
3 changes: 3 additions & 0 deletions tests/raft_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Add parent directory to Python path
# Get the absolute path of the parent directory
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))

# Add the parent directory to the Python path
sys.path.append(parent_dir)
# This can be removed if setting PYTHONPATH (export PYTHONPATH=cyraft)
Expand Down Expand Up @@ -95,6 +96,8 @@ async def _unittest_raft_node_init() -> None:
assert len(raft_node._request_vote_clients) == 1
assert len(raft_node._append_entries_clients) == 1
assert raft_node._next_index == [1]
raft_node.close()
await asyncio.sleep(1)
# assert raft_node._match_index == [0]
raft_node.close()
await asyncio.sleep(1)
Expand Down