1+ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+ name : Build
4+
5+ # Trigger the action on push to master
6+ on :
7+ workflow_call : {} # Allow reusing this workflow
8+ push :
9+ branches :
10+ - master # Run for pushes to master
11+ pull_request :
12+ branches :
13+ - ' *' # Run the workflow for all pull requests
14+
15+ # Sets permissions of the GITHUB_TOKEN to allow reading packages
16+ permissions :
17+ packages : read
18+
19+ env :
20+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1
21+ DOTNET_NOLOGO : true
22+ NUGET_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+ NuGetDirectory : ${{ github.workspace}}/nuget
24+
25+ defaults :
26+ run :
27+ shell : pwsh
28+
29+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
30+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
31+ concurrency :
32+ group : " ci"
33+ cancel-in-progress : false
34+
35+ jobs :
36+ Build :
37+ runs-on : ubuntu-latest
38+ steps :
39+ # Setup environment
40+ - name : Checkout
41+ uses : actions/checkout@v4
42+
43+ - name : Setup Dotnet
44+ uses : actions/setup-dotnet@v4
45+ with :
46+ dotnet-version : 9.x
47+ source-url : https://nuget.pkg.github.com/ResoniteModdingGroup/index.json
48+
49+ - name : Add MonkeyLoader NuGet Source
50+ run : dotnet nuget add source https://pkg.munally.com/MonkeyModdingTroop/index.json
51+
52+ - name : Restore NuGet Package Cache
53+ uses : actions/cache/restore@v4
54+ with :
55+ path : ~/.nuget/packages
56+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
57+ restore-keys : |
58+ ${{ runner.os }}-nuget
59+
60+ # Build and test projects
61+ - name : Restore
62+ run : dotnet restore
63+
64+ - name : Build
65+ run : dotnet build --no-restore --configuration Release
66+
67+ - name : Test
68+ run : dotnet test --no-restore --no-build
69+
70+ - name : Move NuGet Packages
71+ run : mv (Get-ChildItem -Recurse ./ -Include *.nupkg) ./
72+
73+ # Removes the version number from the package name
74+ - name : Rename NuGet Packages
75+ run : Get-ChildItem -Include *.nupkg -Path ./* | Rename-Item -NewName { $_.Name -Replace '\.\d+\.\d+\.\d+.*$','.nupkg' }
76+
77+ # Publish the NuGet package(s) as an artifact, so they can be used in the following jobs
78+ - name : Upload NuGet Packages Artifact
79+ uses : actions/upload-artifact@v4
80+ with :
81+ name : NuGet Packages
82+ if-no-files-found : error
83+ retention-days : 7
84+ path : ./*.nupkg
85+
86+ # Only when it's not from a PR to avoid any funny packages in the cache
87+ - name : Save NuGet Package Cache
88+ if : ${{ github.event_name != 'pull_request' }}
89+ uses : actions/cache/save@v4
90+ with :
91+ path : ~/.nuget/packages
92+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
93+
94+ Validate-NuGet :
95+ runs-on : ubuntu-latest
96+ needs : [ Build ]
97+ steps :
98+ - name : Setup Dotnet
99+ uses : actions/setup-dotnet@v4
100+ with :
101+ dotnet-version : 9.x
102+ source-url : https://nuget.pkg.github.com/ResoniteModdingGroup/index.json
103+
104+ - name : Add MonkeyLoader NuGet Source
105+ run : dotnet nuget add source https://pkg.munally.com/MonkeyModdingTroop/index.json
106+
107+ - name : Restore NuGet Package Cache
108+ uses : actions/cache/restore@v4
109+ with :
110+ path : ~/.nuget/packages
111+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
112+ restore-keys : |
113+ ${{ runner.os }}-nuget
114+
115+ - name : Install NuGet Validator
116+ run : dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
117+
118+ - name : Download NuGet Packages Artifact
119+ uses : actions/download-artifact@v4
120+ with :
121+ name : NuGet Packages
122+ path : ${{ env.NuGetDirectory }}
123+
124+ # Validate metadata and content of the NuGet package
125+ # https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
126+ # If some rules are not applicable, you can disable them
127+ # using the --excluded-rules or --excluded-rule-ids option
128+ - name : Validate Package(s)
129+ run : meziantou.validate-nuget-package (Get-ChildItem -Recurse "${{ env.NuGetDirectory }}" -Include *.nupkg) --excluded-rules IconMustBeSet
0 commit comments