|
| 1 | +name: Main Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-and-test: |
| 14 | + name: Build, Test and Pack |
| 15 | + uses: ./.github/workflows/build-and-test.yml |
| 16 | + with: |
| 17 | + create-pack: true |
| 18 | + |
| 19 | + create-draft-release: |
| 20 | + name: Create Draft Release |
| 21 | + needs: build-and-test |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v6 |
| 29 | + |
| 30 | + - name: Download NuGet packages |
| 31 | + uses: actions/download-artifact@v4 |
| 32 | + with: |
| 33 | + name: nuget-packages |
| 34 | + path: ./artifacts |
| 35 | + |
| 36 | + - name: Check if tag exists |
| 37 | + id: check-tag |
| 38 | + run: | |
| 39 | + TAG="v${{ needs.build-and-test.outputs.version }}" |
| 40 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 41 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 42 | + echo "⚠️ Tag $TAG already exists" |
| 43 | + else |
| 44 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 45 | + echo "✅ Tag $TAG does not exist yet" |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Delete existing draft releases |
| 49 | + if: steps.check-tag.outputs.exists == 'false' |
| 50 | + env: |
| 51 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + run: | |
| 53 | + echo "Checking for existing draft releases..." |
| 54 | + gh release list --json isDraft,tagName --jq '.[] | select(.isDraft) | .tagName' | while read -r tag_name; do |
| 55 | + echo "Deleting existing draft release: $tag_name" |
| 56 | + gh release delete "$tag_name" --yes --cleanup-tag || echo "Failed to delete release $tag_name" |
| 57 | + done |
| 58 | +
|
| 59 | + - name: Create Draft Release |
| 60 | + if: steps.check-tag.outputs.exists == 'false' |
| 61 | + uses: release-drafter/release-drafter@v6 |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + with: |
| 65 | + config-name: release-drafter.yml |
| 66 | + version: v${{ needs.build-and-test.outputs.version }} |
| 67 | + tag: v${{ needs.build-and-test.outputs.version }} |
| 68 | + name: Version ${{ needs.build-and-test.outputs.version }} |
| 69 | + publish: false |
| 70 | + prerelease: false |
| 71 | + |
| 72 | + - name: Upload packages to draft release |
| 73 | + if: steps.check-tag.outputs.exists == 'false' |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + run: | |
| 77 | + TAG="v${{ needs.build-and-test.outputs.version }}" |
| 78 | + # Wait a moment for the release to be created |
| 79 | + sleep 2 |
| 80 | +
|
| 81 | + # Upload new artifacts to the draft release |
| 82 | + echo "📦 Uploading new NuGet packages..." |
| 83 | + for file in ./artifacts/*.nupkg; do |
| 84 | + gh release upload "$TAG" "$file" --clobber |
| 85 | + done |
| 86 | + echo "✅ Uploaded NuGet packages to draft release" |
| 87 | +
|
| 88 | + - name: Summary |
| 89 | + if: steps.check-tag.outputs.exists == 'false' |
| 90 | + run: | |
| 91 | + echo "✅ Draft release created/updated" >> $GITHUB_STEP_SUMMARY |
| 92 | + echo "Version: v${{ needs.build-and-test.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 93 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "### Next steps:" >> $GITHUB_STEP_SUMMARY |
| 95 | + echo "1. Go to [Releases](../../releases)" >> $GITHUB_STEP_SUMMARY |
| 96 | + echo "2. Review the draft release" >> $GITHUB_STEP_SUMMARY |
| 97 | + echo "3. Edit release notes if needed" >> $GITHUB_STEP_SUMMARY |
| 98 | + echo "4. Publish release to trigger production deployment" >> $GITHUB_STEP_SUMMARY |
| 99 | +
|
| 100 | + - name: Release already exists |
| 101 | + if: steps.check-tag.outputs.exists == 'true' |
| 102 | + run: | |
| 103 | + echo "ℹ️ Release v${{ needs.build-and-test.outputs.version }} already exists" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "No action taken" >> $GITHUB_STEP_SUMMARY |
0 commit comments