Skip to content

Commit 4a9c37c

Browse files
committed
add release script
1 parent ff2039e commit 4a9c37c

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

.github/release.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Create Release and Publish to NuGet
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_type:
7+
description: 'Release type'
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
16+
jobs:
17+
build-and-release:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Setup .NET
26+
uses: actions/setup-dotnet@v3
27+
with:
28+
dotnet-version: '7.0.x'
29+
30+
# Setup
31+
- name: Install GitVersion
32+
uses: gittools/actions/gitversion/setup@v0.10.2
33+
with:
34+
preferLatestVersion: true
35+
36+
# Fetch version
37+
- name: Determine Version
38+
id: gitversion
39+
uses: gittools/actions/gitversion/execute@v0.10.2
40+
with:
41+
useConfigFile: true
42+
43+
# Gen release notes
44+
- name: Generate Release Notes
45+
id: release_notes
46+
run: |
47+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
48+
if [ -z "$PREVIOUS_TAG" ]; then
49+
COMMITS=$(git log --pretty=format:"- %s" --no-merges)
50+
else
51+
COMMITS=$(git log ${PREVIOUS_TAG}..HEAD --pretty=format:"- %s" --no-merges)
52+
fi
53+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
54+
echo "## What's Changed" >> $GITHUB_ENV
55+
echo "$COMMITS" >> $GITHUB_ENV
56+
echo "EOF" >> $GITHUB_ENV
57+
58+
# Calc new version
59+
- name: Calculate New Version
60+
id: version
61+
run: |
62+
CURRENT_VERSION=${{ steps.gitversion.outputs.semVer }}
63+
IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
64+
MAJOR="${VERSION_PARTS[0]}"
65+
MINOR="${VERSION_PARTS[1]}"
66+
PATCH="${VERSION_PARTS[2]}"
67+
68+
case "${{ github.event.inputs.release_type }}" in
69+
"major")
70+
NEW_VERSION="$((MAJOR + 1)).0.0"
71+
;;
72+
"minor")
73+
NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
74+
;;
75+
"patch")
76+
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
77+
;;
78+
esac
79+
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
80+
81+
# Update csproj
82+
- name: Update Version
83+
run: |
84+
find . -name "*.csproj" -type f -exec sed -i "s/<Version>.*<\/Version>/<Version>${{ env.NEW_VERSION }}<\/Version>/g" {} \;
85+
86+
- name: Restore dependencies
87+
run: dotnet restore
88+
89+
- name: Build
90+
run: dotnet build --configuration Release --no-restore
91+
92+
- name: Pack
93+
run: dotnet pack --configuration Release --no-build --output nupkgs
94+
95+
# Create release
96+
- name: Create Release
97+
id: create_release
98+
uses: actions/create-release@v1
99+
env:
100+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
101+
with:
102+
tag_name: v${{ env.NEW_VERSION }}
103+
release_name: Release v${{ env.NEW_VERSION }}
104+
body: ${{ env.RELEASE_NOTES }}
105+
draft: false
106+
prerelease: false
107+
108+
# Move .nupkg into dist
109+
- name: Upload Release Asset
110+
uses: softprops/action-gh-release@v1
111+
with:
112+
files: ./nupkgs/*.nupkg
113+
tag_name: v${{ env.NEW_VERSION }}
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
117+
# Publish
118+
- name: Push to NuGet
119+
run: dotnet nuget push "./nupkgs/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate
120+
121+
# Commit
122+
- name: Commit version update
123+
run: |
124+
git config --local user.email "action@github.com"
125+
git config --local user.name "GitHub Action"
126+
git add .
127+
git commit -m "Bump version to ${{ env.NEW_VERSION }}"
128+
git tag -a "v${{ env.NEW_VERSION }}" -m "Release v${{ env.NEW_VERSION }}"
129+
git push --follow-tags

0 commit comments

Comments
 (0)