From 4dea9db4e6f299047e2804104bd051be68a6e482 Mon Sep 17 00:00:00 2001 From: shueja <32416547+shueja@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:44:22 -0800 Subject: [PATCH] Choreolib Build in CI (#234) * first test of choreolib ci * attempt to set working directory * attempt to set working directory * remove errant working-directory * add more working-directories * try copying PPLib's setup * fix yaml syntax error * format * fix choreo.h * wpiformat * fix choreoswervecommand.h * fix choreoswervecommand again * fix java artifact id * Fix extra folder in maven structure --- .github/workflows/build-choreolib-release.yml | 129 ++++++++++++++++++ .github/workflows/build-choreolib.yml | 108 +++++++++++++++ choreolib/publish.gradle | 8 +- .../cpp/choreo/lib/ChoreoSwerveCommand.cpp | 2 +- .../main/native/include/choreo/lib/Choreo.h | 16 ++- .../include/choreo/lib/ChoreoSwerveCommand.h | 2 +- 6 files changed, 252 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/build-choreolib-release.yml create mode 100644 .github/workflows/build-choreolib.yml diff --git a/.github/workflows/build-choreolib-release.yml b/.github/workflows/build-choreolib-release.yml new file mode 100644 index 000000000..0efb58e3d --- /dev/null +++ b/.github/workflows/build-choreolib-release.yml @@ -0,0 +1,129 @@ +name: Build ChoreoLib Release + +on: + workflow_dispatch: + inputs: + version: + type: string + description: The full version string, i.e. 2024.0.0-alpha-1 or 2024.1.1 + required: true + +jobs: + build-docker: + strategy: + fail-fast: false + matrix: + include: + - container: wpilib/roborio-cross-ubuntu:2024-22.04 + artifact-name: ChoreoLib-Athena + build-options: "-Ponlylinuxathena" + - container: wpilib/ubuntu-base:22.04 + artifact-name: ChoreoLib-Linux + build-options: "-Ponlylinuxx86-64" + - container: wpilib/raspbian-cross-ubuntu:bullseye-22.04 + artifact-name: ChoreoLib-Arm32 + build-options: "-Ponlylinuxarm32" + - container: wpilib/aarch64-cross-ubuntu:bullseye-22.04 + artifact-name: ChoreoLib-Arm64 + build-options: "-Ponlylinuxarm64" + name: "[ChoreoLib] Build - ${{ matrix.artifact-name }}" + runs-on: ubuntu-22.04 + container: ${{ matrix.container }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + working-directory: ./choreolib + + - name: Set version + run: sed -i "s/0.0.0/${{ github.event.inputs.version }}/g" publish.gradle + working-directory: ./choreolib + + - name: Ensure spotless is applied + run: ./gradlew spotlessApply + working-directory: ./choreolib + + - name: Build + run: ./gradlew build -PreleaseMode ${{ matrix.build-options }} + working-directory: ./choreolib + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact-name }} + path: choreolib/build/allOutputs + + build-host: + strategy: + fail-fast: false + matrix: + include: + - os: windows-2022 + artifact-name: ChoreoLib-Win64 + - os: macos-13 + artifact-name: ChoreoLib-macOS + name: "[ChoreoLib] Build - ${{ matrix.artifact-name }}" + runs-on: ${{ matrix.os }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup java + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "zulu" + + - name: Set version + run: sed -i '' "s/0.0.0/${{ github.event.inputs.version }}/g" publish.gradle + working-directory: ./choreolib + + - name: Ensure spotless is applied + run: ./gradlew spotlessApply + working-directory: ./choreolib + + - name: Build + run: ./gradlew build -Pbuildalldesktop -PreleaseMode + working-directory: ./choreolib + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact-name }} + path: choreolib/build/allOutputs + + combine: + name: "[ChoreoLib] Combine" + needs: [build-docker, build-host] + runs-on: ubuntu-22.04 + steps: + - name: Checkout build-tools + uses: actions/checkout@v4 + with: + repository: wpilibsuite/build-tools + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + path: combiner/products/build/allOutputs + + - name: Flatten Artifacts + run: rsync -a --delete combiner/products/build/allOutputs/*/* combiner/products/build/allOutputs/ + + - name: Setup java + uses: actions/setup-java@v3 + with: + java-version: "17" + distribution: "zulu" + + - name: Combine + run: ./gradlew publish -Pthirdparty + working-directory: combiner + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: ChoreoLib-Maven-v${{ github.event.inputs.version }} + path: ~/releases diff --git a/.github/workflows/build-choreolib.yml b/.github/workflows/build-choreolib.yml new file mode 100644 index 000000000..5b096e358 --- /dev/null +++ b/.github/workflows/build-choreolib.yml @@ -0,0 +1,108 @@ +name: Build Choreolib + +on: [push, pull_request] + +jobs: + build-docker: + strategy: + fail-fast: false + matrix: + include: + - container: wpilib/roborio-cross-ubuntu:2024-22.04 + artifact-name: Athena + build-options: "-Ponlylinuxathena" + # - container: wpilib/raspbian-cross-ubuntu:bullseye-22.04 + # artifact-name: Arm32 + # build-options: "-Ponlylinuxarm32" + # - container: wpilib/aarch64-cross-ubuntu:bullseye-22.04 + # artifact-name: Arm64 + # build-options: "-Ponlylinuxarm64" + - container: wpilib/ubuntu-base:22.04 + artifact-name: Linux + build-options: "" + name: "Build - ${{ matrix.artifact-name }}" + runs-on: ubuntu-latest + container: ${{ matrix.container }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + - name: Fetch all history and metadata + run: | + git config --global --add safe.directory /__w/${{ github.event.repository.name }}/${{ github.event.repository.name }} + - name: Build with Gradle + run: ./gradlew build --max-workers 1 ${{ matrix.build-options }} + working-directory: choreolib + - uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact-name }} + path: choreolib/build/allOutputs + + build-host: + env: + MACOSX_DEPLOYMENT_TARGET: 12 + strategy: + fail-fast: false + matrix: + include: + - os: windows-2022 + artifact-name: Win64 + architecture: x64 + - os: macos-12 + artifact-name: macOS + architecture: x64 + name: "Build - ${{ matrix.artifact-name }}" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Fetch all history and metadata + run: git fetch --prune --unshallow + - uses: actions/setup-java@v3 + with: + distribution: "zulu" + java-version: 17 + architecture: ${{ matrix.architecture }} + - name: Build with Gradle + run: ./gradlew build -Pbuildalldesktop + working-directory: choreolib + - uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.artifact-name }} + path: choreolib/build/allOutputs + + combine: + name: Combine + needs: [build-docker, build-host] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + repository: wpilibsuite/build-tools + - uses: actions/download-artifact@v3 + with: + path: combiner/products/build/allOutputs + - name: Flatten Artifacts + run: rsync -a --delete combiner/products/build/allOutputs/*/* combiner/products/build/allOutputs/ + - uses: actions/setup-java@v3 + with: + distribution: "zulu" + java-version: 17 + - name: Combine + if: | + !startsWith(github.ref, 'refs/tags/v') + run: ./gradlew publish -Pthirdparty + working-directory: combiner + - name: Combine (Release) + if: | + github.repository_owner == 'wpilibsuite' && + startsWith(github.ref, 'refs/tags/v') + run: | + ./gradlew publish -Pthirdparty + working-directory: combiner + - uses: actions/upload-artifact@v3 + with: + name: Maven + path: ~/releases diff --git a/choreolib/publish.gradle b/choreolib/publish.gradle index 33c10d821..9394299fc 100644 --- a/choreolib/publish.gradle +++ b/choreolib/publish.gradle @@ -44,8 +44,8 @@ ext.addTaskToCopyAllOutputs = { task -> def artifactGroupId = 'com.choreo.lib' def baseArtifactId = 'ChoreoLib' -def zipBaseName = "_GROUP_com_choreo_lib_choreolib_ID_${baseArtifactId}-cpp_CLS" -def javaBaseName = "_GROUP_com_choreo_lib_choreolib_ID_${baseArtifactId}-java_CLS" +def zipBaseName = "_GROUP_com_choreo_lib_ID_${baseArtifactId}-cpp_CLS" +def javaBaseName = "_GROUP_com_choreo_lib_ID_${baseArtifactId}-java_CLS" // C++ configuration for the future. task cppHeadersZip(type: Zip) { @@ -151,7 +151,6 @@ model { def taskList = createComponentZipTasks($.components, ['ChoreoLib'], zipBaseName, Zip, project, includeStandardZipFormat) publications { - // C++ configuration for the future. cpp(MavenPublication) { taskList.each { artifact it @@ -169,8 +168,7 @@ model { artifact sourcesJar artifact javadocJar - // artifactId = "${baseArtifactId}-java" - artifactId = baseArtifactId + artifactId = "${baseArtifactId}-java" groupId artifactGroupId version pubVersion } diff --git a/choreolib/src/main/native/cpp/choreo/lib/ChoreoSwerveCommand.cpp b/choreolib/src/main/native/cpp/choreo/lib/ChoreoSwerveCommand.cpp index 96d48612d..8d4ce1c91 100644 --- a/choreolib/src/main/native/cpp/choreo/lib/ChoreoSwerveCommand.cpp +++ b/choreolib/src/main/native/cpp/choreo/lib/ChoreoSwerveCommand.cpp @@ -27,7 +27,7 @@ void ChoreoSwerveCommand::Initialize() { // Called repeatedly when this Command is scheduled to run void ChoreoSwerveCommand::Execute() { units::second_t currentTrajTime = m_timer.Get(); - bool mirror = mirrorTrajectory(); + bool mirror = m_mirrorTrajectory(); m_outputChassisSpeeds( m_controller(m_pose(), m_traj.Sample(currentTrajTime, mirror))); } diff --git a/choreolib/src/main/native/include/choreo/lib/Choreo.h b/choreolib/src/main/native/include/choreo/lib/Choreo.h index d06aa4106..41440dde3 100644 --- a/choreolib/src/main/native/include/choreo/lib/Choreo.h +++ b/choreolib/src/main/native/include/choreo/lib/Choreo.h @@ -49,8 +49,9 @@ class Choreo { * global heading of the robot * @param outputChassisSpeeds a function that consuming the calculated robot * relative ChassisSpeeds - * @param useAllianceColor if true, mirror the trajectory along the midline of - * the field + * @param mirrorTrajectory If this returns true, the path will be mirrored to + * the opposite side, while keeping the same coordinate system origin. This + * will be called every loop during the command. * @param requirements the frc2::Requirements of the command * @return an frc2::CommandPtr containing the command that will command your * drivebase to follow a trajectory @@ -60,7 +61,8 @@ class Choreo { frc::PIDController xController, frc::PIDController yController, frc::PIDController rotationController, std::function outputChassisSpeeds, - bool useAllianceColor, frc2::Requirements requirements = {}); + std::function mirrorTrajectory, + frc2::Requirements requirements = {}); /** * Creates a CommandPtr that commands your drivebase to follow a Choreo @@ -73,8 +75,9 @@ class Choreo { * the robots position * @param outputChassisSpeeds a function that consuming the calculated robot * relative ChassisSpeeds - * @param useAllianceColor if true, mirror the trajectory along the midline of - * the field + * @param mirrorTrajectory If this returns true, the path will be mirrored to + * the opposite side, while keeping the same coordinate system origin. This + * will be called every loop during the command. * @param requirements the frc2::Requirements of the command * @return an frc2::CommandPtr containing the command that will command your * drivebase to follow a trajectory @@ -83,7 +86,8 @@ class Choreo { ChoreoTrajectory trajectory, std::function poseSupplier, ChoreoControllerFunction controller, std::function outputChassisSpeeds, - bool useAllianceColor, frc2::Requirements requirements = {}); + std::function mirrorTrajectory, + frc2::Requirements requirements = {}); /** * Creates a ChoreoControllerFunction handles the feedback of the drivebase diff --git a/choreolib/src/main/native/include/choreo/lib/ChoreoSwerveCommand.h b/choreolib/src/main/native/include/choreo/lib/ChoreoSwerveCommand.h index 9849147e6..00bd955a4 100644 --- a/choreolib/src/main/native/include/choreo/lib/ChoreoSwerveCommand.h +++ b/choreolib/src/main/native/include/choreo/lib/ChoreoSwerveCommand.h @@ -61,6 +61,6 @@ class ChoreoSwerveCommand std::function m_pose; ChoreoControllerFunction m_controller; std::function m_outputChassisSpeeds; - std::function mirrorTrajectory; + std::function m_mirrorTrajectory; }; } // namespace choreolib