|
5 | 5 | branches: [ main, develop, 'release/*' ] |
6 | 6 | pull_request: |
7 | 7 | branches: [ main, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + release_type: |
| 11 | + description: 'Release type' |
| 12 | + required: true |
| 13 | + default: 'patch' |
| 14 | + type: choice |
| 15 | + options: |
| 16 | + - patch |
| 17 | + - minor |
| 18 | + - major |
8 | 19 |
|
9 | 20 | permissions: |
10 | 21 | contents: write |
|
47 | 58 | name: Pack NuGet Packages |
48 | 59 | runs-on: ubuntu-latest |
49 | 60 | needs: build-and-test |
50 | | - if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.head.ref, 'release/') |
| 61 | + if: (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.head.ref, 'release/')) || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) |
51 | 62 |
|
52 | 63 | steps: |
53 | 64 | - name: Checkout |
|
74 | 85 | name: Publish to NuGet |
75 | 86 | runs-on: ubuntu-latest |
76 | 87 | needs: pack |
77 | | - if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.head.ref, 'release/') |
| 88 | + if: (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.head.ref, 'release/')) || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) |
78 | 89 |
|
79 | 90 | steps: |
80 | 91 | - name: Download packages |
@@ -187,6 +198,79 @@ jobs: |
187 | 198 | console.error(`Failed to delete feature branch ${branchName}:`, error.message); |
188 | 199 | } |
189 | 200 |
|
| 201 | + update-version: |
| 202 | + name: Update Package Version |
| 203 | + runs-on: ubuntu-latest |
| 204 | + if: github.event_name == 'workflow_dispatch' |
| 205 | + |
| 206 | + steps: |
| 207 | + - name: Checkout |
| 208 | + |
| 209 | + with: |
| 210 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 211 | + |
| 212 | + - name: Setup .NET |
| 213 | + |
| 214 | + with: |
| 215 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 216 | + |
| 217 | + - name: Update version |
| 218 | + run: | |
| 219 | + echo "Updating version for ${{ github.event.inputs.release_type }} release" |
| 220 | + |
| 221 | + # Read current version |
| 222 | + CURRENT_VERSION=$(grep '<PowerCSharpVersion>' Directory.Build.props | sed 's/.*<PowerCSharpVersion>\(.*\)<\/PowerCSharpVersion>.*/\1/') |
| 223 | + echo "Current version: $CURRENT_VERSION" |
| 224 | + |
| 225 | + # Split version into parts |
| 226 | + IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" |
| 227 | + MAJOR=${VERSION_PARTS[0]} |
| 228 | + MINOR=${VERSION_PARTS[1]} |
| 229 | + PATCH=${VERSION_PARTS[2]} |
| 230 | + |
| 231 | + # Update version based on release type |
| 232 | + case "${{ github.event.inputs.release_type }}" in |
| 233 | + "major") |
| 234 | + MAJOR=$((MAJOR + 1)) |
| 235 | + MINOR=0 |
| 236 | + PATCH=0 |
| 237 | + ;; |
| 238 | + "minor") |
| 239 | + MINOR=$((MINOR + 1)) |
| 240 | + PATCH=0 |
| 241 | + ;; |
| 242 | + "patch") |
| 243 | + PATCH=$((PATCH + 1)) |
| 244 | + ;; |
| 245 | + esac |
| 246 | + |
| 247 | + NEW_VERSION="$MAJOR.$MINOR.$PATCH" |
| 248 | + echo "New version: $NEW_VERSION" |
| 249 | + |
| 250 | + # Update Directory.Build.props |
| 251 | + sed -i "s/<PowerCSharpVersion>.*<\/PowerCSharpVersion>/<PowerCSharpVersion>$NEW_VERSION<\/PowerCSharpVersion>/" Directory.Build.props |
| 252 | + |
| 253 | + # Commit and push changes |
| 254 | + git config --local user.email "[email protected]" |
| 255 | + git config --local user.name "GitHub Action" |
| 256 | + git add Directory.Build.props |
| 257 | + git commit -m "chore: bump version to $NEW_VERSION" |
| 258 | + git push |
| 259 | + |
| 260 | + - name: Create release tag |
| 261 | + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd |
| 262 | + with: |
| 263 | + script: | |
| 264 | + const version = require('fs').readFileSync('Directory.Build.props', 'utf8') |
| 265 | + .match(/<PowerCSharpVersion>(.+?)<\/PowerCSharpVersion>/)[1]; |
| 266 | + |
| 267 | + await github.rest.git.createRef({ |
| 268 | + owner: context.repo.owner, |
| 269 | + repo: context.repo.repo, |
| 270 | + ref: `refs/tags/v${version}`, |
| 271 | + sha: context.sha |
| 272 | + }); |
| 273 | +
|
190 | 274 | delete-release-branch: |
191 | 275 | name: Delete Release Branch |
192 | 276 | runs-on: ubuntu-latest |
|
0 commit comments