Skip to content

Commit bd9d01d

Browse files
committed
Automatic releases?
1 parent db1fd7f commit bd9d01d

2 files changed

Lines changed: 101 additions & 13 deletions

File tree

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ name: dotnet-CI
44

55
# Trigger the action on push to master
66
on:
7+
workflow_call: [] # Allow reusing this workflow
78
push:
89
branches:
9-
- master
10+
- master # Run for pushes to master
11+
pull_request:
12+
branches:
13+
- '*' # Run the workflow for all pull requests
1014

1115
# Sets permissions of the GITHUB_TOKEN to allow reading packages
1216
permissions:
@@ -40,9 +44,9 @@ jobs:
4044
uses: actions/setup-dotnet@v4
4145
with:
4246
source-url: https://nuget.pkg.github.com/MonkeyModdingTroop/index.json
43-
44-
# Cache NuGet packages
45-
- uses: actions/cache@v4
47+
48+
- name: Cache NuGet Packages
49+
uses: actions/cache@v4
4650
with:
4751
path: ~/.nuget/packages
4852
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
@@ -58,25 +62,30 @@ jobs:
5862

5963
- name: Test
6064
run: dotnet test --no-restore --no-build
65+
66+
- name: Move NuGet Packages
67+
run: mv (Get-ChildItem -Recurse ./ -Include *.nupkg) ./
6168

6269
# Publish the NuGet package(s) as an artifact, so they can be used in the following jobs
63-
- uses: actions/upload-artifact@v4
70+
- name: Upload NuGet Packages Artifact
71+
uses: actions/upload-artifact@v4
6472
with:
65-
name: nuget
73+
name: NuGet Packages
6674
if-no-files-found: error
6775
retention-days: 7
68-
path: ./**/*.nupkg
76+
path: ./*.nupkg
6977

7078
Validate-NuGet:
7179
runs-on: ubuntu-latest
7280
needs: [ Build ]
7381
steps:
74-
# Install the .NET SDK indicated in the global.json file
7582
- name: Setup Dotnet
7683
uses: actions/setup-dotnet@v4
84+
with:
85+
source-url: https://nuget.pkg.github.com/MonkeyModdingTroop/index.json
7786

78-
# Cache NuGet packages
79-
- uses: actions/cache@v4
87+
- name: Cache NuGet Packages
88+
uses: actions/cache@v4
8089
with:
8190
path: ~/.nuget/packages
8291
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
@@ -86,8 +95,8 @@ jobs:
8695
- name: Install NuGet Validator
8796
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
8897

89-
# Download the NuGet package created in the previous job
90-
- uses: actions/download-artifact@v4
98+
- name: Download NuGet Packages Artifact
99+
uses: actions/download-artifact@v4
91100
with:
92101
name: nuget
93102
path: ${{ env.NuGetDirectory }}
@@ -97,4 +106,4 @@ jobs:
97106
# If some rules are not applicable, you can disable them
98107
# using the --excluded-rules or --excluded-rule-ids option
99108
- name: Validate Package(s)
100-
run: meziantou.validate-nuget-package (Get-ChildItem -Recurse "${{ env.NuGetDirectory }}/*.nupkg") --excluded-rules IconMustBeSet
109+
run: meziantou.validate-nuget-package (Get-ChildItem -Recurse "${{ env.NuGetDirectory }}" -Include *.nupkg) --excluded-rules IconMustBeSet

.github/workflows/publish.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: publish
4+
5+
on:
6+
push:
7+
branches:
8+
- master # Run the workflow when pushing to the master branch
9+
tags:
10+
- v** # Only when a v... tag is pushed
11+
12+
# Sets permissions of the GITHUB_TOKEN to allow reading packages and push releases
13+
permissions:
14+
packages: read
15+
16+
env:
17+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
18+
DOTNET_NOLOGO: true
19+
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
NuGetDirectory: ${{ github.workspace}}/nuget
21+
22+
defaults:
23+
run:
24+
shell: pwsh
25+
26+
jobs:
27+
build:
28+
uses: ./.github/workflows/build.yml
29+
30+
release:
31+
if: startsWith(github.ref, 'refs/tags/')
32+
runs-on: ubuntu-latest
33+
needs: [ build ]
34+
steps:
35+
- name: Download NuGet Packages Artifact
36+
uses: actions/download-artifact@v4
37+
with:
38+
name: nuget
39+
path: ${{ env.NuGetDirectory }}
40+
41+
- name: Build Changelog
42+
id: build_changelog
43+
uses: mikepenz/release-changelog-builder-action@v4
44+
#env:
45+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Create Release
48+
uses: mikepenz/action-gh-release@v1 #softprops/action-gh-release
49+
with:
50+
body: ${{steps.build_changelog.outputs.changelog}}
51+
files: ${{ env.NuGetDirectory }}/*.nupkg
52+
fail_on_unmatched_files: true
53+
fail_on_asset_upload_issue: true
54+
prerelease: ${{ contains(github.ref, '-') }} # simple check for vX.Y.Z-something
55+
56+
publish_github:
57+
if: startsWith(github.ref, 'refs/tags/')
58+
runs-on: ubuntu-latest
59+
needs: [ build ]
60+
steps:
61+
- name: Download NuGet Packages Artifact
62+
uses: actions/download-artifact@v4
63+
with:
64+
name: nuget
65+
path: ${{ env.NuGetDirectory }}
66+
67+
- name: Setup Dotnet
68+
uses: actions/setup-dotnet@v4
69+
with:
70+
source-url: https://nuget.pkg.github.com/MonkeyModdingTroop/index.json
71+
72+
# Publish all NuGet packages to the GitHub feed
73+
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
74+
# If you retry a failed workflow, already published packages will be skipped without error.
75+
- name: Publish NuGet Packages
76+
run: |
77+
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
78+
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://nuget.pkg.github.com/MonkeyModdingTroop/index.json --skip-duplicate
79+
}

0 commit comments

Comments
 (0)