Skip to content

Commit 1dee95d

Browse files
committed
Init project
1 parent 1bedb2f commit 1dee95d

File tree

108 files changed

+749
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+749
-0
lines changed

.editorconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
root = true
2+
3+
[*]
4+
trim_trailing_whitespace = true
5+
csharp_using_directive_placement = outside_namespace:silent
6+
csharp_style_namespace_declarations = file_scoped:silent
7+
8+
[*.yml]
9+
indent_size = 2
10+
indent_style = space
11+
12+
[*.{proj,csproj,vbproj,props,targets,resx,vsixmanifest}]
13+
indent_size = 2
14+
indent_style = space
15+
16+
[*.cs]
17+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0290
18+
csharp_style_prefer_primary_constructors = false
19+
dotnet_diagnostic.IDE0290.severity = none
20+
21+
# https://www.jetbrains.com/help/rider/ConvertToPrimaryConstructor.html
22+
resharper_convert_to_primary_constructor_highlighting = none
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'NuGet Pack'
2+
description: 'Packs RocketModFix NuGet packages'
3+
inputs:
4+
nuspec_path:
5+
description: 'Path to .nuspec'
6+
required: true
7+
nuget_push:
8+
description: 'Push to Nuget?'
9+
required: false
10+
default: false
11+
nuget_key:
12+
description: 'NuGet deploy key'
13+
required: false
14+
runs:
15+
using: "composite"
16+
steps:
17+
- name: Pack
18+
run: nuget pack ${{ inputs.nuspec_path }}
19+
shell: bash
20+
- name: Push to NuGet (Release)
21+
run: if ${{ inputs.nuget_push == 'true' }}; then
22+
dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ inputs.nuget_key }} --source https://api.nuget.org/v3/index.json;
23+
fi
24+
shell: bash
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: 'Project Build'
2+
description: 'Builds FixLibrary project'
3+
inputs:
4+
project_path:
5+
description: 'Path to project folder'
6+
required: true
7+
runtime_version:
8+
description: 'Build runtime version default linux-x64'
9+
required: false
10+
default: 'linux-x64'
11+
nuget_push:
12+
description: 'Push to Nuget on release?'
13+
required: false
14+
default: false
15+
nuget_key:
16+
description: 'NuGet deploy key'
17+
required: false
18+
github_token:
19+
description: 'GitHub token'
20+
required: false
21+
outputs:
22+
version:
23+
description: "Generated version (SemVersion compatible)"
24+
value: ${{ steps.get-version.outputs.version }}
25+
is_prerelease:
26+
description: 'Gets if the version is a prerelease'
27+
value: ${{ steps.check-prerelease.outputs.is_prerelease }}
28+
runs:
29+
using: "composite"
30+
steps:
31+
# Generate semver compatible version from current tag and commit hash
32+
- name: Create version
33+
id: get-version
34+
run: echo "version=$(git describe --tags `git rev-list --tags --max-count=1`)+$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
35+
shell: bash
36+
37+
- name: Check Prerelease
38+
id: check-prerelease
39+
run: "if ${{ contains(steps.get-version.outputs.version, '-') }}; then
40+
echo is_prerelease=true >> $GITHUB_OUTPUT;
41+
else
42+
echo is_prerelease=false >> $GITHUB_OUTPUT;
43+
fi"
44+
shell: bash
45+
46+
# Commands that are used multiple times.
47+
# Placed in one place to make sure that the arguments would always be the same
48+
- name: Common commands
49+
id: common-commands
50+
run: |
51+
echo "dotnet-restore=dotnet restore \$PROJECT_PATH --runtime ${{ inputs.runtime_version }}" >> $GITHUB_OUTPUT
52+
echo "dotnet-build=dotnet build \$PROJECT_PATH --configuration Release --no-restore -p:FixLibraryVersion=${{ steps.get-version.outputs.version }} --runtime ${{ inputs.runtime_version }}" >> $GITHUB_OUTPUT
53+
echo "dotnet-test=dotnet test \$PROJECT_PATH --configuration Release --no-restore --no-build --runtime ${{ inputs.runtime_version }}" >> $GITHUB_OUTPUT
54+
shell: bash
55+
56+
# Install dependencies (this needs to be a separate step from build for caching)
57+
- name: Install dependencies
58+
run: |
59+
${{ steps.common-commands.outputs.dotnet-restore }}
60+
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$PROJECT_PATH" '${{ steps.common-commands.outputs.dotnet-restore }}'
61+
env:
62+
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
63+
shell: bash
64+
65+
# Build project
66+
- name: Build
67+
run: |
68+
${{ steps.common-commands.outputs.dotnet-build }}
69+
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$PROJECT_PATH" '${{ steps.common-commands.outputs.dotnet-build }}'
70+
env:
71+
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
72+
shell: bash
73+
74+
# Test project
75+
- name: Test
76+
run: |
77+
pwsh -File .github/actions/project-build/run-command-for-every-tests-project.ps1 "$PROJECT_PATH" '${{ steps.common-commands.outputs.dotnet-test }}'
78+
env:
79+
PROJECT_PATH: ${{ inputs.project_path }} # Used by commands in `common-commands` step
80+
shell: bash
81+
82+
# Push to GitHub packages on each commit and release
83+
- name: Push to NuGet (Nightly)
84+
if: |
85+
inputs.nuget_push == 'true' && (github.event_name == 'push' ||
86+
github.event_name == 'create' && github.event.ref_type == 'tag')
87+
run: dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.github_token }} --skip-duplicate --source https://nuget.pkg.github.com/UnturnedCommunity/index.json;
88+
shell: bash
89+
90+
# Push to NuGet on each tag, but only if the tag is not a pre-release version
91+
- name: Push to NuGet (Release)
92+
if: |
93+
inputs.nuget_push == 'true' && steps.check-prerelease.outputs.is_prerelease == 'false' &&
94+
github.event_name == 'create' && github.event.ref_type == 'tag'
95+
run: dotnet nuget push ${{ inputs.project_path }}/bin/Release/*.nupkg --api-key ${{ inputs.nuget_key }} --skip-duplicate --source https://api.nuget.org/v3/index.json;
96+
shell: bash
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Finds all tests projects for a project passed as the first argument
3+
# and runs a command passed as the second argument for every tests project found.
4+
# Also sets PROJECT_PATH environment variables with value of the tests project folder path.
5+
#
6+
# Example usage:
7+
# pwsh -f .github/actions/project-build/run-command-for-every-tests-project.ps1 "framework/OpenMod.Core" "echo \$PROJECT_PATH"
8+
#
9+
# Example output:
10+
# Tests project found: framework/OpenMod.Core/../tests/OpenMod.Core.Tests. Executing a command: echo $PROJECT_PATH
11+
# framework/OpenMod.Core/../tests/OpenMod.Core.Tests
12+
13+
$projectPath = $args[0]
14+
$projectName = Split-Path -Path $projectPath -Leaf
15+
$testsFolderPath = Join-Path -Path $projectPath -ChildPath "../tests"
16+
17+
$commandToExecute = $args[1]
18+
19+
Get-ChildItem -Path $testsFolderPath -Directory -Recurse `
20+
| Where-Object { $_.Name -match "^$projectName.*Tests$" } `
21+
| ForEach-Object {
22+
$testsProjectName = $_.Name
23+
$testsProjectPath = Join-Path -Path $testsFolderPath -ChildPath $testsProjectName
24+
Write-Output "Tests project found: $testsProjectPath. Executing a command: $commandToExecute"
25+
bash -c "PROJECT_PATH=$testsProjectPath && $commandToExecute"
26+
}

.github/workflows/FixLibrary.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: FixLibrary
2+
3+
on:
4+
create:
5+
tags:
6+
- "*"
7+
push:
8+
branches: [ master ]
9+
paths:
10+
- '.github/workflows/FixLibrary.yml'
11+
- 'Module.cs'
12+
- 'Module/RuntimeLibs/**'
13+
- 'FixLibrary.csproj'
14+
pull_request:
15+
paths:
16+
- '.github/workflows/FixLibrary.yml'
17+
- 'Module.cs'
18+
- 'Module/RuntimeLibs/**'
19+
- 'FixLibrary.csproj'
20+
21+
jobs:
22+
Build:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0
30+
31+
- uses: actions/setup-dotnet@v4
32+
name: Setup .NET
33+
with:
34+
dotnet-version: 8.x
35+
36+
- name: Install zip
37+
run: sudo apt-get install zip
38+
39+
- name: Build FixLibrary.Module
40+
uses: ./.github/actions/project-build
41+
id: fixlibrary-module-build
42+
with:
43+
project_path: '.' # Use current directory for the project
44+
nuget_key: ${{ secrets.NUGET_DEPLOY_KEY }}
45+
nuget_push: false
46+
github_token: ${{ secrets.PAT }}
47+
48+
- name: Zip FixLibrary artifacts
49+
run: "cd bin/Release/net461/linux-x64/FixLibrary && zip -qq -r ./FixLibrary.Module.zip *"
50+
51+
- name: Upload FixLibrary
52+
uses: actions/upload-artifact@v4
53+
with:
54+
name: FixLibrary.Module.zip
55+
path: "bin/Release/net461/linux-x64/FixLibrary/FixLibrary.Module.zip"
56+
if-no-files-found: error
57+
58+
- name: Create Release
59+
if: github.event_name == 'create' && github.event.ref_type == 'tag'
60+
uses: ncipollo/[email protected]
61+
with:
62+
name: FixLibrary Release v${{ steps.auto-installer-build.outputs.version }}
63+
tag: ${{ steps.auto-installer-build.outputs.version }}
64+
artifacts: bin/Release/net461/linux-x64/FixLibrary/FixLibrary.Module.zip
65+
token: ${{ secrets.PAT }}
66+
prerelease: ${{ steps.auto-installer-build.outputs.is_prerelease }}
67+
allowUpdates: true
68+
draft: true

0 commit comments

Comments
 (0)