diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 736c015..8de8bb9 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,11 +1,14 @@ name: .NET on: + workflow_dispatch: # Allow running the workflow manually from the GitHub UI push: branches: [ master ] - pull_request: - branches: [ master ] +defaults: + run: + shell: bash + jobs: build: runs-on: windows-latest @@ -14,36 +17,132 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: - submodules: false fetch-depth: 0 - - name: Install .NET 8.0 - uses: actions/setup-dotnet@v3 - with: - dotnet-version: '8.0.x' - - - name: Restore dependencies - run: dotnet restore ./Source/SVGImage/DotNetProjects.SVGImage.csproj - - - name: GitVersion - id: gitversion # step id used as reference for output values - uses: roryprimrose/set-vs-sdk-project-version@v1.0.6 + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0 with: - projectFilter: './Source/SVGImage/*.SVGImage.csproj' - version: '5.0.118' + versionSpec: '5.x' + + - name: Use GitVersion + id: gitversion # step id used as reference for output values + uses: gittools/actions/gitversion/execute@v0 + + - name: Display GitVersion outputs (step output) + run: | + echo "Major: ${{ steps.gitversion.outputs.major }}" + echo "Minor: ${{ steps.gitversion.outputs.minor }}" + echo "Patch: ${{ steps.gitversion.outputs.patch }}" + echo "PreReleaseTag: ${{ steps.gitversion.outputs.preReleaseTag }}" + echo "PreReleaseTagWithDash: ${{ steps.gitversion.outputs.preReleaseTagWithDash }}" + echo "PreReleaseLabel: ${{ steps.gitversion.outputs.preReleaseLabel }}" + echo "PreReleaseNumber: ${{ steps.gitversion.outputs.preReleaseNumber }}" + echo "WeightedPreReleaseNumber: ${{ steps.gitversion.outputs.weightedPreReleaseNumber }}" + echo "BuildMetaData: ${{ steps.gitversion.outputs.buildMetaData }}" + echo "BuildMetaDataPadded: ${{ steps.gitversion.outputs.buildMetaDataPadded }}" + echo "FullBuildMetaData: ${{ steps.gitversion.outputs.fullBuildMetaData }}" + echo "MajorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}" + echo "SemVer: ${{ steps.gitversion.outputs.semVer }}" + echo "LegacySemVer: ${{ steps.gitversion.outputs.legacySemVer }}" + echo "LegacySemVerPadded: ${{ steps.gitversion.outputs.legacySemVerPadded }}" + echo "AssemblySemVer: ${{ steps.gitversion.outputs.assemblySemVer }}" + echo "AssemblySemFileVer: ${{ steps.gitversion.outputs.assemblySemFileVer }}" + echo "FullSemVer: ${{ steps.gitversion.outputs.fullSemVer }}" + echo "InformationalVersion: ${{ steps.gitversion.outputs.informationalVersion }}" + echo "BranchName: ${{ steps.gitversion.outputs.branchName }}" + echo "EscapedBranchName: ${{ steps.gitversion.outputs.escapedBranchName }}" + echo "Sha: ${{ steps.gitversion.outputs.sha }}" + echo "ShortSha: ${{ steps.gitversion.outputs.shortSha }}" + echo "NuGetVersionV2: ${{ steps.gitversion.outputs.nuGetVersionV2 }}" + echo "NuGetVersion: ${{ steps.gitversion.outputs.nuGetVersion }}" + echo "NuGetPreReleaseTagV2: ${{ steps.gitversion.outputs.nuGetPreReleaseTagV2 }}" + echo "NuGetPreReleaseTag: ${{ steps.gitversion.outputs.nuGetPreReleaseTag }}" + echo "VersionSourceSha: ${{ steps.gitversion.outputs.versionSourceSha }}" + echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.commitsSinceVersionSource }}" + echo "CommitsSinceVersionSourcePadded: ${{ steps.gitversion.outputs.commitsSinceVersionSourcePadded }}" + echo "UncommittedChanges: ${{ steps.gitversion.outputs.uncommittedChanges }}" + echo "CommitDate: ${{ steps.gitversion.outputs.commitDate }}" - name: Update project version uses: roryprimrose/set-vs-sdk-project-version@v1.0.6 with: projectFilter: './Source/SVGImage/*.SVGImage.csproj' - version: '5.0.118' - # version: ${{ steps.gitversion.outputs.NuGetVersionV2 }} + version: ${{ steps.gitversion.outputs.NuGetVersionV2 }} assemblyVersion: ${{ steps.gitversion.outputs.AssemblySemVer }} fileVersion: ${{ steps.gitversion.outputs.MajorMinorPatch }} informationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }} - - name: Build, Test, Pack, Publish - shell: bash + - name: Install .NET 8.0 + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Restore dependencies + run: dotnet restore ./Source/SVGImage/DotNetProjects.SVGImage.csproj + + - name: Build + run: dotnet build --configuration Release DotNetProjects.SVGImage.csproj + working-directory: ./Source/SVGImage + + - name: Generate nuget package. + run: dotnet pack DotNetProjects.SVGImage.csproj --configuration Release -o nupkg + working-directory: ./Source/SVGImage + + - name: Publish to nuget + # run: find . -type f -name *.nupkg -print0 | xargs -0 -I pkg dotnet nuget push pkg -k $nuget_api_key -s "https://api.nuget.org/v3/index.json" --skip-duplicate run: | - dotnet tool install -g dotnet-releaser - dotnet-releaser run --nuget-token "${{secrets.NUGET_API_KEY}}" --github-token "${{secrets.GITHUB_TOKEN}}" Source/dotnet-releaser.toml + find . -type f -name *.nupkg -print0 | xargs -0 -I pkg dotnet nuget push pkg -k $nuget_api_key -s "https://api.nuget.org/v3/index.json" --skip-duplicate + env: + nuget_api_key: ${{ secrets.NUGET_API_KEY }} + working-directory: ./Source/SVGImage/nupkg + + - name: "Create release" + uses: "actions/github-script@v6" + id: createrelease + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + try { + const response = await github.rest.repos.createRelease({ + draft: false, + generate_release_notes: true, + name: "Release ${{ steps.gitversion.outputs.semVer }}", + owner: context.repo.owner, + prerelease: false, + repo: context.repo.repo, + tag_name: "${{ steps.gitversion.outputs.semVer }}", + }); + + core.exportVariable('RELEASE_ID', response.data.id); + core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url); + } catch (error) { + core.setFailed(error.message); + } + + - name: Upload release artifacts + uses: actions/github-script@v6 + env: + releaseId: ${{ env.RELEASE_ID }} + workingDirectory: ./Source/SVGImage/nupkg + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const releaseId = process.env.releaseId; + const workingDirectory = process.env.workingDirectory; + const fs = require('fs'); + const dirPath = workingDirectory; + const path = require('path'); + fs.readdir(dirPath, async (err,list) => { + if (err) throw err; + for (var i = 0; i < list.length; i++) { + if (path.extname(list[i]) === '.nupkg' || path.extname(list[i]) === '.snupkg') { + const uploadAssetResponse = await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: releaseId, + name: list[i], + data: fs.readFileSync(path.join(dirPath, list[i])) + }); + } + } + }); diff --git a/.github/workflows/dotnetpull.yml b/.github/workflows/dotnetpull.yml new file mode 100644 index 0000000..1153c53 --- /dev/null +++ b/.github/workflows/dotnetpull.yml @@ -0,0 +1,88 @@ +name: .NET + +on: + pull_request: + branches: [ master ] + +defaults: + run: + shell: bash + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install GitVersion + uses: gittools/actions/gitversion/setup@v0 + with: + versionSpec: '5.x' + + - name: Use GitVersion + id: gitversion # step id used as reference for output values + uses: gittools/actions/gitversion/execute@v0 + + - name: Display GitVersion outputs (step output) + run: | + echo "Major: ${{ steps.gitversion.outputs.major }}" + echo "Minor: ${{ steps.gitversion.outputs.minor }}" + echo "Patch: ${{ steps.gitversion.outputs.patch }}" + echo "PreReleaseTag: ${{ steps.gitversion.outputs.preReleaseTag }}" + echo "PreReleaseTagWithDash: ${{ steps.gitversion.outputs.preReleaseTagWithDash }}" + echo "PreReleaseLabel: ${{ steps.gitversion.outputs.preReleaseLabel }}" + echo "PreReleaseNumber: ${{ steps.gitversion.outputs.preReleaseNumber }}" + echo "WeightedPreReleaseNumber: ${{ steps.gitversion.outputs.weightedPreReleaseNumber }}" + echo "BuildMetaData: ${{ steps.gitversion.outputs.buildMetaData }}" + echo "BuildMetaDataPadded: ${{ steps.gitversion.outputs.buildMetaDataPadded }}" + echo "FullBuildMetaData: ${{ steps.gitversion.outputs.fullBuildMetaData }}" + echo "MajorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}" + echo "SemVer: ${{ steps.gitversion.outputs.semVer }}" + echo "LegacySemVer: ${{ steps.gitversion.outputs.legacySemVer }}" + echo "LegacySemVerPadded: ${{ steps.gitversion.outputs.legacySemVerPadded }}" + echo "AssemblySemVer: ${{ steps.gitversion.outputs.assemblySemVer }}" + echo "AssemblySemFileVer: ${{ steps.gitversion.outputs.assemblySemFileVer }}" + echo "FullSemVer: ${{ steps.gitversion.outputs.fullSemVer }}" + echo "InformationalVersion: ${{ steps.gitversion.outputs.informationalVersion }}" + echo "BranchName: ${{ steps.gitversion.outputs.branchName }}" + echo "EscapedBranchName: ${{ steps.gitversion.outputs.escapedBranchName }}" + echo "Sha: ${{ steps.gitversion.outputs.sha }}" + echo "ShortSha: ${{ steps.gitversion.outputs.shortSha }}" + echo "NuGetVersionV2: ${{ steps.gitversion.outputs.nuGetVersionV2 }}" + echo "NuGetVersion: ${{ steps.gitversion.outputs.nuGetVersion }}" + echo "NuGetPreReleaseTagV2: ${{ steps.gitversion.outputs.nuGetPreReleaseTagV2 }}" + echo "NuGetPreReleaseTag: ${{ steps.gitversion.outputs.nuGetPreReleaseTag }}" + echo "VersionSourceSha: ${{ steps.gitversion.outputs.versionSourceSha }}" + echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.commitsSinceVersionSource }}" + echo "CommitsSinceVersionSourcePadded: ${{ steps.gitversion.outputs.commitsSinceVersionSourcePadded }}" + echo "UncommittedChanges: ${{ steps.gitversion.outputs.uncommittedChanges }}" + echo "CommitDate: ${{ steps.gitversion.outputs.commitDate }}" + + - name: Update project version + uses: roryprimrose/set-vs-sdk-project-version@v1.0.6 + with: + projectFilter: './Source/SVGImage/*.SVGImage.csproj' + version: ${{ steps.gitversion.outputs.NuGetVersionV2 }} + assemblyVersion: ${{ steps.gitversion.outputs.AssemblySemVer }} + fileVersion: ${{ steps.gitversion.outputs.MajorMinorPatch }} + informationalVersion: ${{ steps.gitversion.outputs.InformationalVersion }} + + - name: Install .NET 8.0 + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '8.0.x' + + - name: Restore dependencies + run: dotnet restore ./Source/SVGImage/DotNetProjects.SVGImage.csproj + + - name: Build + run: dotnet build --configuration Release DotNetProjects.SVGImage.csproj + working-directory: ./Source/SVGImage + + - name: Generate nuget package. + run: dotnet pack DotNetProjects.SVGImage.csproj --configuration Release -o nupkg + working-directory: ./Source/SVGImage diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..71ac670 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1 @@ +next-version: 5.0.118 diff --git a/Source/dotnet-releaser.toml b/Source/dotnet-releaser.toml deleted file mode 100644 index e9d1e23..0000000 --- a/Source/dotnet-releaser.toml +++ /dev/null @@ -1,6 +0,0 @@ -# configuration file for dotnet-releaser -[msbuild] -project = "./SVGImage/DotNetProjects.SVGImage.csproj" -[github] -user = "jogibear9988" -repo = "SVGImage"