Skip to content

Commit 7e6e1aa

Browse files
committed
Preparing for GitHub Actions
1 parent 8553fb6 commit 7e6e1aa

File tree

3 files changed

+219
-0
lines changed

3 files changed

+219
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
name: Pull Request
3+
on: pull_request
4+
5+
env:
6+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
7+
DOTNET_CLI_TELEMETRY_OPTOUT: true
8+
9+
jobs:
10+
11+
###################################################
12+
# BUILD
13+
###################################################
14+
15+
build:
16+
name: Build
17+
if: "!contains(github.event.head_commit.message, 'skip-ci')"
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup .NET SDK
26+
uses: actions/setup-dotnet@v4
27+
with:
28+
dotnet-version: |
29+
8.0.x
30+
9.0.x
31+
32+
- name: Build
33+
shell: bash
34+
run: |
35+
dotnet tool restore
36+
dotnet cake
37+
38+
- name: Upload Verify Test Results
39+
if: failure()
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: verify-test-results
43+
path: |
44+
**/*.received.*

.github/workflows/publish.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
name: Publish
3+
4+
on:
5+
push:
6+
tags:
7+
- '*'
8+
branches:
9+
- main
10+
11+
env:
12+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
13+
DOTNET_CLI_TELEMETRY_OPTOUT: true
14+
15+
jobs:
16+
17+
###################################################
18+
# PUBLISH
19+
###################################################
20+
21+
build:
22+
name: Publish NuGet Packages
23+
if: "!contains(github.event.head_commit.message, 'skip-ci') || startsWith(github.ref, 'refs/tags/')"
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Setup .NET SDK
32+
uses: actions/setup-dotnet@v4
33+
with:
34+
dotnet-version: |
35+
8.0.x
36+
9.0.x
37+
38+
- name: Publish
39+
shell: bash
40+
run: |
41+
dotnet tool restore
42+
dotnet cake --target="publish" \
43+
--nuget-key="${{secrets.NUGET_API_KEY}}" \
44+
--github-key="${{secrets.GITHUB_TOKEN}}"
45+
46+
###################################################
47+
# DOCS
48+
###################################################
49+
50+
documentation:
51+
name: Publish Documentation
52+
needs: [build]
53+
runs-on: windows-latest
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Setup .NET SDK
61+
uses: actions/setup-dotnet@v4
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: '16'
67+
68+
- name: Cache dependencies
69+
uses: actions/cache@v4
70+
with:
71+
path: ~/.npm
72+
key: npm-${{ hashFiles('package-lock.json') }}
73+
restore-keys: npm-
74+
75+
- name: Publish Documentation
76+
shell: bash
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
NETLIFY_ACCESS_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }}
80+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
81+
run: |
82+
cd docs
83+
dotnet tool restore
84+
dotnet run --configuration Release -- deploy

publish.cake

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
var target = Argument("target", "Publish");
2+
var configuration = Argument("configuration", "Release");
3+
4+
////////////////////////////////////////////////////////////////
5+
// Tasks
6+
7+
Task("Clean")
8+
.Does(context =>
9+
{
10+
context.CleanDirectory("./.artifacts");
11+
});
12+
13+
Task("Build")
14+
.IsDependentOn("Clean")
15+
.Does(context =>
16+
{
17+
Information("Compiling TextPromptWithHistory...");
18+
DotNetBuild("./src/TextPromptWithHistory.sln", new DotNetBuildSettings {
19+
Configuration = configuration,
20+
Verbosity = DotNetVerbosity.Minimal,
21+
NoLogo = true,
22+
NoIncremental = context.HasArgument("rebuild"),
23+
MSBuildSettings = new DotNetMSBuildSettings()
24+
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error)
25+
});
26+
});
27+
28+
Task("Test")
29+
.IsDependentOn("Build")
30+
.Does(context =>
31+
{
32+
DotNetTest("./src/Tests/TextPromptWithHistory.Tests/TextPromptWithHistory.Tests.csproj", new DotNetTestSettings {
33+
Configuration = configuration,
34+
Verbosity = DotNetVerbosity.Minimal,
35+
NoLogo = true,
36+
NoRestore = true,
37+
NoBuild = true,
38+
});
39+
});
40+
41+
Task("Package")
42+
.IsDependentOn("Test")
43+
.Does(context =>
44+
{
45+
context.DotNetPack($"./src/TextPromptWithHistory.sln", new DotNetPackSettings {
46+
Configuration = configuration,
47+
Verbosity = DotNetVerbosity.Minimal,
48+
NoLogo = true,
49+
NoRestore = true,
50+
NoBuild = true,
51+
OutputDirectory = "./.artifacts",
52+
MSBuildSettings = new DotNetMSBuildSettings()
53+
.TreatAllWarningsAs(MSBuildTreatAllWarningsAs.Error)
54+
});
55+
});
56+
57+
Task("Publish-NuGet")
58+
.WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions")
59+
.IsDependentOn("Package")
60+
.Does(context =>
61+
{
62+
var apiKey = Argument<string>("nuget-key", null);
63+
if(string.IsNullOrWhiteSpace(apiKey)) {
64+
throw new CakeException("No NuGet API key was provided.");
65+
}
66+
67+
// Publish to GitHub Packages
68+
foreach(var file in context.GetFiles("./.artifacts/*.nupkg"))
69+
{
70+
context.Information("Publishing {0}...", file.GetFilename().FullPath);
71+
DotNetNuGetPush(file.FullPath, new DotNetNuGetPushSettings
72+
{
73+
Source = "https://api.nuget.org/v3/index.json",
74+
ApiKey = apiKey,
75+
});
76+
}
77+
});
78+
79+
////////////////////////////////////////////////////////////////
80+
// Targets
81+
82+
Task("Publish")
83+
.IsDependentOn("Publish-NuGet");
84+
85+
Task("Default")
86+
.IsDependentOn("Package");
87+
88+
////////////////////////////////////////////////////////////////
89+
// Execution
90+
91+
RunTarget(target)

0 commit comments

Comments
 (0)