Skip to content

Commit cecc4b0

Browse files
authored
Automatic releasing (#150)
* Prepare Directory.Build.props * Update Build all projects.yml * Create release-drafter.yml * Fix * Update Test all projects.yml * Update Build all projects.yml * Restore * dotnet nuget * Update Test all projects.yml * Update Test all projects.yml * Fixes * Fix PackageVersion * Update Test all projects.yml * Update Directory.Build.props * Update Test all projects.yml * Update Test all projects.yml * Update Test all projects.yml * Update Test all projects.yml * Create Release.yml * Rename Build all projects.yml to Build.yml * Rename Test all projects.yml to Test.yml * Update release-drafter.yml * Update Release.yml * Update Test.yml * Update Release.yml * Update release-drafter.yml * Update Release.yml * Update Test.yml * Update release-drafter.yml * Update Test.yml * Update Test.yml * Update Test.yml * Update Test.yml * Update Test.yml * Update Test.yml * Update Directory.Build.props * Update Release.yml * Update release-drafter.yml * Update Release.yml * Update Test.yml * Update Release.yml * "RELEASE_NOTES"? lol * RELEEASE_NOTES? lol * Update CaretTests.cs * Update Release.yml
1 parent aabb520 commit cecc4b0

File tree

7 files changed

+181
-64
lines changed

7 files changed

+181
-64
lines changed

.github/release-drafter.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# https://github.com/marketplace/actions/release-drafter#configuration
2+
name-template: '$RESOLVED_VERSION CI'
3+
tag-template: 'v$RESOLVED_VERSION'
4+
version-resolver:
5+
major:
6+
labels:
7+
- 'Version/Major'
8+
minor:
9+
labels:
10+
- 'Version/Minor'
11+
patch:
12+
labels:
13+
- 'Version/Patch'
14+
default: patch
15+
exclude-labels:
16+
- 'Version/None'
17+
prerelease: true
18+
template: |
19+
<!--Example release name: $RESOLVED_VERSION xxx Update [Alpha|Beta]-->
20+
<!--Please release immediately after modifying as any changes will be overwritten on next run of the Test workflow-->
21+
<!--Remove these comments, they will be visible in the released NuGet packages!-->
22+
23+
## Changes from $PREVIOUS_TAG (Recently merged first)
24+
$CHANGES
25+
26+
## Contributors
27+
$CONTRIBUTORS
28+
categories:
29+
- title: '🌈 New Platform!'
30+
labels:
31+
- 'Type/Platform'
32+
- title: '🚀 Features'
33+
labels:
34+
- 'Type/Enhancement'
35+
- title: '🐛 Bug Fixes'
36+
labels:
37+
- 'Type/Bug'
38+
- title: '🧰 Maintenance'
39+
label: 'Type/Housekeeping'
40+
# Extra line before $BODY or markdown on the first line of $BODY will be interpreted as plain text
41+
change-template: |
42+
<details><summary>$TITLE (#$NUMBER) @$AUTHOR</summary>
43+
44+
$BODY
45+
</details>
46+
no-changes-template: '* (No changes)'
47+
replacers:
48+
# We don't support nested <summary> and <details> so we add a (?!<details>|<summary>)
49+
- search: '/<details><summary>((?:(?!<details>|<summary>).)+?)<\/summary>\s*<\/details>/g'
50+
replace: '- $1'

.github/workflows/Build all projects.yml

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/Build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build
2+
3+
on: [push, pull_request]
4+
jobs:
5+
all_projects:
6+
runs-on: windows-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
with:
10+
submodules: 'recursive'
11+
- name: Setup .NET Core
12+
uses: actions/setup-dotnet@v1
13+
with:
14+
dotnet-version: '3.1.302'
15+
- name: Setup NuGet
16+
uses: NuGet/setup-nuget@v1.0.2
17+
- name: Setup MSBuild Path
18+
uses: warrenbuckley/Setup-MSBuild@v1
19+
- name: Restore NuGet Packages
20+
run: nuget restore CSharpMath.sln
21+
- name: Build CI artifacts
22+
run: msbuild CSharpMath.sln /p:Configuration=Release

.github/workflows/Release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
jobs:
7+
all_projects:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
with:
12+
submodules: 'recursive'
13+
- name: Setup .NET Core
14+
uses: actions/setup-dotnet@v1
15+
with:
16+
dotnet-version: '3.1.302'
17+
- name: Build GitHub Releases draft artifacts
18+
env:
19+
RELEASE_NOTES: |
20+
# ${{ github.event.release.name }}
21+
22+
${{ github.event.release.body }}
23+
# run: dotnet test CSharpMath.CrossPlatform.slnf
24+
run: | # https://github.com/dotnet/sdk/issues/10409, https://github.com/dotnet/sdk/issues/11417
25+
# .NET Core MSBuild cannot parse , and ; correctly so we replace them with substitutions: https://github.com/dotnet/msbuild/issues/471#issuecomment-366268743
26+
# https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion
27+
# ${parameter/pattern/string} If pattern begins with ‘/’, all matches of pattern are replaced with string. Normally only the first match is replaced.
28+
RELEASE_NOTES=${RELEASE_NOTES//,/%2C}
29+
RELEASE_NOTES=${RELEASE_NOTES//;/%3B}
30+
for p in\
31+
"CSharpMath.CoreTests"\
32+
"CSharpMath.Editor.Tests"\
33+
"CSharpMath.Editor.Tests.FSharp"\
34+
"CSharpMath.Evaluation.Tests"\
35+
`# "CSharpMath.Ios" # https://github.com/dotnet/sdk/issues/11108 + https://github.com/release-drafter/release-drafter/issues/558`\
36+
"CSharpMath.Rendering.Tests"\
37+
"CSharpMath.Rendering.Text.Tests"\
38+
"CSharpMath.Xaml.Tests"\
39+
"CSharpMath.Xaml.Tests.NuGet"\
40+
"Typography/Typography.TextBreak/Typography.TextBreak.UnitTests"
41+
do
42+
# -r for restore
43+
dotnet msbuild -r -p:Configuration=Release -p:PackageVersion="${{ github.event.release.tag_name }}" -p:PackageReleaseNotes="$RELEASE_NOTES" "$p"
44+
done
45+
- name: Upload to GitHub Releases
46+
uses: svenstaro/upload-release-action@v2
47+
with:
48+
repo_token: ${{ secrets.GITHUB_TOKEN }}
49+
tag: ${{ github.ref }}
50+
file: .nupkgs/*
51+
file_glob: true
52+
overwrite: true
53+
- name: Upload to NuGet
54+
run: dotnet nuget push .nupkgs/* -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json

.github/workflows/Test all projects.yml renamed to .github/workflows/Test.yml

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,26 @@ name: Test
33
on: [push, pull_request]
44
jobs:
55
Core:
6-
runs-on: ${{ matrix.os }}
7-
strategy:
8-
matrix:
9-
os: [ubuntu-latest, macos-latest]
6+
runs-on: ubuntu-latest # release-drafter/release-drafter@v5 only works on Linux: https://github.com/release-drafter/release-drafter/issues/558
107
steps:
8+
- name: Update draft on GitHub Releases
9+
id: release_drafter
10+
uses: release-drafter/release-drafter@v5
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
- uses: cardinalby/git-get-release-action@v1
14+
id: release_info
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
with:
18+
releaseId: ${{ steps.release_drafter.outputs.id }}
1119
- uses: actions/checkout@v2
1220
with:
1321
submodules: 'recursive'
1422
- name: Setup .NET Core
1523
uses: actions/setup-dotnet@v1
1624
with:
17-
dotnet-version: '3.1.301'
18-
- name: Setup JDK # Needed to run ANTLR for AngouriMath
19-
uses: actions/setup-java@v1
20-
with:
21-
java-version: '8'
25+
dotnet-version: '3.1.302'
2226
- name: Update dependencies in CSharpMath.Xaml.Tests.NuGet
2327
run: |
2428
dotnet tool install -g dotnet-outdated
@@ -29,13 +33,24 @@ jobs:
2933
# retry 5 times since dotnet outdated fails often: https://github.com/jerriep/dotnet-outdated/issues/299
3034
update || update || update || update || update
3135
- name: Build and Test
36+
env:
37+
RELEASE_NOTES: |
38+
# ${{ steps.release_info.outputs.name }}
39+
40+
${{ steps.release_info.outputs.body }}
3241
# run: dotnet test CSharpMath.CrossPlatform.slnf
3342
run: | # https://github.com/dotnet/sdk/issues/10409, https://github.com/dotnet/sdk/issues/11417
43+
# .NET Core MSBuild cannot parse , and ; correctly so we replace them with substitutions: https://github.com/dotnet/msbuild/issues/471#issuecomment-366268743
44+
# https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion
45+
# ${parameter/pattern/string} If pattern begins with ‘/’, all matches of pattern are replaced with string. Normally only the first match is replaced.
46+
RELEASE_NOTES=${RELEASE_NOTES//,/%2C}
47+
RELEASE_NOTES=${RELEASE_NOTES//;/%3B}
3448
for p in\
3549
"CSharpMath.CoreTests"\
3650
"CSharpMath.Editor.Tests"\
3751
"CSharpMath.Editor.Tests.FSharp"\
3852
"CSharpMath.Evaluation.Tests"\
53+
`# "CSharpMath.Ios" # https://github.com/dotnet/sdk/issues/11108 + https://github.com/release-drafter/release-drafter/issues/558`\
3954
"CSharpMath.Rendering.Tests"\
4055
"CSharpMath.Rendering.Text.Tests"\
4156
"CSharpMath.Xaml.Tests"\
@@ -44,13 +59,28 @@ jobs:
4459
do
4560
dotnet add "$p" package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything
4661
dotnet add "$p" package GitHubActionsTestLogger
47-
dotnet test "$p" -c Release -l GitHubActions
62+
# -r for restore
63+
dotnet msbuild -r -p:Configuration=Release -p:PackageVersion=${{ steps.release_drafter.outputs.tag_name }}-ci-${{ github.sha }} -p:PackageReleaseNotes="$RELEASE_NOTES" "$p"
64+
# --no-build because building again will produce additional NuGet packages without the PackageVersion setting above
65+
dotnet test "$p" --no-build -c Release -l GitHubActions --blame
4866
done
4967
- uses: actions/upload-artifact@v2
5068
if: always() # Run even when a previous step failed: https://stackoverflow.com/a/58859404/5429648
5169
with:
52-
name: CSharpMath.Rendering.Tests results (${{ matrix.os }})
70+
name: CSharpMath.Rendering.Tests results
5371
path: CSharpMath.Rendering.Tests/*/*.png
72+
- name: Upload CI artifacts
73+
uses: actions/upload-artifact@v2
74+
if: always()
75+
with:
76+
name: NuGet packages
77+
path: .nupkgs/
78+
- name: Push CI artifacts to GitHub Packages registry
79+
if: github.ref == 'refs/heads/master'
80+
run: |
81+
# Non-Windows platforms require --store-password-in-clear-text: https://github.com/NuGet/Home/issues/1851
82+
dotnet nuget add source https://nuget.pkg.github.com/verybadcat/index.json -n github -u verybadcat -p ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text
83+
dotnet nuget push .nupkgs/ --source "github" --skip-duplicate
5484
Ios:
5585
runs-on: macos-latest
5686
steps:

CSharpMath.Editor.Tests/CaretTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public async Task Test() {
146146
await Task.Delay((int)MathKeyboard<TestFont, char>.DefaultBlinkMilliseconds - CaretBlinks.MillisecondBuffer);
147147

148148
Assert.Equal(MathKeyboardCaretState.Shown, keyboard.CaretState);
149-
await Task.Delay(2 * CaretBlinks.MillisecondBuffer);
149+
await Task.Delay(3 * CaretBlinks.MillisecondBuffer);
150150
Assert.Equal(MathKeyboardCaretState.TemporarilyHidden, keyboard.CaretState);
151151
}
152152
}

Directory.Build.props

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--Directory.Build.props: MSBuild properties that are included in every project-->
22
<!--Info: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2019#directorybuildprops-and-directorybuildtargets-->
3-
<Project InitialTargets="AppendCISignatureToPackageVersion">
3+
<Project InitialTargets="SetDefaultPackageVersion">
44
<PropertyGroup Condition="$(MSBuildProjectName.StartsWith('CSharpMath'))"> <!--Don't apply to Typography projects-->
55
<LangVersion>preview</LangVersion>
66
<Nullable>enable</Nullable>
@@ -12,7 +12,7 @@
1212

1313
<!--NuGet properties: Ordered according to https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target-->
1414
<PackageId>$(MSBuildProjectName)</PackageId>
15-
<PackageVersion>0.4.2</PackageVersion>
15+
<!--PackageVersion is set in the SetDefaultPackageVersion target below-->
1616
<Authors>CSharpMath Contributors (verybadcat, Happypig375, charlesroddie, FoggyFinder)</Authors>
1717
<Title>$(PackageId)</Title>
1818
<!--Description property is defined in individual projects-->
@@ -25,15 +25,11 @@
2525
math mathematics mathematical formula equation equations
2626
expression tex latex render rendering display beautiful CSharpMath
2727
</PackageTags>
28-
<PackageReleaseNotes>
29-
The 0.4 Avalonia Update brings the Avalonia front end!
30-
0.4.1: Fixed Measure in CSharpMath.Rendering
31-
0.4.2: Fixed TextPainter setting the position of display maths in the first line to above the canvas bounds
32-
</PackageReleaseNotes>
28+
<!--PackageReleaseNotes is not set by default and is set by CI-->
3329
<RepositoryUrl>https://github.com/verybadcat/CSharpMath.git</RepositoryUrl>
3430
<RepositoryType>git</RepositoryType>
3531
<RepositoryBranch>master</RepositoryBranch>
36-
<!--RepositoryCommit property is set dynamically below-->
32+
<!--RepositoryCommit property is set in the SetDefaultPackageVersion target below-->
3733

3834
<!--SourceLink properties: Ordered according to https://github.com/dotnet/sourcelink#using-source-link-in-net-projects-->
3935
<PublishRepositoryUrl>true</PublishRepositoryUrl>
@@ -50,9 +46,6 @@
5046
<NeutralLanguage>en</NeutralLanguage>
5147
<RootNamespace>$(MSBuildProjectName)</RootNamespace> <!--Prefix namespace for embedded resources-->
5248
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
53-
<AssemblyVersion>$(PackageVersion.Split('-')[0])</AssemblyVersion>
54-
<FileVersion>$(AssemblyVersion)</FileVersion> <!--"File version" in DLL Details, $(AssemblyVersion) if unset-->
55-
<Version>$(AssemblyVersion)</Version> <!--"Product version" in DLL Details, '1.0.0' if unset-->
5649
</PropertyGroup>
5750
<ItemGroup Condition="
5851
$(MSBuildProjectName.StartsWith('CSharpMath'))
@@ -61,15 +54,19 @@
6154
<None Include="$(MSBuildThisFileDirectory)Icon.png" Pack="true" PackagePath="" />
6255
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
6356
</ItemGroup>
64-
<Target Name="AppendCISignatureToPackageVersion" Condition="$(MSBuildProjectName.StartsWith('CSharpMath'))">
57+
<!--Also run for non-CSharpMath projects: Normalize PackageVersion or else error-->
58+
<Target Name="SetDefaultPackageVersion">
6559
<!--Setting StandardOutputImportance to Low ensures that EchoOff works: https://github.com/Microsoft/msbuild/issues/2826-->
6660
<Exec Command="git rev-parse HEAD" ConsoleToMSBuild="true" EchoOff="true" StandardOutputImportance="Low">
6761
<Output TaskParameter="ConsoleOutput" PropertyName="RepositoryCommit" />
6862
</Exec>
69-
<!-- Appending build date and time as metadata for version is blocked on https://github.community/t/bug-nuget-support-build-metadata-properly/117606 -->
70-
<!-- <CreateProperty Value="$(PackageVersion)-ci-$(RepositoryCommit)+$([System.DateTime]::UtcNow.ToString('yyyy.MM.dd-HH.mm.ss'))"> -->
71-
<CreateProperty Condition="!$([System.String]::IsNullOrEmpty($(CI))) And $(CI)" Value="$(PackageVersion)-ci-$(RepositoryCommit)">
63+
<!--For local builds-->
64+
<CreateProperty Condition="$(PackageVersion) == '1.0.0'" Value="99.99.99-localbuild-$(RepositoryCommit)">
65+
<Output TaskParameter="Value" PropertyName="PackageVersion" />
66+
</CreateProperty>
67+
<!--For CI builds-->
68+
<CreateProperty Value="$(PackageVersion.TrimStart('v'))">
7269
<Output TaskParameter="Value" PropertyName="PackageVersion" />
7370
</CreateProperty>
7471
</Target>
75-
</Project>
72+
</Project>

0 commit comments

Comments
 (0)