Skip to content

Commit

Permalink
Switch to Cake for build orchestration.
Browse files Browse the repository at this point in the history
Also:

* Switch to artifacts output paths in .NET projects.
* Simplify GitHub Actions workflows by moving logic into cathode.cake.
* Upload build logs/artifacts from GitHub Actions workflows.
* Improve the JetBrains Fleet experience in the repo.

Closes #26.
  • Loading branch information
alexrp committed Dec 12, 2023
1 parent 7d1f1be commit 977ed84
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 87 deletions.
7 changes: 7 additions & 0 deletions .fleet/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"files.exclude": [
"out",
".idea",
".vs"
]
}
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ jobs:
submodules: recursive
- name: Set up .NET
uses: actions/[email protected]
- name: Build project
- name: Run Cake
run: |
dotnet build
./cake
- name: Upload artifacts
if: always()
uses: actions/[email protected]
with:
name: ${{ github.workflow }}-${{ github.run_number }}-${{ github.run_attempt }}-${{ matrix.os }}-${{ matrix.cfg }}
path: |
out/log
out/pkg
16 changes: 11 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
DOTNET_NOLOGO: true
NUGET_TOKEN: ${{ secrets.NUGET_TOKEN }}
jobs:
release:
if: github.repository == 'vezel-dev/zig-toolsets'
Expand All @@ -23,9 +24,14 @@ jobs:
submodules: recursive
- name: Set up .NET
uses: actions/[email protected]
- name: Build project
- name: Run Cake
run: |
dotnet build
- name: Upload NuGet packages
run: |
dotnet nuget push pkg/feed/*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_TOKEN }} --skip-duplicate
./cake upload
- name: Upload artifacts
if: always()
uses: actions/[email protected]
with:
name: ${{ github.workflow }}-${{ github.run_number }}-${{ github.run_attempt }}-${{ matrix.os }}-${{ matrix.cfg }}
path: |
out/log
out/pkg
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.vs
/out
*.user
/pkg/cache/*/*
/pkg/feed/*.nupkg
bin
obj
.idea
.vs
8 changes: 3 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"files.exclude": {
"**/.vs": true,
"pkg/cache/*[!_._]": true,
"pkg/feed/*.nupkg": true,
"**/bin": true,
"**/obj": true
"out": true,
"**/.idea": true,
"**/.vs": true
}
}
49 changes: 0 additions & 49 deletions .vscode/tasks.json

This file was deleted.

10 changes: 8 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Configuration>Release</Configuration>
<EnablePackageValidation>true</EnablePackageValidation>
<IsPackable>false</IsPackable>
Expand All @@ -24,11 +23,18 @@ This project packs and distributes the Zig compiler and standard library in a
set of NuGet packages for each platform that .NET runs on. These packages are
mainly used by the Zig SDK but can also be used by other projects.</PackageDescription>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageOutputPath>$(MSBuildThisFileDirectory)pkg/feed/</PackageOutputPath>
<PackageProjectUrl>https://ziglang.org</PackageProjectUrl>
<PackageReleaseNotes>https://ziglang.org/download/$(ZigVersion)/release-notes.html</PackageReleaseNotes>
<PublishRelease>false</PublishRelease>
<RepositoryUrl>https://github.com/vezel-dev/zig-toolsets.git</RepositoryUrl>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
<ArtifactsPath>$(MSBuildThisFileDirectory)out</ArtifactsPath>
<ArtifactsProjectName>$([MSBuild]::MakeRelative('$(MSBuildThisFileDirectory)', '$(MSBuildProjectDirectory)'))</ArtifactsProjectName>
<ArtifactsPublishOutputName>pub</ArtifactsPublishOutputName>
<ArtifactsPackageOutputName>pkg</ArtifactsPackageOutputName>
</PropertyGroup>
</Project>
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

<div align="center">
<img src="zig.svg"
width="128" />
width="128"
alt="Zig Toolsets" />
</div>

<p align="center">
Expand Down Expand Up @@ -97,6 +98,11 @@ The following MSBuild properties will be injected into your project:
* `ZigLibPath`: Path to the Zig standard library.
* `ZigDocPath`: Path to the Zig standard library documentation.

## Building

Simply run `./cake` (a [Bash](https://www.gnu.org/software/bash) script) to
build artifacts.

## License

This project is licensed under the terms found in
Expand Down
7 changes: 7 additions & 0 deletions cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -eou pipefail

cd -- "$(dirname -- "$(readlink -e -- "${BASH_SOURCE[0]}")")"

dotnet tool restore
dotnet cake zig-toolsets.cake -t "${1:-default}" "${@:2}"
8 changes: 8 additions & 0 deletions cake.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Paths]
Addins=out/bld/addins
Cache=out/bld/cache
Tools=out/bld/tools

[Settings]
SkipVerification=true
EnableScriptCache=true
12 changes: 12 additions & 0 deletions dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"cake.tool": {
"version": "4.0.0",
"commands": [
"dotnet-cake"
]
}
}
}
4 changes: 2 additions & 2 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<configuration>
<config>
<add key="globalPackagesFolder" value="pkg/cache" />
<add key="globalPackagesFolder" value="out/dep" />
</config>

<fallbackPackageFolders>
Expand All @@ -10,7 +10,7 @@
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="zig-toolsets" value="pkg/feed" />
<add key="zig-toolsets" value="out/pkg/release" />
</packageSources>

<packageSourceMapping>
Expand Down
Empty file removed pkg/cache/_._
Empty file.
Empty file removed pkg/feed/_._
Empty file.
2 changes: 1 addition & 1 deletion src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This package provides the toolset for the $(ZigBuildRuntime) build platform.</Pa
DestinationFolder="$(OutputPath)"
Condition="'$(ZigArchiveType)' == 'zip' and !Exists('$(_ArchiveStamp)')" />

<Exec Command="tar xf &quot;../../$(_ArchivePath)&quot;"
<Exec Command="tar xf $(_ArchiveName)"
WorkingDirectory="$(OutputPath)"
Condition="'$(ZigArchiveType)' == 'tar.xz' and !Exists('$(_ArchiveStamp)')" />

Expand Down
30 changes: 15 additions & 15 deletions tasks.vs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
"contextType": "build",
"appliesTo": "/",
"type": "launch",
"command": "dotnet",
"args": [
"build",
"-clp:NoSummary"
]
},
{
"taskLabel": "Clean",
"contextType": "clean",
"appliesTo": "/",
"type": "launch",
"command": "dotnet",
"args": [
"clean",
"-clp:NoSummary"
"commands": [
{
"command": "dotnet",
"args": [
"tool",
"restore"
]
},
{
"command": "dotnet",
"args": [
"cake",
"zig-toolsets.cake"
]
}
]
}
]
Expand Down
106 changes: 106 additions & 0 deletions zig-toolsets.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#nullable enable

// Arguments

var target = Argument("t", "default");

// Environment

var nugetToken = EnvironmentVariable("NUGET_TOKEN");

// Paths

var root = Context.Environment.WorkingDirectory;
var zigToolsetsProj = root.CombineWithFilePath("zig-toolsets.proj");
var @out = root.Combine("out");
var outLog = @out.Combine("log");
var outPkg = @out.Combine("pkg");

// Globs

var nugetGlob = new GlobPattern(outPkg.Combine("release").CombineWithFilePath("*.nupkg").FullPath);

// Utilities

DotNetMSBuildSettings ConfigureMSBuild(string target)
{
var prefix = $"{target}_{Environment.UserName}_{Environment.MachineName}_";
var time = DateTime.Now;

string name;

do
{
name = $"{prefix}{time:yyyy-MM-dd_HH_mm_ss}.binlog";
time = time.AddSeconds(1);
}
while (System.IO.File.Exists(name));

return new()
{
// TODO: https://github.com/dotnet/msbuild/issues/6756
NoLogo = true,
BinaryLogger = new()
{
Enabled = true,
FileName = outLog.CombineWithFilePath(name).FullPath,
},
ConsoleLoggerSettings = new()
{
NoSummary = true,
},
ArgumentCustomization = args => args.Append("-ds:false"),
};
}

// Tasks

Task("default")
.IsDependentOn("build")
.IsDependentOn("pack");

Task("restore")
.Does(() =>
DotNetRestore(
zigToolsetsProj.FullPath,
new()
{
MSBuildSettings = ConfigureMSBuild("restore"),
}));

Task("build")
.IsDependentOn("restore")
.Does(() =>
DotNetBuild(
zigToolsetsProj.FullPath,
new()
{
MSBuildSettings = ConfigureMSBuild("build"),
NoRestore = true,
}));

Task("pack")
.IsDependentOn("build")
.Does(() =>
DotNetPack(
zigToolsetsProj.FullPath,
new()
{
MSBuildSettings = ConfigureMSBuild("pack"),
NoBuild = true,
}));

Task("upload")
.WithCriteria(BuildSystem.GitHubActions.Environment.Workflow.Ref.StartsWith("refs/tags/v"))
.IsDependentOn("pack")
.Does(() =>
DotNetNuGetPush(
nugetGlob.Pattern,
new()
{
Source = "https://api.nuget.org/v3/index.json",
ApiKey = nugetToken,
SkipDuplicate = true,
}));

RunTarget(target);

0 comments on commit 977ed84

Please sign in to comment.