-
Notifications
You must be signed in to change notification settings - Fork 69
[robotpy parity] Write a deploy.json log file when deploying code #690
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
Open
spacey-sooty
wants to merge
11
commits into
wpilibsuite:main
Choose a base branch
from
spacey-sooty:deploy_data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e0b462a
start working on deploy data
spacey-sooty d63d80a
create file to be deployed
spacey-sooty 32cbe68
start switching to proper gradle way
spacey-sooty b1866f5
Use grgit for hash and branchname
spacey-sooty a2c42c7
should be working now
spacey-sooty e3dcd14
pass args to grgit.open
spacey-sooty 3e09be4
jgit
spacey-sooty 95b8941
Merge branch 'main' into deploy_data
spacey-sooty df72f28
Merge branch 'main' into deploy_data
spacey-sooty 91d1498
review fixes
spacey-sooty d2f02b6
working raaa
spacey-sooty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/edu/wpi/first/gradlerio/deploy/CreateLogFileTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package edu.wpi.first.gradlerio.deploy; | ||
|
||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.Gson; | ||
|
||
import org.codehaus.groovy.runtime.ResourceGroovyMethods; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.logging.LogLevel; | ||
import org.gradle.api.provider.Provider; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.OutputFile; | ||
|
||
import java.util.HashMap; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.io.File; | ||
import java.time.LocalDateTime; | ||
|
||
public class CreateLogFileTask extends DefaultTask { | ||
public static final String[] DEPLOY_ITEMS = { | ||
"deployHost", | ||
"deployUser", | ||
"deployDate", | ||
"codePath", | ||
"gitHash", | ||
"gitBranch", | ||
"gitDesc", | ||
}; | ||
private RegularFileProperty deployFile; | ||
private String json; | ||
private String gitDirectory; | ||
|
||
@Inject | ||
public CreateLogFileTask(Project project) { | ||
deployFile = project.getObjects().fileProperty(); | ||
} | ||
|
||
@TaskAction | ||
public void execute() throws IOException { | ||
deployFile.getAsFile().get().getParentFile().mkdirs(); | ||
HashMap<String, String> data = new HashMap<String, String>(); | ||
GsonBuilder builder = new GsonBuilder(); | ||
builder.setPrettyPrinting(); | ||
Gson jsongen = builder.create(); | ||
|
||
try { | ||
Repository repository = new FileRepositoryBuilder().setGitDir(new File(gitDirectory)) | ||
.readEnvironment() // scan environment GIT_* variables | ||
.findGitDir() // scan up the file system tree | ||
.build(); | ||
|
||
try { | ||
data.put(DEPLOY_ITEMS[4], repository.resolve("HEAD").toString()); | ||
} catch (Exception e) { | ||
getLogger().log(LogLevel.WARN, "Couldn't get git hash"); | ||
} | ||
|
||
try { | ||
data.put(DEPLOY_ITEMS[5], repository.getBranch()); | ||
} catch (Exception e) { | ||
getLogger().log(LogLevel.WARN, "Couldn't get git branch"); | ||
} | ||
try { | ||
data.put(DEPLOY_ITEMS[6], repository.getGitwebDescription()); | ||
} catch (Exception e) { | ||
getLogger().log(LogLevel.WARN, "Couldn't get git description"); | ||
} | ||
} catch (Exception e) { | ||
getLogger().log(LogLevel.WARN, "Couldn't find git"); | ||
} | ||
|
||
try { | ||
data.put(DEPLOY_ITEMS[0], InetAddress.getLocalHost().getHostName()); | ||
} catch (IOException e) { | ||
getLogger().log(LogLevel.WARN, "Couldn't get host name"); | ||
} | ||
|
||
data.put(DEPLOY_ITEMS[1], System.getProperty("user.name")); | ||
data.put(DEPLOY_ITEMS[2], LocalDateTime.now().toString()); | ||
data.put(DEPLOY_ITEMS[3], System.getProperty("user.dir")); | ||
|
||
json = jsongen.toJson(data); | ||
ResourceGroovyMethods.setText(deployFile.getAsFile().get(), json); | ||
} | ||
|
||
public void setGitDirectory(String dir) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a string property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find a StringProperty class in the Gradle API? |
||
gitDirectory = dir; | ||
} | ||
|
||
@OutputFile | ||
public RegularFileProperty getDeployFile() { | ||
return deployFile; | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.