Publish #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| permissions: | |
| contents: write | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| type: string | |
| required: true | |
| description: Version (Semver without leading v) | |
| nuget-release: | |
| type: boolean | |
| description: Release NuGet Package? | |
| default: true | |
| github-release: | |
| type: boolean | |
| description: Make GitHub Release? | |
| default: true | |
| github-release-draft: | |
| type: boolean | |
| description: Mark GitHub Release as Draft? | |
| default: false | |
| github-release-prerelease: | |
| type: boolean | |
| description: Mark GitHub Release as Prerelease? | |
| default: false | |
| jobs: | |
| publish: | |
| name: Publish to NuGet and Create Release | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| env: | |
| RELEASE_VERSION: ${{ github.event.inputs.version }} | |
| permissions: | |
| id-token: write # Allow action to get OIDC token from GitHub | |
| contents: write # Allow action to create tags and releases | |
| attestations: write | |
| steps: | |
| - id: semver | |
| uses: matt-usurp/validate-semver@v2 | |
| with: | |
| version: ${{ env.RELEASE_VERSION }} | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: | | |
| 9.0.x | |
| - name: Restore | |
| run: dotnet restore | |
| - name: Pre Build | |
| run: | | |
| dotnet build -c Release --no-restore > /dev/null 2>&1 || : | |
| - name: Build | |
| run: dotnet build -c Release --no-restore -p:Version=${{ env.RELEASE_VERSION }} | |
| - name: Test | |
| run: dotnet test -c Release --no-build | |
| - name: Pack | |
| run: | | |
| dotnet pack -c Release --no-build --no-restore --output nupkg --include-symbols --include-source --version-suffix ${{ env.RELEASE_VERSION }} | |
| - name: Read Changelog Entry | |
| uses: mindsers/changelog-reader-action@v2 | |
| id: read_changelog | |
| with: | |
| version: ${{ env.RELEASE_VERSION }} | |
| path: ./CHANGELOG.md | |
| # https://github.com/microsoft/azure-pipelines-tasks/issues/1511 | |
| - name: Push Packages to NuGet | |
| run: | | |
| dotnet nuget push "nupkg/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate | |
| - name: Create Git tag | |
| run: | | |
| git config user.name "${{ github.actor }}" | |
| git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" | |
| git tag "v${{ github.event.inputs.version }}" -m "Release version ${{ github.event.inputs.version }}" | |
| - name: Push Git tag | |
| run: git push origin "v${{ github.event.inputs.version }}" | |
| - name: Create GitHub Release and Upload Assets | |
| id: create_release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: "v${{ github.event.inputs.version }}" | |
| name: "v${{ github.event.inputs.version }}" | |
| body: ${{ steps.read_changelog.outputs.changes }} | |
| draft: ${{ github.event.inputs.github-release-draft == 'true' }} | |
| prerelease: ${{ github.event.inputs.github-release-prerelease == 'true' }} | |
| artifacts: "nupkg/*" | |
| allowUpdates: true |