diff --git a/.github/workflows/clean-old-images.yml b/.github/workflows/clean-old-images.yml new file mode 100644 index 0000000..83c4991 --- /dev/null +++ b/.github/workflows/clean-old-images.yml @@ -0,0 +1,26 @@ +name: Clean Old Docker Image + +on: + workflow_dispatch: + +jobs: + cleanup-old-images: + runs-on: ubuntu-latest + permissions: + packages: write + deployments: write + statuses: write + + steps: + - name: Log in to GHCR + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Purge untagged images + uses: dataaxiom/ghcr-cleanup-action@v1 + with: + keep-n-untagged: 0 + dry-run: false \ No newline at end of file diff --git a/.github/workflows/colcon-test-docker.yml b/.github/workflows/colcon-test-docker.yml index e58b710..370926a 100644 --- a/.github/workflows/colcon-test-docker.yml +++ b/.github/workflows/colcon-test-docker.yml @@ -8,11 +8,13 @@ on: workflow_dispatch: jobs: - build-and-push: + spin-up-and-test: runs-on: ubuntu-latest permissions: contents: read packages: write + checks: write + id-token: write environment: name: docker-image @@ -27,24 +29,42 @@ jobs: - name: Checkout repository uses: actions/checkout@v5 + - name: Log in to GHCR + uses: docker/login-action@v4 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Folder for Binding Results + run: mkdir -m 777 -p $GITHUB_WORKSPACE/log + + - name: Pull Docker Image + run: | + docker pull ghcr.io/ref-ras/ros2:latest + # spin up docker compose service ros2 and execute colcon test - name: Execute Colcon Tests run: | docker compose run --rm ros2-test bash -c " source /opt/ros/\$ROS_DISTRO/setup.bash && - sudo uv pip install pytest-github-actions-annotate-failures && + cd /workspace/ros2_ws && colcon build && + source install/setup.bash && colcon test --event-handlers console_cohesion+ && - colcon test-result --all + colcon test-result --all && + sudo cp /workspace/ros2_ws/build/rviz_marker_publisher/pytest.xml /workspace/ros2_ws/src/rviz_marker_publisher " # publish test report - name: Publish Test Report Dashboard - uses: mikepenz/action-junit-report@v4 - if: always() # ensures the UI loads even if tests fail + uses: mikepenz/action-junit-report@v6 + if: success() || failure() # always run even if the previous step fails with: - report_paths: 'build/**/test_results/**/*.xml' # path where colcon stores pytest XML reports + # report_paths: '**/build/test-results/test/TEST-*.xml' + report_paths: '**/pytest.xml' # clean up resources to prevent leaks - name: Tear Down Containers if: always() - run: docker compose down --volumes + run: | + docker compose down --volumes diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml index ad3d71c..a18fe5f 100644 --- a/.github/workflows/docker-build-and-push.yml +++ b/.github/workflows/docker-build-and-push.yml @@ -3,10 +3,14 @@ name: Docker Compose Build and Push on: workflow_dispatch: inputs: - environment: - description: 'Target Environment' + docker_image: + type: choice + description: 'Docker Image' required: true - default: 'docker-image' + default: 'ros2' + options: + - ros2 + - moveit2 jobs: build-and-push: @@ -34,11 +38,11 @@ jobs: # compile the Docker images - name: Build Docker Compose Images - run: docker compose build moveit2 ros2 + run: docker compose build ${{ inputs.docker_image }} # spin up the containers to ensure they start up successfully - name: Test Start Containers - run: docker compose up moveit2 ros2 -d --wait + run: docker compose up ${{ inputs.docker_image }} -d --wait # check container statuses and ensure none have exited with errors - name: Verify Container Statuses @@ -66,17 +70,6 @@ jobs: # push using the image name defined in docker-compose.yml, only runs when code is merged to main - name: Push image with Docker Compose to GHCR - if: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }} - run: docker compose push moveit2 ros2 + # if: ${{ github.ref == 'refs/heads/main' && github.event_name != 'pull_request' }} + run: docker compose push ${{ inputs.docker_image }} - cleanup-old-images: - needs: build-and-push - runs-on: ubuntu-latest - permissions: - packages: write - steps: - - name: Purge untagged images - uses: dataaxiom/ghcr-cleanup-action@v1 - with: - keep-n-untagged: 0 - dry-run: false \ No newline at end of file diff --git a/.github/workflows/remove-deployments.yml b/.github/workflows/remove-deployments.yml index d8e9019..2169095 100644 --- a/.github/workflows/remove-deployments.yml +++ b/.github/workflows/remove-deployments.yml @@ -21,10 +21,12 @@ jobs: - name: Inactivaate and delete deployments env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + OWNER: ${{ github.repository_owner }} + REPO: ${{ github.event.repository.name }} run: | # 1. Fetch all deployment IDs for the current repository echo "Fetching deployments..." - DEPLOYMENTS=$(gh api repos/${{ github.repository }}/deployments --paginate -q '.[].id') + DEPLOYMENTS=$(gh api repos/$OWNER/$REPO/deployments --paginate -q '.[].id') if [ -z "$DEPLOYMENTS" ]; then echo "No deployments found." @@ -35,18 +37,17 @@ jobs: for DEPLOYMENT_ID in $DEPLOYMENTS; do echo "Processing Deployment ID: $DEPLOYMENT_ID" - # Formulate the API URL for this specific deployment - API_URL="repos/${{ github.repository }}/deployments/$DEPLOYMENT_ID" - # Step A: Inactivate the deployment by setting its status to 'inactive' - # (GitHub requires a deployment to be inactive or have no active statuses before deletion) - gh api repos/$API_URL/deployments/$id/statuses \ - -X POST -H "Accept: application/vnd.github.ant-man-preview+json" -f state='inactive' \ - --silent || true; + # Note: The gh api command automatically fills in the domain, just start with /repos + gh api "/repos/$OWNER/$REPO/deployments/$DEPLOYMENT_ID/statuses" \ + -X POST \ + -H "Accept: application/vnd.github.ant-man-preview+json" \ + -F state="inactive" \ + --silent || true # Step B: Delete the deployment record echo "Deleting Deployment ID: $DEPLOYMENT_ID..." - gh api repos/$API_URL/deployments/$id -X DELETE; + gh api "/repos/$OWNER/$REPO/deployments/$DEPLOYMENT_ID" -X DELETE done echo "Cleanup complete!" diff --git a/README.md b/README.md index 6d336b2..24d1dca 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ ![Visualization Topic](https://badgen.net/badge/topic/Visualization/orange?icon=github) [![License: BSD NON-AI](https://badgen.net/badge/license/BSD-3%20NON-AI?icon=github)](https://github.com/non-ai-licenses/non-ai-licenses/blob/main/NON-AI-BSD3) -[![Docker Compose Build and Deploy](https://github.com/REF-RAS/rviz_marker_tools/actions/workflows/docker-build.yml/badge.svg)](https://github.com/REF-RAS/rviz_marker_tools/actions/workflows/docker-build.yml) -[![Build Sphinx and Deploy](https://github.com/REF-RAS/rviz_marker_tools/actions/workflows/sphinx.yml/badge.svg)](https://github.com/REF-RAS/rviz_marker_tools/actions/workflows/sphinx.yml) +[![Docker Compose Build and Push](https://github.com/REF-RAS/rviz_marker_publisher/actions/workflows/docker-build-and-push.yml/badge.svg)](https://github.com/REF-RAS/rviz_marker_publisher/actions/workflows/docker-build-and-push.yml) +[![Colcon Test Package in Container](https://github.com/REF-RAS/rviz_marker_publisher/actions/workflows/colcon-test-docker.yml/badge.svg)](https://github.com/REF-RAS/rviz_marker_publisher/actions/workflows/colcon-test-docker.yml) +[![Build Sphinx and Deploy](https://github.com/REF-RAS/rviz_marker_publisher/actions/workflows/sphinx.yml/badge.svg)](https://github.com/REF-RAS/rviz_marker_publisher/actions/workflows/sphinx.yml) ## Introduction diff --git a/docker/compose.yaml b/docker/compose.yaml index 85a7473..7c59f75 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -39,11 +39,13 @@ services: ros2-test: extends: service: ros2 - working_dir: ~/ros2_ws + container_name: ros2-test + working_dir: /workspace/ros2_ws environment: - GITHUB_ACTIONS=true volumes: - - .:/workspace/ros2_ws/src/rviz_marker_publisher:rw + # the working directory is docker, so .. going back to the repository root + - ${GITHUB_WORKSPACE}:/workspace/ros2_ws/src/rviz_marker_publisher:rw # service: moveit2 image is based on FROM moveit/moveit2:jazzy-release moveit2: