Skip to content

Commit

Permalink
Automatic releases?
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Jun 25, 2024
1 parent db1fd7f commit bd9d01d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
35 changes: 22 additions & 13 deletions .github/workflows/dotnet.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ name: dotnet-CI

# Trigger the action on push to master
on:
workflow_call: [] # Allow reusing this workflow
push:
branches:
- master
- master # Run for pushes to master
pull_request:
branches:
- '*' # Run the workflow for all pull requests

# Sets permissions of the GITHUB_TOKEN to allow reading packages
permissions:
Expand Down Expand Up @@ -40,9 +44,9 @@ jobs:
uses: actions/setup-dotnet@v4
with:
source-url: https://nuget.pkg.github.com/MonkeyModdingTroop/index.json
# Cache NuGet packages
- uses: actions/cache@v4

- name: Cache NuGet Packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
Expand All @@ -58,25 +62,30 @@ jobs:

- name: Test
run: dotnet test --no-restore --no-build

- name: Move NuGet Packages
run: mv (Get-ChildItem -Recurse ./ -Include *.nupkg) ./

# Publish the NuGet package(s) as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v4
- name: Upload NuGet Packages Artifact
uses: actions/upload-artifact@v4
with:
name: nuget
name: NuGet Packages
if-no-files-found: error
retention-days: 7
path: ./**/*.nupkg
path: ./*.nupkg

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

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

# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v4
- name: Download NuGet Packages Artifact
uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}
Expand All @@ -97,4 +106,4 @@ jobs:
# If some rules are not applicable, you can disable them
# using the --excluded-rules or --excluded-rule-ids option
- name: Validate Package(s)
run: meziantou.validate-nuget-package (Get-ChildItem -Recurse "${{ env.NuGetDirectory }}/*.nupkg") --excluded-rules IconMustBeSet
run: meziantou.validate-nuget-package (Get-ChildItem -Recurse "${{ env.NuGetDirectory }}" -Include *.nupkg) --excluded-rules IconMustBeSet
79 changes: 79 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json

name: publish

on:
push:
branches:
- master # Run the workflow when pushing to the master branch
tags:
- v** # Only when a v... tag is pushed

# Sets permissions of the GITHUB_TOKEN to allow reading packages and push releases
permissions:
packages: read

env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NuGetDirectory: ${{ github.workspace}}/nuget

defaults:
run:
shell: pwsh

jobs:
build:
uses: ./.github/workflows/build.yml

release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [ build ]
steps:
- name: Download NuGet Packages Artifact
uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Build Changelog
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v4
#env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
uses: mikepenz/action-gh-release@v1 #softprops/action-gh-release
with:
body: ${{steps.build_changelog.outputs.changelog}}
files: ${{ env.NuGetDirectory }}/*.nupkg
fail_on_unmatched_files: true
fail_on_asset_upload_issue: true
prerelease: ${{ contains(github.ref, '-') }} # simple check for vX.Y.Z-something

publish_github:
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [ build ]
steps:
- name: Download NuGet Packages Artifact
uses: actions/download-artifact@v4
with:
name: nuget
path: ${{ env.NuGetDirectory }}

- name: Setup Dotnet
uses: actions/setup-dotnet@v4
with:
source-url: https://nuget.pkg.github.com/MonkeyModdingTroop/index.json

# Publish all NuGet packages to the GitHub feed
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
- name: Publish NuGet Packages
run: |
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://nuget.pkg.github.com/MonkeyModdingTroop/index.json --skip-duplicate
}

0 comments on commit bd9d01d

Please sign in to comment.