From ea8f19ef81695f94126377d279992c8396d53c4f Mon Sep 17 00:00:00 2001 From: Gavin P Date: Thu, 2 Jan 2025 15:13:59 -0800 Subject: [PATCH] Added workflows and plugins --- .github/workflows/main.yml | 85 +++++++++++++++++++ .gitignore | 4 + build.gradle | 77 ++++++++++++++++- src/main/java/frc/robot/RobotContainer.java | 6 +- src/main/java/frc/robot/commands/Autos.java | 2 +- .../frc/robot/commands/ExampleCommand.java | 2 +- 6 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ae25cf1 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,85 @@ +# This is a basic workflow to build robot code. + +name: CI + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the main branch. +on: + workflow_dispatch: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains two jobs, one for testing build and simulation, and one for automatically applying spotless + spotless: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # This grabs the WPILib docker container + container: wpilib/roborio-cross-ubuntu:2024-22.04 + + permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{secrets.BOT_ACCESS_TOKEN}} + + # Declares the repository safe and not under dubious ownership. + - name: Add repository to git safe directories + run: git config --global --add safe.directory $GITHUB_WORKSPACE + + # Logs into our 4201 actions bot + - name: Setup Git + run: | + git config user.name "4201-actions-bot" + git config user.email "gavinsjunkmail@yahoo.com" + + # Runs a single command using the runners shell + - name: Applying spotless formatting + run: ./gradlew spotlessApply + + # Runs a single command using the runners shell + - name: Commiting changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Automatically applied spotless + + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # This grabs the WPILib docker container + container: wpilib/roborio-cross-ubuntu:2024-22.04 + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Declares the repository safe and not under dubious ownership. + - name: Add repository to git safe directories + run: git config --global --add safe.directory $GITHUB_WORKSPACE + + # Grant execute permission for gradlew + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # Runs a single command using the runners shell + - name: Applying spotless formatting + run: ./gradlew spotlessApply + + # Runs a single command using the runners shell + - name: Compile and run tests on robot code + run: ./gradlew build -x test + + # Runs a single command using the runners shell + - name: Run the robot code in a simulator + run: timeout 30 ./gradlew simulateJava || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index 34cbaac..e3a5afb 100644 --- a/.gitignore +++ b/.gitignore @@ -171,6 +171,7 @@ out/ # Simulation GUI and other tools window save file networktables.json simgui.json +simgui-ds.json *-window.json # Simulation data log directory @@ -185,3 +186,6 @@ compile_commands.json # Eclipse generated file for annotation processors .factorypath + +# Auto-generated at build time by gversion +src/main/java/frc/robot/BuildConstants.java diff --git a/build.gradle b/build.gradle index 9d8ae14..89253b2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,8 @@ plugins { id "java" id "edu.wpi.first.GradleRIO" version "2025.1.1" + id 'com.diffplug.spotless' version '6.25.0' + id "com.peterabeles.gversion" version "1.10.3" } java { @@ -27,6 +29,13 @@ deploy { // getTargetTypeClass is a shortcut to get the class type using a string frcJava(getArtifactTypeClass('FRCJavaArtifact')) { + // Enable VisualVM connection + jvmArgs.add("-Dcom.sun.management.jmxremote=true") + jvmArgs.add("-Dcom.sun.management.jmxremote.port=1198") + jvmArgs.add("-Dcom.sun.management.jmxremote.local.only=false") + jvmArgs.add("-Dcom.sun.management.jmxremote.ssl=false") + jvmArgs.add("-Dcom.sun.management.jmxremote.authenticate=false") + jvmArgs.add("-Djava.rmi.server.hostname=10.42.01.2") // Replace XX.XX with team number } // Static files artifact @@ -34,7 +43,7 @@ deploy { files = project.fileTree('src/main/deploy') directory = '/home/lvuser/deploy' deleteOldFiles = false // Change to true to delete files on roboRIO that no - // longer exist in deploy directory of this project + // longer exist in deploy directory of this project } } } @@ -87,7 +96,11 @@ wpi.sim.addDriverstation() // in order to make them all available at runtime. Also adding the manifest so WPILib // knows where to look for our Robot Class. jar { - from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + from { + configurations.runtimeClasspath.collect { + it.isDirectory() ? it : zipTree(it) + } + } from sourceSets.main.allSource manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS) duplicatesStrategy = DuplicatesStrategy.INCLUDE @@ -102,3 +115,63 @@ wpi.java.configureTestTasks(test) tasks.withType(JavaCompile) { options.compilerArgs.add '-XDstringConcat=inline' } + +// Spotless code formatter configuration +spotless { + java { + target fileTree('.') { + include '**/*.java' + exclude '**/build/**', '**/build-*/**' + } + toggleOffOn() + googleJavaFormat() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + } + groovyGradle { + target fileTree('.') { + include '**/*.gradle' + exclude '**/build/**', '**/build-*/**' + } + greclipse() + indentWithSpaces(4) + trimTrailingWhitespace() + endWithNewline() + } + format 'xml', { + target fileTree('.') { + include '**/*.xml' + exclude '**/build/**', '**/build-*/**' + } + eclipseWtp('xml') + trimTrailingWhitespace() + indentWithSpaces(2) + endWithNewline() + } + format 'misc', { + target fileTree('.') { + include '**/*.md', '**/.gitignore' + exclude '**/build/**', '**/build-*/**' + } + trimTrailingWhitespace() + indentWithSpaces(2) + endWithNewline() + } +} + +project.compileJava.dependsOn(createVersionFile) +gversion { + srcDir = "src/main/java/" + classPackage = "frc.robot" + className = "BuildConstants" + dateFormat = "yyyy-MM-dd HH:mm:ss z" + timeZone = "America/New_York" // Use preferred time zone + indent = " " +} + +apply plugin: 'com.diffplug.spotless' + +afterEvaluate { + tasks.getByName('spotlessCheck').dependsOn(tasks.getByName('spotlessApply')) +} diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index a33249e..0cff9b6 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -4,13 +4,13 @@ package frc.robot; +import edu.wpi.first.wpilibj2.command.Command; +import edu.wpi.first.wpilibj2.command.button.CommandXboxController; +import edu.wpi.first.wpilibj2.command.button.Trigger; import frc.robot.Constants.OperatorConstants; import frc.robot.commands.Autos; import frc.robot.commands.ExampleCommand; import frc.robot.subsystems.ExampleSubsystem; -import edu.wpi.first.wpilibj2.command.Command; -import edu.wpi.first.wpilibj2.command.button.CommandXboxController; -import edu.wpi.first.wpilibj2.command.button.Trigger; /** * This class is where the bulk of the robot should be declared. Since Command-based is a diff --git a/src/main/java/frc/robot/commands/Autos.java b/src/main/java/frc/robot/commands/Autos.java index 107aad7..6c45474 100644 --- a/src/main/java/frc/robot/commands/Autos.java +++ b/src/main/java/frc/robot/commands/Autos.java @@ -4,9 +4,9 @@ package frc.robot.commands; -import frc.robot.subsystems.ExampleSubsystem; import edu.wpi.first.wpilibj2.command.Command; import edu.wpi.first.wpilibj2.command.Commands; +import frc.robot.subsystems.ExampleSubsystem; public final class Autos { /** Example static factory for an autonomous command. */ diff --git a/src/main/java/frc/robot/commands/ExampleCommand.java b/src/main/java/frc/robot/commands/ExampleCommand.java index 7481d3c..318de13 100644 --- a/src/main/java/frc/robot/commands/ExampleCommand.java +++ b/src/main/java/frc/robot/commands/ExampleCommand.java @@ -4,8 +4,8 @@ package frc.robot.commands; -import frc.robot.subsystems.ExampleSubsystem; import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.ExampleSubsystem; /** An example command that uses an example subsystem. */ public class ExampleCommand extends Command {