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

ci: add create-ros2-package CI and template files #44

Merged
merged 2 commits into from
Jun 19, 2024
Merged
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
81 changes: 81 additions & 0 deletions .github/workflows/create-ros2-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: create-ros2-package

on:
workflow_dispatch:
inputs:
package-name:
description: "Name of the ROS 2 package to create"
required: true
type: string
maintainer-email:
description: "Email of the maintainer"
required: true
type: string
maintainer-name:
description: "Name of the maintainer"
required: true
type: string

jobs:
create-package:
runs-on: ubuntu-latest
steps:
- name: Generate token
id: generate-token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.PRIVATE_KEY }}

- name: Check out repository
uses: actions/checkout@v4

- name: Create ROS 2 package
run: |
if [ -d ${{ inputs.package-name }} ]; then
echo "Package ${{ inputs.package-name }} already exists."
exit 1
fi

mkdir ${{ inputs.package-name}} && cd ${{ inputs.package-name}}

if [[ "${{ inputs.package-name }}" != *_msgs ]]; then
mkdir src && touch src/.gitkeep
mkdir include/${{ inputs.package-name}} && touch include/${{ inputs.package-name}}/.gitkeep
mkdir launch && touch launch/.gitkeep
cp ../.template-package/.CMakeLists.txt ./CMakeLists.txt
cp ../.template-package/.package.xml ./package.xml
else
mkdir msg && touch msg/.gitkeep
cp ../.template-interface-package/.CMakeLists.txt ./CMakeLists.txt
cp ../.template-interface-package/.package.xml ./package.xml
fi

sed 's/__PACKAGE_NAME__/package-name/g' ./CMakeLists.txt > "./CMakeLists.txt.tmp"
mv "./CMakeLists.txt.tmp" "./CMakeLists.txt"
sed -e 's/__PACKAGE_NAME__/package-name/g' -e 's/__MAINTAINER_EMAIL__/maintainer-email/g' -e 's/__MAINTAINER_NAME__/maintainer-name/g' ./package.xml > "./package.xml.tmp"
mv "./package.xml.tmp" "./package.xml"

- name: Create PR
id: create-pr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ steps.generate-token.outputs.token }}
base: ${{ github.event.repository.default_branch }}
branch: create-package-${{ inputs.package-name }}
title: "feat: create ${{ inputs.package-name }} package"
commit-message: "feat: create ${{ inputs.package-name }} package"
body: "Create ${{ inputs.package-name }} package."
signoff: true
delete-branch: true

- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.create-pr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.create-pr.outputs.pull-request-url }}"

- name: Enable auto-merge
if: ${{ steps.create-pr.outputs.pull-request-operation == 'created' }}
run: gh pr merge --squash --auto "${{ steps.create-pr.outputs.pull-request-number }}"
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
19 changes: 19 additions & 0 deletions .template-interface-package/.CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.5)
project(__PACKAGE_NAME__)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
DEPENDENCIES
)

ament_package()
19 changes: 19 additions & 0 deletions .template-interface-package/.package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>__PACKAGE_NAME__</name>
<version>0.0.0</version>
<description>The __PACKAGE_NAME__ package</description>
<maintainer email="__MAINTAINER_EMAIL__">__MAINTAINER_NAME__</maintainer>

<license>Apache 2</license>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<member_of_group>rosidl_interface_packages</member_of_group>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
21 changes: 21 additions & 0 deletions .template-package/.CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.5)
project(__PACKAGE_NAME__)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()

ament_auto_package(INSTALL_TO_SHARE
launch
)
16 changes: 16 additions & 0 deletions .template-package/.package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>__PACKAGE_NAME__</name>
<version>0.0.0</version>
<description>The __PACKAGE_NAME__ package</description>
<maintainer email="__MAINTAINER_EMAIL__">__MAINTAINER_NAME__</maintainer>

<license>Apache 2</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading