Skip to content

Commit

Permalink
Merge pull request #327 from una-auxme/289-feature-add-automatic-code…
Browse files Browse the repository at this point in the history
…-formatting

289 feature add automatic code formatting
  • Loading branch information
JulianTrommer authored Oct 15, 2024
2 parents e82a042 + daf2255 commit 7d10c04
Show file tree
Hide file tree
Showing 85 changed files with 3,022 additions and 2,534 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.py]
max_line_length = 80
max_line_length = 88
indent_size = 4

[*.md]
Expand Down
8 changes: 2 additions & 6 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[flake8]
exclude= code/planning/src/behavior_agent/behavior_tree.py,
code/planning/src/behavior_agent/behaviours/__init__.py,
code/planning/src/behavior_agent/behaviours,
code/planning/__init__.py,
doc/development/templates/template_class_no_comments.py,
doc/development/templates/template_class.py
max-line-length = 88
extend-ignore = E203,E701
2 changes: 1 addition & 1 deletion .github/workflows/add-to-project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Add bugs to bugs project
name: Add issue to project

on:
issues:
Expand Down
90 changes: 6 additions & 84 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Build, publish and run tests
name: Build and push image

on:
push:
branches: [ 'main' ]
pull_request:
workflow_run:
workflows: ["Check code format", "Linter markdown and code"]
types:
- completed

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -38,19 +39,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Bump version and push tag
# only run on push to main
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
id: tag
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: main

- name: Get commit hash
id: hash
run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Build and push Docker image
id: build
uses: docker/build-push-action@v3
Expand All @@ -59,72 +47,6 @@ jobs:
file: ./build/docker/build/Dockerfile
push: true
# tag 'latest' and version on push to main, otherwise use the commit hash
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.new_version == '' && steps.hash.outputs.hash || steps.tag.outputs.new_version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && 'latest' || steps.hash.outputs.hash }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Output version
id: version
# take either the created tag or the commit hash
run: echo "version=${{ steps.tag.outputs.new_version == '' && steps.hash.outputs.hash || steps.tag.outputs.new_version }}" >> $GITHUB_OUTPUT
drive:
runs-on: self-hosted
needs: build-and-push-image
# run only on pull request for now
if: github.event_name == 'pull_request'
env:
AGENT_VERSION: ${{ needs.build-and-push-image.outputs.version }}
COMPOSE_FILE: ./build/docker-compose.cicd.yaml
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Print environment variables (DEBUG)
run: |
echo "AGENT_VERSION=${AGENT_VERSION}"
echo "COMPOSE_FILE=${COMPOSE_FILE}"
- name: Get commit hash
id: hash
run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Set AGENT_VERSION from hash (workaround)
run: echo "AGENT_VERSION=${{ steps.hash.outputs.hash }}" >> $GITHUB_ENV
- name: Run docker-compose
run: docker compose up --quiet-pull --exit-code-from agent
- name: Copy results
run: docker compose cp agent:/tmp/simulation_results.json .
- name: Stop docker-compose
# always run this step, to clean up even on error
if: always()
run: docker compose down -v
# add rendered JSON as comment to the pull request
- name: Add simulation results as comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# this script reads the simulation_results.json and creates a comment on the pull request with the results.
script: |
const fs = require('fs');
// read the simulation results
const results = fs.readFileSync('./simulation_results.json', 'utf8');
let resultsJson = JSON.parse(results);
// create a markdown table of the results
let resultsTable = resultsJson.values.map((values, i) => {
return `| ${resultsJson.labels[i]} | ${values} |`;
});
// create a markdown table header
let resultsTableHeader = `| Metric | Value |`;
// create a markdown table divider
let resultsTableDivider = `| --- | --- |`;
// add everything to the resultsTable
resultsTable = resultsTableHeader + '\n' + resultsTableDivider + '\n' + resultsTable.join('\n');
// add the results as a comment to the pull request
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "## Simulation results\n" + resultsTable
});
- name: Prune all images older than 30 days from self-hosted runner
run: docker image prune -a --force --filter "until=720h"
63 changes: 63 additions & 0 deletions .github/workflows/drive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Evaluate agent

on:
workflow_run:
workflows: ["Build and push image"]
types:
- completed

jobs:
drive:
runs-on: self-hosted
needs: build-and-push-image
# run only on pull request for now
if: github.event_name == 'pull_request'
env:
AGENT_VERSION: latest
COMPOSE_FILE: ./build/docker-compose.cicd.yaml
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Print environment variables (DEBUG)
run: |
echo "AGENT_VERSION=${AGENT_VERSION}"
echo "COMPOSE_FILE=${COMPOSE_FILE}"
- name: Run docker-compose
run: docker compose up --quiet-pull --exit-code-from agent
- name: Copy results
run: docker compose cp agent:/tmp/simulation_results.json .
- name: Stop docker-compose
# always run this step, to clean up even on error
if: always()
run: docker compose down -v
# add rendered JSON as comment to the pull request
- name: Add simulation results as comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# this script reads the simulation_results.json and creates a comment on the pull request with the results.
script: |
const fs = require('fs');
// read the simulation results
const results = fs.readFileSync('./simulation_results.json', 'utf8');
let resultsJson = JSON.parse(results);
// create a markdown table of the results
let resultsTable = resultsJson.values.map((values, i) => {
return `| ${resultsJson.labels[i]} | ${values} |`;
});
// create a markdown table header
let resultsTableHeader = `| Metric | Value |`;
// create a markdown table divider
let resultsTableDivider = `| --- | --- |`;
// add everything to the resultsTable
resultsTable = resultsTableHeader + '\n' + resultsTableDivider + '\n' + resultsTable.join('\n');
// add the results as a comment to the pull request
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "## Simulation results\n" + resultsTable
});
- name: Prune all images older than 30 days from self-hosted runner
run: docker image prune -a --force --filter "until=720h"
21 changes: 21 additions & 0 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check code format

on:
pull_request:
branches:
- "main"

jobs:
format:
name: Check code files format
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
# Execute the python formatter
- name: Run the python formatter
uses: addnab/docker-run-action@v3
with:
image: pyfound/black
options: -v ${{ github.workspace}}:/apps
run: black --check ./apps/
18 changes: 9 additions & 9 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: linter
name: Linter markdown and code

on: pull_request
on:
pull_request:
branches:
- "main"

