|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-version-tag: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + outputs: |
| 11 | + version: ${{ steps.get_version.outputs.current-version }} |
| 12 | + prev_tag: ${{ steps.prev_tag.outputs.tag }} |
| 13 | + is_new_tag: ${{ !steps.tag_exists.outputs.exists }} |
| 14 | + steps: |
| 15 | + - name: Checkout repository |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-tags: true |
| 19 | + |
| 20 | + - name: Get version from ReflectorNet.csproj |
| 21 | + id: get_version |
| 22 | + shell: bash |
| 23 | + run: | |
| 24 | + version=$(grep -oP '<Version>\K[^<]+' ReflectorNet/ReflectorNet.csproj) |
| 25 | + echo "current-version=$version" >> $GITHUB_OUTPUT |
| 26 | + echo "Found version: $version" |
| 27 | +
|
| 28 | + - name: Find previous version tag |
| 29 | + id: prev_tag |
| 30 | + uses: WyriHaximus/github-action-get-previous-tag@v1 |
| 31 | + |
| 32 | + - name: Check if tag exists |
| 33 | + id: tag_exists |
| 34 | + uses: mukunku/tag-exists-action@v1.6.0 |
| 35 | + with: |
| 36 | + tag: ${{ steps.get_version.outputs.current-version }} |
| 37 | + |
| 38 | + build-and-test: |
| 39 | + runs-on: ${{ matrix.os }} |
| 40 | + needs: check-version-tag |
| 41 | + if: needs.check-version-tag.outputs.is_new_tag == 'true' |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + os: [ubuntu-latest] |
| 45 | + dotnet-version: [ '9.0.x' ] |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + - name: Setup .NET ${{ matrix.dotnet-version }} |
| 49 | + uses: actions/setup-dotnet@v4 |
| 50 | + with: |
| 51 | + dotnet-version: ${{ matrix.dotnet-version }} |
| 52 | + - name: Restore dependencies |
| 53 | + run: dotnet restore |
| 54 | + - name: Build |
| 55 | + run: dotnet build --no-restore --configuration Release |
| 56 | + - name: Test |
| 57 | + run: dotnet test --no-build --verbosity normal --configuration Release |
| 58 | + |
| 59 | + modify-release: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: [check-version-tag, build-and-test] |
| 62 | + if: needs.check-version-tag.outputs.is_new_tag == 'true' |
| 63 | + steps: |
| 64 | + - name: Checkout repository |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + fetch-depth: 0 |
| 68 | + fetch-tags: true |
| 69 | + |
| 70 | + - name: Generate release description |
| 71 | + id: rel_desc |
| 72 | + env: |
| 73 | + GH_TOKEN: ${{ github.token }} |
| 74 | + run: | |
| 75 | + set -e |
| 76 | + version=${{ needs.check-version-tag.outputs.version }} |
| 77 | + prev_tag=${{ needs.check-version-tag.outputs.prev_tag }} |
| 78 | + repo_url="https://github.com/${GITHUB_REPOSITORY}" |
| 79 | + today=$(date +'%B %e, %Y') |
| 80 | +
|
| 81 | + echo "repo_url: $repo_url" |
| 82 | + echo "today: $today" |
| 83 | +
|
| 84 | + echo "# ReflectorNet Version $version" > release.md |
| 85 | + echo "**Released:** *$today*" >> release.md |
| 86 | +
|
| 87 | + echo "" >> release.md |
| 88 | + echo "---" >> release.md |
| 89 | + echo "" >> release.md |
| 90 | +
|
| 91 | + if [ -n "$prev_tag" ]; then |
| 92 | + echo "## Comparison" >> release.md |
| 93 | + echo "See every change: [Compare $prev_tag...$version]($repo_url/compare/$prev_tag...$version)" >> release.md |
| 94 | +
|
| 95 | + echo "" >> release.md |
| 96 | + echo "---" >> release.md |
| 97 | + echo "" >> release.md |
| 98 | + fi |
| 99 | +
|
| 100 | + echo "## Commit Summary (Newest → Oldest)" >> release.md |
| 101 | + for sha in $(git log --pretty=format:'%H' $prev_tag..HEAD); do |
| 102 | + username=$(gh api repos/${GITHUB_REPOSITORY}/commits/$sha --jq '.author.login // .commit.author.name') |
| 103 | + message=$(git log -1 --pretty=format:'%s' $sha) |
| 104 | + short_sha=$(git log -1 --pretty=format:'%h' $sha) |
| 105 | + echo "- [\`$short_sha\`]($repo_url/commit/$sha) — $message by @$username" >> release.md |
| 106 | + done |
| 107 | + printf "release_body<<ENDOFRELEASEBODY\n%s\nENDOFRELEASEBODY\n" "$(cat release.md)" >> $GITHUB_ENV |
| 108 | + echo "success=true" >> $GITHUB_OUTPUT |
| 109 | +
|
| 110 | + deploy: |
| 111 | + needs: [build-and-test, check-version-tag] |
| 112 | + runs-on: ubuntu-latest |
| 113 | + if: needs.check-version-tag.outputs.is_new_tag == 'true' |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v4 |
| 116 | + - name: Setup .NET |
| 117 | + uses: actions/setup-dotnet@v4 |
| 118 | + with: |
| 119 | + dotnet-version: '9.0.x' |
| 120 | + - name: Restore dependencies |
| 121 | + run: dotnet restore |
| 122 | + - name: Build |
| 123 | + run: dotnet build --no-restore --configuration Release |
| 124 | + - name: Pack |
| 125 | + run: dotnet pack ReflectorNet/ReflectorNet.csproj --no-build --configuration Release --output ./packages |
| 126 | + - name: Publish to NuGet |
| 127 | + run: dotnet nuget push ./packages/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate |
0 commit comments