Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package publish automation #357

Merged
merged 3 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-validate": {
"version": "0.0.1-preview.304",
"commands": [
"dotnet-validate"
]
}
}
}
28 changes: 27 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:

outputs:
dotnet-sdk-version: ${{ steps.setup-dotnet.outputs.dotnet-version }}
dotnet-validate-version: ${{ steps.get-dotnet-validate-version.outputs.dotnet-validate-version }}
package-names: ${{ steps.build.outputs.package-names }}
package-version: ${{ steps.build.outputs.package-version }}

permissions:
attestations: write
Expand Down Expand Up @@ -54,6 +57,7 @@ jobs:
id: setup-dotnet

- name: Build, Test and Package
id: build
shell: pwsh
run: ./build.ps1

Expand Down Expand Up @@ -84,6 +88,13 @@ jobs:
path: ./artifacts/package/release
if-no-files-found: error

- name: Get dotnet-validate version
id: get-dotnet-validate-version
shell: pwsh
run: |
$dotnetValidateVersion = (Get-Content "./.config/dotnet-tools.json" | Out-String | ConvertFrom-Json).tools.'dotnet-validate'.version
"dotnet-validate-version=${dotnetValidateVersion}" >> $env:GITHUB_OUTPUT

validate-packages:
needs: build
runs-on: ubuntu-latest
Expand All @@ -101,8 +112,10 @@ jobs:

- name: Validate NuGet packages
shell: pwsh
env:
DOTNET_VALIDATE_VERSION: ${{ needs.build.outputs.dotnet-validate-version }}
run: |
dotnet tool install --global dotnet-validate --version 0.0.1-preview.304
dotnet tool install --global dotnet-validate --version ${env:DOTNET_VALIDATE_VERSION}
$packages = Get-ChildItem -Filter "*.nupkg" | ForEach-Object { $_.FullName }
$invalidPackages = 0
foreach ($package in $packages) {
Expand Down Expand Up @@ -173,3 +186,16 @@ jobs:
API_KEY: ${{ secrets.NUGET_TOKEN }}
SOURCE: https://api.nuget.org/v3/index.json
run: dotnet nuget push "*.nupkg" --api-key "${API_KEY}" --skip-duplicate --source "${SOURCE}"

- name: Publish nuget_packages_published
uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # v3.0.0
with:
event-type: nuget_packages_published
repository: ${{ github.repository_owner }}/github-automation
token: ${{ secrets.COSTELLOBOT_TOKEN }}
client-payload: |-
{
"repository": "${{ github.repository }}",
"packages": "${{ needs.build.outputs.package-names }}",
"version": "${{ needs.build.outputs.package-version }}"
}
22 changes: 22 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project>
<Target Name="SetNuGetPackageOutputs" AfterTargets="Pack" Condition=" '$(GITHUB_OUTPUT)' != '' ">
<PropertyGroup>
<_PackageNamesPath>$(ArtifactsPath)\package-names.txt</_PackageNamesPath>
</PropertyGroup>
<ReadLinesFromFile File="$(_PackageNamesPath)">
<Output TaskParameter="Lines" ItemName="_PackageNames" />
</ReadLinesFromFile>
<ItemGroup>
<_PackageNames Include="$(PackageId)" />
</ItemGroup>
<RemoveDuplicates Inputs="@(_PackageNames)">
<Output TaskParameter="Filtered" ItemName="_UniquePackageNames" />
</RemoveDuplicates>
<PropertyGroup>
<_UniquePackageNames>@(_UniquePackageNames->'%(Identity)', ',')</_UniquePackageNames>
</PropertyGroup>
<WriteLinesToFile File="$(_PackageNamesPath)" Lines="@(_UniquePackageNames)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<WriteLinesToFile File="$(GITHUB_OUTPUT)" Lines="package-names=$(_UniquePackageNames)" />
<WriteLinesToFile File="$(GITHUB_OUTPUT)" Lines="package-version=$(Version)" />
</Target>
</Project>
1 change: 1 addition & 0 deletions PseudoLocalizer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.vsconfig = .vsconfig
build.ps1 = build.ps1
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
global.json = global.json
LICENSE = LICENSE
Expand Down
8 changes: 5 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ ForEach ($packageProject in $packageProjects) {
DotNetPack $packageProject
}

Write-Host "Running tests..." -ForegroundColor Green
ForEach ($testProject in $testProjects) {
DotNetTest $testProject
if (-Not $SkipTests) {
Write-Host "Running tests..." -ForegroundColor Green
ForEach ($testProject in $testProjects) {
DotNetTest $testProject
}
}