jobs:
linter:
Expand All @@ -13,16 +16,13 @@ jobs:
- name: Run the markdown linter
uses: addnab/docker-run-action@v3
with:
image: peterdavehello/markdownlint:0.32.2
options: -v ${{ github.workspace }}:/md
run: |
markdownlint .
image: peterdavehello/markdownlint:0.32.2
options: -v ${{ github.workspace }}:/md
run: markdownlint .
# Execute the python linter (executes even if the previous step failed)
- name: Run the python linter
if: always()
uses: addnab/docker-run-action@v3
with:
image: alpine/flake8
options: -v ${{ github.workspace }}:/apps
run: |
flake8 code
run: flake8 .
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"bierner.markdown-mermaid",
"richardkotze.git-mob",
"ms-vscode-remote.remote-containers",
"valentjn.vscode-ltex"
"valentjn.vscode-ltex",
"ms-python.black-formatter"
]
}
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"githubIssues.issueBranchTitle": "${issueNumber}-${sanitizedIssueTitle}",
"githubIssues.queries": [

{
"label": "My Issues",
"query": "default"
Expand All @@ -23,8 +22,9 @@
"docker.commands.composeUp": [
{
"label": "Compose Up",
"template": "xhost +local: && ${composeCommand} ${configurationFile} up"
"template": "xhost +local: && USERNAME=$(whoami) USER_UID=$(id -u) USER_GID=$(id -g) ${composeCommand} ${configurationFile} up"
}
],
"workbench.iconTheme": "vscode-icons"
"workbench.iconTheme": "vscode-icons",
"editor.formatOnSave": true
}
7 changes: 4 additions & 3 deletions build/agent_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ services:
agent:
build:
dockerfile: build/docker/agent/Dockerfile
args:
- USER_UID=${DOCKER_HOST_UNIX_UID:-1000}
- USER_GID=${DOCKER_HOST_UNIX_GID:-1000}
context: ../
args:
USERNAME: ${USERNAME}
USER_UID: ${USER_UID}
USER_GID: ${USER_GID}
init: true
tty: true
shm_size: 2gb
Expand Down
12 changes: 7 additions & 5 deletions build/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# compose file for the development without a driving vehicle
# "interactive" development without a car
include:
- roscore_service.yaml

services:
agent-dev:
build:
dockerfile: build/docker/agent-dev/Dockerfile
context: ../
args:
- USER_UID=${DOCKER_HOST_UNIX_UID:-1000}
- USER_GID=${DOCKER_HOST_UNIX_GID:-1000}
USERNAME: ${USERNAME}
USER_UID: ${USER_UID}
USER_GID: ${USER_GID}
init: true
tty: true
shm_size: 2gb
Expand All @@ -23,6 +27,4 @@ services:
- DISPLAY=${DISPLAY}
network_mode: host
privileged: true
entrypoint: ["/dev_entrypoint.sh"]
command: bash

command: bash -c "sudo chown -R ${USER_UID}:${USER_GID} ../ && sudo chmod -R a+w ../ && bash"
2 changes: 1 addition & 1 deletion build/docker-compose.devroute-distributed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
extends:
file: agent_service.yaml
service: agent
command: bash -c "sleep 10 && roslaunch agent/launch/dev.launch"
command: bash -c "sleep 10 && sudo chown -R ${USER_UID}:${USER_GID} ../ && sudo chmod -R a+w ../ && roslaunch agent/launch/dev.launch"
environment:
- CARLA_SIM_HOST=<carla_server_ip_address>
- ROUTE=/workspace/code/routes/routes_simple.xml
Expand Down
2 changes: 1 addition & 1 deletion build/docker-compose.devroute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ services:
service: agent
environment:
- ROUTE=/workspace/code/routes/routes_simple.xml
command: bash -c "sleep 10 && sudo chown -R carla:carla ../code/ && sudo chmod -R a+w ../code/ && python3 /opt/leaderboard/leaderboard/leaderboard_evaluator.py --debug=0 --routes=$${ROUTE} --agent=/workspace/code/agent/src/agent/agent.py --host=$${CARLA_SIM_HOST} --track=MAP"
command: bash -c "sleep 10 && sudo chown -R ${USER_UID}:${USER_GID} ../ && sudo chmod -R a+w ../ && python3 /opt/leaderboard/leaderboard/leaderboard_evaluator.py --debug=0 --routes=$${ROUTE} --agent=/workspace/code/agent/src/agent/agent.py --host=$${CARLA_SIM_HOST} --track=MAP"
2 changes: 1 addition & 1 deletion build/docker-compose.leaderboard-distributed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
extends:
file: agent_service.yaml
service: agent
command: bash -c "sleep 10 && sudo chown -R carla:carla ../code/ && sudo chmod -R a+w ../code/ && python3 /opt/leaderboard/leaderboard/leaderboard_evaluator.py --debug=0 --routes=$${ROUTE} --agent=/workspace/code/agent/src/agent/agent.py --host=$${CARLA_SIM_HOST} --track=MAP"
command: bash -c "sleep 10 && sudo chown -R ${USER_UID}:${USER_GID} ../ && sudo chmod -R a+w ../ && python3 /opt/leaderboard/leaderboard/leaderboard_evaluator.py --debug=0 --routes=$${ROUTE} --agent=/workspace/code/agent/src/agent/agent.py --host=$${CARLA_SIM_HOST} --track=MAP"
environment:
- CARLA_SIM_HOST=<carla_server_ip_address>

Expand Down
2 changes: 1 addition & 1 deletion build/docker-compose.leaderboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
extends:
file: agent_service.yaml
service: agent
command: bash -c "sleep 10 && sudo chown -R carla:carla ../code/ && sudo chmod -R a+w ../code/ && python3 /opt/leaderboard/leaderboard/leaderboard_evaluator.py --debug=0 --routes=$${ROUTE} --agent=/workspace/code/agent/src/agent/agent.py --host=$${CARLA_SIM_HOST} --track=MAP"
command: bash -c "sleep 10 && sudo chown -R ${USER_UID}:${USER_GID} ../ && sudo chmod -R a+w ../ && python3 /opt/leaderboard/leaderboard/leaderboard_evaluator.py --debug=0 --routes=$${ROUTE} --agent=/workspace/code/agent/src/agent/agent.py --host=$${CARLA_SIM_HOST} --track=MAP"
6 changes: 6 additions & 0 deletions build/docker-compose.linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ services:
volumes:
- ../:/apps

black:
image: pyfound/black
command: black --check ./apps/
volumes:
- ../:/apps

mdlint:
image: peterdavehello/markdownlint:0.32.2
command: markdownlint .
Expand Down
16 changes: 2 additions & 14 deletions build/docker/agent-dev/dev_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
#!/bin/bash
set -e

# Source ROS setup
source /opt/ros/noetic/setup.bash

# Source the catkin workspace setup
source /catkin_ws/devel/setup.bash

# Set up any additional environment variables if needed
export CARLA_ROOT=/opt/carla
export SCENARIO_RUNNER_ROOT=/opt/scenario_runner
export LEADERBOARD_ROOT=/opt/leaderboard

# Execute the command passed to the script, or start a bash session if no command was given
if [ $# -eq 0 ]; then
exec bash
else
exec "$@"
fi
exec "$@"
Loading

0 comments on commit 7d10c04

Please sign in to comment.