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