diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1e0e9bb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,129 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Build + +# Trigger the action on push to master +on: + workflow_call: {} # Allow reusing this workflow + push: + branches: + - 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: + 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 + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "ci" + cancel-in-progress: false + +jobs: + Build: + runs-on: ubuntu-latest + steps: + # Setup environment + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + source-url: https://nuget.pkg.github.com/ResoniteModdingGroup/index.json + + - name: Add MonkeyLoader NuGet Source + run: dotnet nuget add source https://pkg.munally.com/MonkeyModdingTroop/index.json + + - name: Restore NuGet Package Cache + uses: actions/cache/restore@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget + + # Build and test projects + - name: Restore + run: dotnet restore + + - name: Build + run: dotnet build --no-restore --configuration Release + + - name: Test + run: dotnet test --no-restore --no-build + + - name: Move NuGet Packages + run: mv (Get-ChildItem -Recurse ./ -Include *.nupkg) ./ + + # Removes the version number from the package name + - name: Rename NuGet Packages + run: Get-ChildItem -Include *.nupkg -Path ./* | Rename-Item -NewName { $_.Name -Replace '\.\d+\.\d+\.\d+.*$','.nupkg' } + + # Publish the NuGet package(s) as an artifact, so they can be used in the following jobs + - name: Upload NuGet Packages Artifact + uses: actions/upload-artifact@v4 + with: + name: NuGet Packages + if-no-files-found: error + retention-days: 7 + path: ./*.nupkg + + # Only when it's not from a PR to avoid any funny packages in the cache + - name: Save NuGet Package Cache + if: ${{ github.event_name != 'pull_request' }} + uses: actions/cache/save@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + + Validate-NuGet: + runs-on: ubuntu-latest + needs: [ Build ] + steps: + - name: Setup Dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + source-url: https://nuget.pkg.github.com/ResoniteModdingGroup/index.json + + - name: Add MonkeyLoader NuGet Source + run: dotnet nuget add source https://pkg.munally.com/MonkeyModdingTroop/index.json + + - name: Restore NuGet Package Cache + uses: actions/cache/restore@v4 + with: + path: ~/.nuget/packages + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} + restore-keys: | + ${{ runner.os }}-nuget + + - name: Install NuGet Validator + run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global + + - name: Download NuGet Packages Artifact + uses: actions/download-artifact@v4 + with: + name: NuGet Packages + path: ${{ env.NuGetDirectory }} + + # Validate metadata and content of the NuGet package + # https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab + # 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 }}" -Include *.nupkg) --excluded-rules IconMustBeSet \ No newline at end of file diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml deleted file mode 100644 index 032979e..0000000 --- a/.github/workflows/dotnet.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: CI - -# Trigger the action on push to master -on: - push: - branches: - - master - -# Sets permissions of the GITHUB_TOKEN to allow reading packages and writing to GH pages -permissions: - actions: read - pages: write - id-token: write - packages: read - -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. -concurrency: - group: "ci" - cancel-in-progress: false - -jobs: - build: - runs-on: ubuntu-latest - steps: - # Setup environment - - name: Checkout - uses: actions/checkout@v3 - - name: Dotnet Setup - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.x - source-url: https://nuget.pkg.github.com/ResoniteModdingGroup/index.json - env: - NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Add MonkeyLoader NuGet source - run: dotnet nuget add source https://pkg.munally.com/MonkeyModdingTroop/index.json - - # Cache NuGet packages - - uses: actions/cache@v3 - with: - path: ~/.nuget/packages - key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }} - restore-keys: | - ${{ runner.os }}-nuget - - # Build and test projects - - name: Install dependencies - run: dotnet restore - - - name: Build - run: dotnet build - - - name: Test - run: dotnet test \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..059338c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,84 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Publish + +on: + push: + tags: + - v** # Only when a v... tag is pushed + +# Sets permissions of the GITHUB_TOKEN to allow writing packages and push releases +permissions: + packages: write + contents: write + +env: + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 + DOTNET_NOLOGO: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + 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: Checkout + uses: actions/checkout@v4 + + - name: Download NuGet Packages Artifact + uses: actions/download-artifact@v4 + with: + name: NuGet Packages + path: ${{ env.NuGetDirectory }} + + - name: Build Changelog + id: build_changelog + uses: mikepenz/release-changelog-builder-action@v4 + + - 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 Packages + path: ${{ env.NuGetDirectory }} + + - name: Setup Dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + source-url: https://nuget.pkg.github.com/ResoniteModdingGroup/index.json + + - name: Add MonkeyLoader NuGet Source + run: dotnet nuget add source https://pkg.munally.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.GITHUB_TOKEN }}" --source https://nuget.pkg.github.com/ResoniteModdingGroup/index.json --skip-duplicate + } \ No newline at end of file