Merge feature/astro-starlight-migration into rel/prod #11
Workflow file for this run
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
| # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
| # see https://www.meziantou.net/publishing-a-nuget-package-following-best-practices-using-github.htm | |
| name: publish | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - 'v[0-9]*.[0-9]*.[0-9]*' | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: "publish" | |
| cancel-in-progress: false | |
| env: | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
| DOTNET_NOLOGO: true | |
| NuGetDirectory: ${{github.workspace}}/nuget | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| create_nuget: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| package_version: ${{ steps.version.outputs.PACKAGE_VERSION }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Determine version from git tag | |
| id: version | |
| run: | | |
| if [[ "$GITHUB_REF" =~ ^refs/tags/v(.+)$ ]]; then | |
| TAG="${BASH_REMATCH[1]}" | |
| else | |
| TAG="0.0.0-local" | |
| fi | |
| echo "Resolved version: $TAG" | |
| echo "PACKAGE_VERSION=$TAG" >> "$GITHUB_OUTPUT" | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: | | |
| 8.0.x | |
| 10.0.x | |
| - name: Restore dependencies | |
| run: dotnet restore Bogoware.Localization.slnx | |
| - name: Build | |
| run: dotnet build Bogoware.Localization.slnx --no-restore -c Release /p:Version=${{ steps.version.outputs.PACKAGE_VERSION }} | |
| - name: Test | |
| run: dotnet test Bogoware.Localization.slnx --no-build --verbosity normal -c Release | |
| - name: Pack | |
| run: | | |
| dotnet pack src/Bogoware.Localization/Bogoware.Localization.csproj --output ${{ env.NuGetDirectory }} -c Release --no-build /p:Version=${{ steps.version.outputs.PACKAGE_VERSION }} | |
| dotnet pack src/Bogoware.Localization.AspNetCore/Bogoware.Localization.AspNetCore.csproj --output ${{ env.NuGetDirectory }} -c Release --no-build /p:Version=${{ steps.version.outputs.PACKAGE_VERSION }} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget | |
| if-no-files-found: error | |
| retention-days: 7 | |
| path: ${{ env.NuGetDirectory }}/*.nupkg | |
| validate_nuget: | |
| runs-on: ubuntu-latest | |
| needs: [ create_nuget ] | |
| steps: | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget | |
| path: ${{ env.NuGetDirectory }} | |
| - name: Install nuget validator | |
| run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global | |
| - name: Validate package | |
| run: | | |
| shopt -s failglob | |
| for file in "${{ env.NuGetDirectory }}"/*.nupkg; do | |
| meziantou.validate-nuget-package --excluded-rules IconMustBeSet,Symbols "$file" | |
| done | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [ create_nuget, validate_nuget ] | |
| environment: nuget-prod | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: nuget | |
| path: ${{ env.NuGetDirectory }} | |
| - name: Validate version | |
| env: | |
| PACKAGE_VERSION: ${{ needs.create_nuget.outputs.package_version }} | |
| run: | | |
| if [ "$PACKAGE_VERSION" = "0.0.0-local" ] || [ -z "$PACKAGE_VERSION" ]; then | |
| echo "::error::Version is '${PACKAGE_VERSION:-empty}' — refusing to publish to NuGet.org" | |
| exit 1 | |
| fi | |
| echo "Publishing version: $PACKAGE_VERSION" | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x | |
| - name: Publish NuGet package | |
| run: | | |
| shopt -s failglob | |
| for file in "${{ env.NuGetDirectory }}"/*.nupkg; do | |
| set +e | |
| output=$(dotnet nuget push "$file" --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate 2>&1) | |
| exit_code=$? | |
| set -e | |
| if echo "$output" | grep -qi 'already exists'; then | |
| echo "::warning::Package already exists: $(basename "$file") — skipped by --skip-duplicate" | |
| elif [ $exit_code -ne 0 ]; then | |
| echo "::error::Failed to push $(basename "$file")" | |
| exit $exit_code | |
| fi | |
| done |