Skip to content

Commit

Permalink
Adjusting workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
kohanis committed May 30, 2024
1 parent c248ad1 commit 0794ba0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "2.0.0",
"version": "4.0.0",
"commands": [
"dotnet-cake"
]
Expand Down
53 changes: 37 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
name: Build

on: [push, pull_request]
on:
push:
branches:
- "**"
pull_request:
workflow_dispatch:

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1

jobs:
test:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-dotnet@v1
- name: Checkout
uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.300
dotnet-version: |
3.x
5.x
6.x
7.x
8.x
- name: Log dotnet info
run: dotnet --info

- name: Run test
run: ./build.ps1 --target=Test

build:
runs-on: windows-latest
if: github.ref == 'refs/heads/master'
needs: test

steps:
- uses: actions/checkout@v1

- uses: actions/setup-dotnet@v1
- name: Checkout
uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
6.0.300
dotnet-version: '8.x'

- name: Make repo pushable
env:
Expand All @@ -49,9 +68,11 @@ jobs:
- name: Get target file
id: getfilename
shell: bash
run: echo "::set-output name=file::$(ls ./Harmony/bin/Release/HarmonyX*.nupkg)"

- uses: actions/upload-artifact@v1
run: |
echo "file=$(ls ./Harmony/bin/Release/HarmonyX*.nupkg)" >> "$GITHUB_OUTPUT"
- name: Upload HarmonyX nupkg
uses: actions/upload-artifact@v4
with:
path: ${{ steps.getfilename.outputs.file }}
name: HarmonyX
path: ${{ steps.getfilename.outputs.file }}
47 changes: 24 additions & 23 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,47 @@ on:
tags:
- 'v*'

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1

permissions:
contents: write

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v1
- uses: actions/setup-dotnet@v1
with:
dotnet-version: |
3.1.x
6.0.300
- name: Checkout
uses: actions/checkout@v4

- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'

- name: Get Version
id: get_version
shell: bash
run: |
tag=${GITHUB_REF##*/}
echo Current branch: ${tag:1}
echo ::set-output name=version_num::${tag:1}
echo "version_num=${tag:1}" >> "$GITHUB_OUTPUT"
- name: Run build script
run: ./build.ps1 --target=Build
shell: powershell

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
name: Release ${{ github.ref }}
body: ""
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./Harmony/bin/Release/HarmonyX.${{ steps.get_version.outputs.version_num }}.nupkg
asset_name: HarmonyX.${{ steps.get_version.outputs.version_num }}.nupkg
asset_content_type: application/zip
token: ${{ secrets.GITHUB_TOKEN }}
files: |
./Harmony/bin/Release/HarmonyX.${{ steps.get_version.outputs.version_num }}.nupkg
1 change: 1 addition & 0 deletions Harmony.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
Directory.Build.props = Directory.Build.props
README.md = README.md
build.cake = build.cake
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Harmony", "Harmony\Harmony.csproj", "{69AEE16A-B6E7-4642-8081-3928B32455DF}"
Expand Down
6 changes: 3 additions & 3 deletions HarmonyTests/HarmonyTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
45 changes: 19 additions & 26 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#addin nuget:?package=Cake.FileHelpers&version=4.0.0
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.12.0"
#addin "nuget:?package=Cake.Incubator&version=6.0.0"
#addin nuget:?package=Cake.FileHelpers&version=7.0.0

var target = Argument("target", "Build");
var nugetKey = Argument("nugetKey", "");
var useTmpLocalNuget = Argument("useTmpLocalNuget", false);

string RunGit(string command, string separator = "")
{
Expand All @@ -22,50 +21,44 @@ Task("Cleanup")
CleanDirectories(GetDirectories("./**/obj/"));
});

Task("PullDependencies")
.Does(() =>
{
Information("Restoring NuGet packages");
DotNetRestore(".");
});

Task("Build")
.IsDependentOn("Cleanup")
.IsDependentOn("PullDependencies")
.Does(() =>
{
var buildSettings = new DotNetBuildSettings {
Configuration = "Release",
MSBuildSettings = new DotNetCoreMSBuildSettings()
MSBuildSettings = new DotNetMSBuildSettings()
};
buildSettings.MSBuildSettings.Targets.Add("build");
buildSettings.MSBuildSettings.Targets.Add("pack");
DotNetBuild(".", buildSettings);
buildSettings.Configuration = "Release";
DotNetBuild("./Harmony/Harmony.csproj", buildSettings);
});

Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
var testTargets = new [] { "net35", "net452", "net48", "netcoreapp3.1", "net5.0", "net6.0", "net7.0", "net8.0" };
foreach (var target in testTargets)
{
Information($"Testing {target}");
DotNetCoreTest("./HarmonyTests/HarmonyTests.csproj", new DotNetCoreTestSettings {
Configuration = "Release",
Framework = target,
Verbosity = DotNetCoreVerbosity.Normal
});
}
var targets = FindRegexMatchGroupInFile("./HarmonyTests/HarmonyTests.csproj", @"<TargetFrameworks>(.*)<\/TargetFrameworks>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value.Split(';');

foreach (var target in targets)
{
Information($"Testing {target}");
DotNetTest("./HarmonyTests/HarmonyTests.csproj", new DotNetTestSettings {
Configuration = "Release",
Framework = target,
Verbosity = DotNetVerbosity.Normal
});
}
});

Task("Publish")
.IsDependentOn("Build")
.Does(() =>
{
var version = FindRegexMatchGroupInFile("./Harmony/Harmony.csproj", @"<Version>(.*)<\/Version>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
var versionTagPresent = !string.IsNullOrWhiteSpace(RunGit($"ls-remote --tags origin v{version}"));
var version = FindRegexMatchGroupInFile("./Directory.Build.props", @"<HarmonyXVersion>(.*)<\/HarmonyXVersion>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value;
version += FindRegexMatchGroupInFile("./Directory.Build.props", @"<HarmonyXVersionSuffix>(.*)<\/HarmonyXVersionSuffix>", 1, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Captures[0].Value;

var versionTagPresent = !string.IsNullOrWhiteSpace(RunGit($"ls-remote --tags origin v{version}"));
if(versionTagPresent)
{
Information("New version exists, no need to push.");
Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"allowPrerelease": false
}
}

0 comments on commit 0794ba0

Please sign in to comment.