|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +env: |
| 9 | + DOTNET_VERSION: '9.0.x' |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + name: Build and Test |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + outputs: |
| 17 | + version: ${{ steps.version.outputs.version }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v5 |
| 22 | + |
| 23 | + - name: Setup .NET |
| 24 | + uses: actions/setup-dotnet@v4 |
| 25 | + with: |
| 26 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 27 | + |
| 28 | + - name: Extract version from Directory.Build.props |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + VERSION=$(grep -oPm1 "(?<=<Version>)[^<]+" Directory.Build.props) |
| 32 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 33 | + echo "Version from Directory.Build.props: $VERSION" |
| 34 | +
|
| 35 | + - name: Restore dependencies |
| 36 | + run: dotnet restore ManagedCode.Orleans.SignalR.sln |
| 37 | + |
| 38 | + - name: Build |
| 39 | + run: dotnet build ManagedCode.Orleans.SignalR.sln --configuration Release --no-restore |
| 40 | + |
| 41 | + - name: Test |
| 42 | + run: dotnet test ManagedCode.Orleans.SignalR.Tests/ManagedCode.Orleans.SignalR.Tests.csproj --configuration Release --no-build --verbosity normal |
| 43 | + |
| 44 | + - name: Pack NuGet packages |
| 45 | + run: dotnet pack ManagedCode.Orleans.SignalR.sln --configuration Release --no-build -p:IncludeSymbols=false -p:SymbolPackageFormat=snupkg --output ./artifacts |
| 46 | + |
| 47 | + - name: Upload artifacts |
| 48 | + uses: actions/upload-artifact@v4 |
| 49 | + with: |
| 50 | + name: nuget-packages |
| 51 | + path: ./artifacts/*.nupkg |
| 52 | + retention-days: 5 |
| 53 | + |
| 54 | + publish-nuget: |
| 55 | + name: Publish to NuGet |
| 56 | + needs: build |
| 57 | + runs-on: ubuntu-latest |
| 58 | + if: github.ref == 'refs/heads/main' |
| 59 | + |
| 60 | + outputs: |
| 61 | + published: ${{ steps.publish.outputs.published }} |
| 62 | + version: ${{ needs.build.outputs.version }} |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout |
| 66 | + uses: actions/checkout@v5 |
| 67 | + |
| 68 | + - name: Download artifacts |
| 69 | + uses: actions/download-artifact@v5 |
| 70 | + with: |
| 71 | + name: nuget-packages |
| 72 | + path: ./artifacts |
| 73 | + |
| 74 | + - name: Setup .NET |
| 75 | + uses: actions/setup-dotnet@v4 |
| 76 | + with: |
| 77 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 78 | + |
| 79 | + - name: Publish to NuGet |
| 80 | + id: publish |
| 81 | + continue-on-error: true |
| 82 | + run: | |
| 83 | + set +e |
| 84 | + OUTPUT="" |
| 85 | + PUBLISHED=false |
| 86 | +
|
| 87 | + for package in ./artifacts/*.nupkg; do |
| 88 | + echo "Publishing $package..." |
| 89 | + RESULT=$(dotnet nuget push "$package" \ |
| 90 | + --api-key ${{ secrets.NUGET_API_KEY }} \ |
| 91 | + --source https://api.nuget.org/v3/index.json \ |
| 92 | + --skip-duplicate 2>&1) |
| 93 | + EXIT_CODE=$? |
| 94 | + echo "$RESULT" |
| 95 | + OUTPUT="$OUTPUT$RESULT" |
| 96 | +
|
| 97 | + if [ $EXIT_CODE -eq 0 ]; then |
| 98 | + echo "Successfully published $package" |
| 99 | + PUBLISHED=true |
| 100 | + elif echo "$RESULT" | grep -q "already exists"; then |
| 101 | + echo "Package already exists, skipping..." |
| 102 | + else |
| 103 | + echo "Failed to publish $package" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | + done |
| 107 | +
|
| 108 | + if [ "$PUBLISHED" = true ] || echo "$OUTPUT" | grep -q "Your package was pushed"; then |
| 109 | + echo "published=true" >> $GITHUB_OUTPUT |
| 110 | + echo "At least one package was successfully published" |
| 111 | + else |
| 112 | + echo "published=false" >> $GITHUB_OUTPUT |
| 113 | + echo "No new packages were published (all already exist)" |
| 114 | + fi |
| 115 | +
|
| 116 | + create-release: |
| 117 | + name: Create GitHub Release and Tag |
| 118 | + needs: publish-nuget |
| 119 | + runs-on: ubuntu-latest |
| 120 | + if: needs.publish-nuget.outputs.published == 'true' |
| 121 | + permissions: |
| 122 | + contents: write |
| 123 | + |
| 124 | + steps: |
| 125 | + - name: Checkout |
| 126 | + uses: actions/checkout@v5 |
| 127 | + with: |
| 128 | + fetch-depth: 0 |
| 129 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 130 | + |
| 131 | + - name: Download artifacts |
| 132 | + uses: actions/download-artifact@v5 |
| 133 | + with: |
| 134 | + name: nuget-packages |
| 135 | + path: ./artifacts |
| 136 | + |
| 137 | + - name: Create and push tag |
| 138 | + id: create_tag |
| 139 | + run: | |
| 140 | + VERSION="${{ needs.publish-nuget.outputs.version }}" |
| 141 | + TAG="v$VERSION" |
| 142 | +
|
| 143 | + git config user.name "github-actions[bot]" |
| 144 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 145 | +
|
| 146 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 147 | + echo "Tag $TAG already exists" |
| 148 | + echo "tag_exists=true" >> $GITHUB_OUTPUT |
| 149 | + else |
| 150 | + echo "Creating tag $TAG" |
| 151 | + git tag -a "$TAG" -m "Release $VERSION" |
| 152 | + git push origin "$TAG" |
| 153 | + echo "tag_exists=false" >> $GITHUB_OUTPUT |
| 154 | + fi |
| 155 | +
|
| 156 | + - name: Get previous tag |
| 157 | + id: prev_tag |
| 158 | + run: | |
| 159 | + CURRENT_TAG="v${{ needs.publish-nuget.outputs.version }}" |
| 160 | + PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -A1 "^$CURRENT_TAG$" | tail -n1 || echo "") |
| 161 | + if [ "$PREVIOUS_TAG" = "$CURRENT_TAG" ] || [ -z "$PREVIOUS_TAG" ]; then |
| 162 | + PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -v "^$CURRENT_TAG$" | head -n1 || echo "") |
| 163 | + fi |
| 164 | + echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT |
| 165 | + echo "Current tag: $CURRENT_TAG" |
| 166 | + echo "Previous tag: $PREVIOUS_TAG" |
| 167 | +
|
| 168 | + - name: Generate release notes |
| 169 | + id: release_notes |
| 170 | + run: | |
| 171 | + VERSION="${{ needs.publish-nuget.outputs.version }}" |
| 172 | + CURRENT_TAG="v$VERSION" |
| 173 | + PREVIOUS_TAG="${{ steps.prev_tag.outputs.previous_tag }}" |
| 174 | +
|
| 175 | + echo "# Release $VERSION" > release_notes.md |
| 176 | + echo "" >> release_notes.md |
| 177 | + echo "Released on $(date +'%Y-%m-%d')" >> release_notes.md |
| 178 | + echo "" >> release_notes.md |
| 179 | +
|
| 180 | + if [ -n "$PREVIOUS_TAG" ]; then |
| 181 | + echo "## 📋 Changes since $PREVIOUS_TAG" >> release_notes.md |
| 182 | + echo "" >> release_notes.md |
| 183 | +
|
| 184 | + echo "### ✨ Features" >> release_notes.md |
| 185 | + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --grep="^feat" --grep="^feature" >> release_notes.md || true |
| 186 | + echo "" >> release_notes.md |
| 187 | +
|
| 188 | + echo "### 🐛 Bug Fixes" >> release_notes.md |
| 189 | + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --grep="^fix" --grep="^bugfix" >> release_notes.md || true |
| 190 | + echo "" >> release_notes.md |
| 191 | +
|
| 192 | + echo "### 📚 Documentation" >> release_notes.md |
| 193 | + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --grep="^docs" --grep="^doc" >> release_notes.md || true |
| 194 | + echo "" >> release_notes.md |
| 195 | +
|
| 196 | + echo "### 🔧 Other Changes" >> release_notes.md |
| 197 | + git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD --invert-grep --grep="^feat" --grep="^feature" --grep="^fix" --grep="^bugfix" --grep="^docs" --grep="^doc" >> release_notes.md || true |
| 198 | + echo "" >> release_notes.md |
| 199 | + else |
| 200 | + echo "## 🎉 Initial Release" >> release_notes.md |
| 201 | + echo "" >> release_notes.md |
| 202 | + echo "### Recent Changes" >> release_notes.md |
| 203 | + git log --pretty=format:"- %s (%h)" --max-count=20 >> release_notes.md |
| 204 | + echo "" >> release_notes.md |
| 205 | + fi |
| 206 | +
|
| 207 | + echo "" >> release_notes.md |
| 208 | + echo "## 📦 NuGet Packages" >> release_notes.md |
| 209 | + echo "" >> release_notes.md |
| 210 | + for package in ./artifacts/*.nupkg; do |
| 211 | + PACKAGE_NAME=$(basename "$package" .nupkg) |
| 212 | + BASE_NAME=$(echo "$PACKAGE_NAME" | sed "s/\.$VERSION//") |
| 213 | + echo "- [$BASE_NAME v$VERSION](https://www.nuget.org/packages/$BASE_NAME/$VERSION)" >> release_notes.md |
| 214 | + done |
| 215 | +
|
| 216 | + echo "" >> release_notes.md |
| 217 | + echo "---" >> release_notes.md |
| 218 | + echo "*This release was automatically created by GitHub Actions*" >> release_notes.md |
| 219 | +
|
| 220 | + - name: Create GitHub Release |
| 221 | + uses: softprops/action-gh-release@v2 |
| 222 | + with: |
| 223 | + tag_name: v${{ needs.publish-nuget.outputs.version }} |
| 224 | + name: v${{ needs.publish-nuget.outputs.version }} |
| 225 | + body_path: release_notes.md |
| 226 | + draft: false |
| 227 | + prerelease: false |
| 228 | + files: ./artifacts/*.nupkg |
| 229 | + token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments