-
Notifications
You must be signed in to change notification settings - Fork 3
158 lines (134 loc) · 5.05 KB
/
release.yml
File metadata and controls
158 lines (134 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Release
on:
push:
branches: ["main"]
permissions:
contents: write
checks: write
pull-requests: write
jobs:
check-version-tag:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
prev_version: ${{ steps.prev_version.outputs.tag }}
is_new_version: ${{ steps.version_exists.outputs.exists == 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get version from ReflectorNet.csproj
id: get_version
shell: bash
run: |
version=$(grep -oP '<Version>\K[^<]+' ReflectorNet/ReflectorNet.csproj)
echo "version=$version" >> $GITHUB_OUTPUT
echo "Found version: $version"
- name: Find previous version tag
id: prev_version
uses: WyriHaximus/github-action-get-previous-tag@v1
- name: Check if tag exists
id: version_exists
uses: mukunku/tag-exists-action@v1.6.0
with:
tag: ${{ steps.get_version.outputs.version }}
- name: Output version info
if: steps.version_exists.outputs.exists == 'true'
run: |
echo "Version tag '${{ steps.get_version.outputs.version }}' already exists. Skipping release process."
- name: Output version info
if: steps.version_exists.outputs.exists == 'false'
run: |
echo "Version tag '${{ steps.get_version.outputs.version }}' does not exist. Proceeding with release process."
build-and-test:
runs-on: ubuntu-latest
needs: check-version-tag
if: needs.check-version-tag.outputs.is_new_version == 'true'
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore --configuration Release
- name: Test
run: dotnet test --no-build --verbosity normal --configuration Release --logger trx
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: "**/TestResults/*.trx"
check_name: "Test Results"
large_files: true
publish-release:
runs-on: ubuntu-latest
needs: [check-version-tag, build-and-test]
if: needs.check-version-tag.outputs.is_new_version == 'true'
outputs:
version: ${{ needs.check-version-tag.outputs.version }}
success: ${{ steps.rel_desc.outputs.success }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Generate release description
id: rel_desc
env:
GH_TOKEN: ${{ github.token }}
run: |
set -e
version=${{ needs.check-version-tag.outputs.version }}
prev_version=${{ needs.check-version-tag.outputs.prev_version }}
repo_url="https://github.com/${GITHUB_REPOSITORY}"
today=$(date +'%B %e, %Y')
echo "repo_url: $repo_url"
echo "today: $today"
echo "# ReflectorNet $version" > release.md
echo "**Released:** *$today*" >> release.md
echo "" >> release.md
echo "---" >> release.md
echo "" >> release.md
if [ -n "$prev_version" ]; then
echo "## Comparison" >> release.md
echo "See every change: [Compare $prev_version...$version]($repo_url/compare/$prev_version...$version)" >> release.md
echo "" >> release.md
echo "---" >> release.md
echo "" >> release.md
echo "## Commit Summary (Newest → Oldest)" >> release.md
for sha in $(git log --pretty=format:'%H' $prev_version..HEAD); do
username=$(gh api repos/${GITHUB_REPOSITORY}/commits/$sha --jq '.author.login // .commit.author.name')
message=$(git log -1 --pretty=format:'%s' $sha)
short_sha=$(git log -1 --pretty=format:'%h' $sha)
echo "- [\`$short_sha\`]($repo_url/commit/$sha) — $message by @$username" >> release.md
done
fi
printf "release_body<<ENDOFRELEASEBODY\n%s\nENDOFRELEASEBODY\n" "$(cat release.md)" >> $GITHUB_OUTPUT
echo "success=true" >> $GITHUB_OUTPUT
- name: Create Tag and Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.check-version-tag.outputs.version }}
name: ${{ needs.check-version-tag.outputs.version }}
body: ${{ steps.rel_desc.outputs.release_body }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy:
needs: publish-release
if: needs.publish-release.outputs.success == 'true'
permissions:
id-token: write
contents: read
uses: ./.github/workflows/deploy.yml
with:
version: ${{ needs.publish-release.outputs.version }}