Skip to content

Instantly share code, notes, and snippets.

@nautilytics
Created January 17, 2024 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nautilytics/13e0e1925b8c3fa4fe081368dd36bd1c to your computer and use it in GitHub Desktop.
Save nautilytics/13e0e1925b8c3fa4fe081368dd36bd1c to your computer and use it in GitHub Desktop.
Setting up formatting and GitHub actions

Installation Instructions

GitHub Action

  • Inspiration from WPILib
  • Create a new file in .github/workflows/build.yml
  • Copy the contents of build.yml into that new file

Formatting

  • Add the new lines from build.gradle into the build.gradle file in the repository
  • ... just means keep existing code, but add the new code around it

Note

  • The new formatting changes will take place after the code compiles locally, so don't be surprised to see a fair amount of changes in existing .java and .json files
plugins {
...
id "com.diffplug.spotless" version "6.12.0"
}
...
// Spotless formatting
project.compileJava.dependsOn(spotlessApply)
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()
}
json {
target fileTree(".") {
include "**/*.json"
exclude "**/build/**", "**/build-*/**"
}
gson().indentWithSpaces(2)
}
format "misc", {
target fileTree(".") {
include "**/*.md", "**/.gitignore"
exclude "**/build/**", "**/build-*/**"
}
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
}
name: Build
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch.
on:
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 a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Grab 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
# Check formatting
- name: Check formatting
run: ./gradlew spotlessCheck
# Compile and run tests on robot code
- name: Compile and run tests on robot code
run: ./gradlew build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment