Use FAKE to Tag a git branch after build - f#-fake

Is it possible to set up a Target that creates and pushes a git tag on a remote after the Build Target completes?
Thanks for your help.

I used the following which seems to work
Target "TagBuild" (fun _ ->
open Fake.Git
let versionNumber = "1.0.0.0"
let repositoryRoot = "../"
let branchName = Fake.Git.Information.getBranchName repositoryRoot
trace ("Current GIT Branch: " + branchName)
let tagName = ("build_" + versionNumber)
trace ("Creating Tag: " + tagName)
tag repositoryRoot tagName
pushTag repositoryRoot "origin" tagName)

Related

How do you specify Fake Target inputs and output?

In the build systems that I'm familiar with (make and msbuild) there's a way to specify the inputs and outputs for a target. If the time stamps on the input files are earlier than those on the outputs the task is skipped. I can't find something similar in FAKE.
For example if I wanted to translate this Makefile to Fake
a.exe: a.fs
fsharpc a.fs -o a.exe
it might look like:
Target "a.exe" (fun _ -> ["a.fs"] |> FscHelper.compile [...])
However, when I run the build command it will always execute the compiler and produce a new a.exe regardless the modification time on a.fs. Is there a simple way to get the same behavior as the makefile?
You could use =?>and provide a function that returns true or false if the task should run.
let fileModified f1 f2 =
FileInfo(f1).LastWriteTime > FileInfo(f2).LastWriteTime
and then in target dependencies
=?> ("a.exe", fileModified "a.fs" "a.exe")
A more complete code example to flesh out Lazydevs answer:
#r "packages/FAKE/tools/FakeLib.dll"
open Fake
open System.IO
Target "build" (fun _ ->
trace "built"
)
let needsUpdate f1 f2 =
let lastWrite files =
files
|> Seq.map (fun f -> FileInfo(f).LastWriteTime)
|> Seq.max
let t1 = lastWrite f1
let t2 = lastWrite f2
t1 > t2
let BuildTarget name infiles outfiles fn =
Target name (fn infiles)
name =?> ("build", needsUpdate infiles outfiles)
BuildTarget "compile" ["Test2.fs"; "Test1.fs"] ["Test2.dll"] (fun files _ ->
files
|> FscHelper.compile [
FscHelper.Target FscHelper.TargetType.Library
]
|> function 0 -> () | c -> failwithf "compile error"
)
RunTargetOrDefault "build"

Change name of apk depending on buildType

I'd like to change the name of my output .apk files. However, I want to have "-debug" or "-release" appended depending on the build type.
Here are the output names I want:
MyApp-0.0.1-debug.apk
MyApp-0.0.1-release.apk
I'm unfamiliar with Gradle and haven't found how to do this, I know I just need to access the buildType within the following code but can't find how to do this.
Currently my output is "MyApp-0.0.1.apk" regardless of buildType. How can I change the code below to alter this?
android.libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName
def bType = ""
// bType = "-" + something.buildType
fileName = "${archivesBaseName}-${project.version}${bType}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
The build type is part of the variant; you're iterating over all the variants in your loop. You can get the build type name via:
variant.buildType.name
You can find (partially complete) API docs at http://tools.android.com/tech-docs/new-build-system/user-guide
For anyone arriving here late, this version works for me in April 2020.
Just place this code inside your buildTypes element ( android or defaultConfig work just as well).
applicationVariants.all { variant ->
def customBuildName = ""
if(variant.buildType.name == "release") customBuildName = "release-name.apk"
else customBuildName = "build-name.apk"
variant.outputs.all {
outputFileName = customBuildName
println("name of ${variant.buildType.name} build is ${outputFileName}")
}
}

Easiest way to set msbuild logging verbosity in fake?

I have a target that looks like this:
Target "builddotnetcode" (fun _ ->
!! "../Mercury.sln"
|> MSBuildRelease null "Clean,Build"
|> Log "MercuryBuild - Output: "
)
I want to simply set the verbosity in there somewhere. As far as I can tell from the docs you need to specify the Verbosity member of the MSBuildParams object. But build is the only MSBuildHelper function that provides a way to pass a MSBuildParams. Using build I then need to specify Configuration=Release property, the project list, and remove the pipeline to the Log. It seems like there ought to be a simpler way that does not cause me to redefine the entire task. Am I missing something?
So what i did is the following. The reason i did is it this was as I want to create a log file per solution file that I am building
let loggerConfig : list<MSBuildFileLoggerConfig> = [
{
Number = 1
Filename = Some (baseDir + name + "_build.log")
Verbosity = Some MSBuildVerbosity.Minimal
Parameters = Some [MSBuildLogParameter.Append]
}
]
let setParams defaults =
{ defaults with
Verbosity = Some MSBuildVerbosity.Minimal
Targets = ["Build"]
MaxCpuCount = Some (Some 4)
FileLoggers = Some loggerConfig
ToolsVersion = Some "12.0"
Properties =
[
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", buildMode
]
}
Lastly the only msbuild task that I could see that will let you override the msbuilddefaults was standard build.
build setParams solution
|> DoNothing

FAKE build a project with unsafe flag

I am trying to build a solution where one of the projects needs to be build with the unsafe flag on, it is set correctly in the project however when building I get the error:
"Unsafe code may only appear if compiling with /unsafe"
This is my target at the moment
Target "CompileApp" (fun _ ->
!! #"**\*.csproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
I tried adding MsBuildParams but not sure how to use them yet (ie there doesnt seem to be an option in MsBuildRelease to add something like this
let setParams defaults =
{ defaults with
Verbosity = Some(Quiet)
Targets = ["Build"]
Properties =
[
"AllowUnsafeBlocks", "True"
"Configuration", "Release"
]
}
Also would the best option here be create two different targets for projects with safe and unsafe code, of would there be a better way?
I found that the AllowUnsafeBlocks=true element was only defined under the DEBUG|AnyCPU and Release|AnyCPU PropertyGroups in my project file.
Using this fixed it for me:
Target "BuildApp" (fun _ ->
!! ".\**\MyApp.*.csproj"
|> MSBuild buildDir "Build" ["Configuration", "Release"; "Platform", "AnyCPU"]
|> Log "AppBuild-Output: "
)
Hope this helps.
Ok I think this might be the way:
Target "CompileUnsafe" (fun _ ->
let buildMode = getBuildParamOrDefault "buildMode" "Release"
let setParams defaults =
{ defaults with
Verbosity = Some(Quiet)
Targets = ["Build"]
Properties =
[
"Optimize", "True"
"DebugSymbols", "True"
"Configuration", buildMode
"AllowUnsafeBlocks", "True"
]
}
build setParams "./ProjectPlugins.sln"
)
IF there are better solutions I'm all ears (the solution was there in the docs and I just missed it)

How to make a clickable link that executes a command with bukkit

I'm trying to make a bukkit plugin and I can't seem to find any documentation on this but I've seen it done, How would I input commands into a chat message that a user could click on to execute a command on the server like "/motd" in the form of a clickable link like a URL
if (commandLabel.equalsIgnoreCase("cmd") {
player.sendMessage("Pick a command: " + </motd> + ", " + </mail> );
}
replacing "" and "" to output something like this:
Pick a command: MOTD, Mail
and clicking them would execute the command to the server as them. How would I do this?
You could do it like this:
IChatBaseComponent comp = ChatSerializer
.a("{\"text\":\"" + "Choose one: " + "\",\"extra\":[{\"text\":\"" + "MOTD" + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + "/motd" + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) <player>).getHandle().playerConnection.sendPacket(packet);
This would send them a message showing:
Choose one: MOTD
and when the user clicked MOTD, it would run the command /motd as the player. Here's a little breakdown of what we're actually doing:
IChatBaseComponent comp = ChatSerializer
.a("{\"text\":\"" + "<Ignored Message> " +
"\",\"extra\":[{\"text\":\"" + "<Message that will be clicked>" +
"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" +
"<Command to be run when message is clicked>" + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) <player>).getHandle().playerConnection.sendPacket(packet);
The above code will send the player:
<Ignored Message> <Message that will be clicked>
and when the player clicks <Message that will be clicked>
they will run the command <Command to be run when a message is clicked>, and because it does not start with the command prefix, /, it will force them to chat <Command to be run when a message is clicked>.
Unfortunately, as far as I know, you can only put one click event per message, so you would have to do something like this:
Choose one:
MOTD
Mail
So you would have to do, where the variable player is the player:
player.sendMessage("Choose one:");
IChatBaseComponent comp = ChatSerializer
.a("{\"text\":\"" +
"\",\"extra\":[{\"text\":\"" + "MOTD" +
"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" +
"/motd" + "\"}}]}");
PacketPlayOutChat packet = new PacketPlayOutChat(comp, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
IChatBaseComponent comp2 = ChatSerializer
.a("{\"text\":\"" +
"\",\"extra\":[{\"text\":\"" + "Mail" +
"\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" +
"/mail" + "\"}}]}");
PacketPlayOutChat packet2 = new PacketPlayOutChat(comp2, true);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet2);
When MOTD is clicked, /motd will be run by the player, and when Mail is clicked, /mail will be run.
Just as a side note, you will need to include craftbukkit in your build path, along with bukkit to do this
Or you could simply just do this (I did my own, You can edit it)
/execute #a ~ ~ ~ tellraw #p ["",{"text":"Click this to die","color":"dark_red","bold":true,"clickEvent":{"action":"run_command","value":"/kill #p"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"Kills you!"}]}}}]
run_command can be replaced with Open URL too.
You can replace dark red with any colour too. You can replace true with false for bold if you want, /kill #p can be replaced with a command (Or a https:// link if you do Open URL, show_text can be replaced with Show Item, Show entity, or Show Achivement. Text & Kills you can be replaced with the different thing (eg, Show entity) (Entity replaces text)
I found a website if your stuck! Good day :) http://minecraftjson.com/