|
1 | 1 | name: publish-package |
| 2 | + |
2 | 3 | concurrency: |
3 | 4 | group: ${{ github.workflow }}-${{ github.ref }} |
4 | 5 | cancel-in-progress: true |
|
9 | 10 | - main |
10 | 11 | paths-ignore: |
11 | 12 | - 'test/**' |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + packages: write |
12 | 18 |
|
13 | 19 | env: |
14 | | - "PipelineEnvironment": true |
| 20 | + PipelineEnvironment: true |
| 21 | + NUGET_XMLDOC_MODE: skip |
15 | 22 |
|
16 | 23 | jobs: |
17 | 24 | publish-package: |
18 | 25 | runs-on: ubuntu-latest |
19 | 26 |
|
20 | 27 | steps: |
21 | 28 | - uses: actions/checkout@v6 |
22 | | - |
| 29 | + with: |
| 30 | + persist-credentials: false |
| 31 | + |
23 | 32 | - name: Setting up build version |
| 33 | + shell: bash |
24 | 34 | run: | |
25 | | - version=$(($GITHUB_RUN_NUMBER)) |
26 | | - echo "BUILD_VERSION=4.0.$version" >> ${GITHUB_ENV} |
| 35 | + echo "BUILD_VERSION=4.0.${GITHUB_RUN_NUMBER}" >> "$GITHUB_ENV" |
| 36 | +
|
| 37 | + - name: Get release notes from latest commit |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + { |
| 41 | + echo "PACKAGE_RELEASE_NOTES<<EOF" |
| 42 | + git log -1 --pretty=%B |
| 43 | + echo "EOF" |
| 44 | + } >> "$GITHUB_ENV" |
27 | 45 |
|
28 | 46 | - name: Setup .NET |
29 | 47 | uses: actions/setup-dotnet@v5 |
30 | 48 | with: |
31 | 49 | dotnet-version: 10.0.x |
32 | 50 |
|
33 | | - - name: Install dependencies with retry |
34 | | - shell: bash |
35 | | - run: | |
36 | | - retries=5 |
37 | | - base_wait_time=15 |
38 | | - exponent=2 |
39 | | -
|
40 | | - for i in $(seq 1 $retries); do |
41 | | - echo "::group::dotnet restore (attempt $i/$retries)" |
42 | | - if dotnet restore -v detailed; then |
43 | | - echo "::endgroup::" |
44 | | - echo "✅ dotnet restore succeeded on attempt $i." |
45 | | - break |
46 | | - else |
47 | | - echo "::endgroup::" |
48 | | - if [ "$i" -lt "$retries" ]; then |
49 | | - wait_time=$(( base_wait_time * (exponent ** (i - 1)) )) |
50 | | - echo "❌ dotnet restore failed (attempt $i). Retrying in ${wait_time}s…" |
51 | | - sleep "$wait_time" |
52 | | - else |
53 | | - echo "::error::dotnet restore failed after $retries attempts" |
54 | | - exit 1 |
55 | | - fi |
56 | | - fi |
57 | | - done |
| 51 | + - name: Restore tests |
| 52 | + run: dotnet restore test/Soenneker.Gen.EnumValues.Tests/Soenneker.Gen.EnumValues.Tests.csproj --verbosity minimal |
58 | 53 |
|
59 | 54 | - name: Build |
60 | | - run: dotnet build --configuration Release --no-restore |
| 55 | + run: dotnet build test/Soenneker.Gen.EnumValues.Tests/Soenneker.Gen.EnumValues.Tests.csproj --configuration Release --no-restore --verbosity minimal |
61 | 56 |
|
62 | 57 | - name: Test |
63 | | - run: dotnet test test/Soenneker.Gen.EnumValues.Tests/Soenneker.Gen.EnumValues.Tests.csproj --no-restore --verbosity normal |
| 58 | + run: dotnet test test/Soenneker.Gen.EnumValues.Tests/Soenneker.Gen.EnumValues.Tests.csproj --configuration Release --no-build --no-restore --verbosity normal |
64 | 59 |
|
65 | 60 | - name: Pack |
66 | | - run: dotnet pack --no-build --configuration Release --output . |
| 61 | + shell: bash |
| 62 | + run: | |
| 63 | + mkdir -p artifacts |
| 64 | + dotnet pack src/Soenneker.Gen.EnumValues/Soenneker.Gen.EnumValues.csproj \ |
| 65 | + --configuration Release \ |
| 66 | + --no-build \ |
| 67 | + --no-restore \ |
| 68 | + --output ./artifacts |
67 | 69 |
|
68 | 70 | - name: Publish to NuGet with retry |
| 71 | + shell: bash |
69 | 72 | run: | |
70 | | - nupkg_files=$(find . -name "*.nupkg") |
71 | | - retries=5 |
72 | | - base_wait_time=20 |
73 | | - exponent=3.5 |
74 | | - |
75 | | - for i in $(seq 1 $retries); do |
76 | | - if dotnet nuget push $nupkg_files --source 'https://api.nuget.org/v3/index.json' --api-key ${{secrets.NUGET__TOKEN}} --skip-duplicate; then |
77 | | - break |
78 | | - fi |
79 | | - |
80 | | - if [ $i -lt $retries ]; then |
81 | | - wait_time=$(awk "BEGIN {print int($base_wait_time * ($exponent ^ ($i - 1)))}") |
82 | | - echo "NuGet publish failed, retrying in $wait_time seconds..." |
83 | | - sleep $wait_time |
| 73 | + for i in 1 2 3; do |
| 74 | + dotnet nuget push ./artifacts/*.nupkg \ |
| 75 | + --source "https://api.nuget.org/v3/index.json" \ |
| 76 | + --api-key "${{ secrets.NUGET__TOKEN }}" \ |
| 77 | + --skip-duplicate && break |
| 78 | +
|
| 79 | + if [ "$i" -lt 3 ]; then |
| 80 | + echo "NuGet publish failed, retrying in 10 seconds..." |
| 81 | + sleep 10 |
84 | 82 | else |
85 | | - echo "NuGet publish failed after $retries retries." |
| 83 | + echo "NuGet publish failed after 3 attempts." |
86 | 84 | exit 1 |
87 | 85 | fi |
88 | 86 | done |
89 | 87 |
|
90 | | - - name: Add GitHub NuGet Source |
91 | | - run: | |
92 | | - dotnet nuget add source https://nuget.pkg.github.com/soenneker/index.json \ |
93 | | - --name "github" \ |
94 | | - --username "any" \ |
95 | | - --password ${{ secrets.GH__TOKEN }} \ |
96 | | - --store-password-in-clear-text |
97 | | -
|
98 | 88 | - name: Publish to GitHub Packages |
| 89 | + shell: bash |
99 | 90 | run: | |
100 | | - dotnet nuget push ./*.nupkg \ |
101 | | - --source "github" \ |
102 | | - --api-key ${{ secrets.GH__TOKEN }} |
| 91 | + dotnet nuget push ./artifacts/*.nupkg \ |
| 92 | + --source "https://nuget.pkg.github.com/soenneker/index.json" \ |
| 93 | + --api-key "${{ secrets.GH__TOKEN }}" \ |
| 94 | + --skip-duplicate |
103 | 95 |
|
104 | 96 | - name: Create GitHub Release |
| 97 | + env: |
| 98 | + GH_TOKEN: ${{ secrets.GH__TOKEN }} |
| 99 | + shell: bash |
105 | 100 | run: | |
106 | | - changelog=$(git log -20 --pretty=format:"- %s") |
107 | | - tag_name="v$BUILD_VERSION" |
108 | | -
|
109 | | - json_payload=$( |
110 | | - jq -n \ |
111 | | - --arg tag_name "$tag_name" \ |
112 | | - --arg name "$tag_name" \ |
113 | | - --arg body "$changelog" \ |
114 | | - '{ |
115 | | - tag_name: $tag_name, |
116 | | - name: $name, |
117 | | - body: $body, |
118 | | - draft: false, |
119 | | - prerelease: false |
120 | | - }' |
121 | | - ) |
122 | | -
|
123 | | - curl -s -X POST \ |
124 | | - -H "Authorization: Bearer ${{ secrets.GH__TOKEN }}" \ |
125 | | - -H "Accept: application/vnd.github+json" \ |
126 | | - https://api.github.com/repos/${{ github.repository }}/releases \ |
127 | | - -d "$json_payload" |
| 101 | + gh release create "v$BUILD_VERSION" \ |
| 102 | + --title "v$BUILD_VERSION" \ |
| 103 | + --notes "${{ env.PACKAGE_RELEASE_NOTES }}" |
0 commit comments