Skip to content

Commit 7625195

Browse files
[Add] release GH action
1 parent 219a598 commit 7625195

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

.github/workflows/release.yml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
name: Nuget-Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'SemVer (e.g., 1.2.3 or 1.2.3-beta.1)'
8+
required: true
9+
type: string
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
env:
18+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
ref: ${{ env.DEFAULT_BRANCH }}
25+
26+
- name: Validate version (SemVer)
27+
id: semver
28+
run: |
29+
set -euo pipefail
30+
VERSION="${{ github.event.inputs.version }}"
31+
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z\.-]+)?$ ]]; then
32+
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
33+
if [[ "$VERSION" == *-* ]]; then
34+
echo "PRERELEASE=true" >> "$GITHUB_ENV"
35+
else
36+
echo "PRERELEASE=false" >> "$GITHUB_ENV"
37+
fi
38+
else
39+
echo "Provided version '$VERSION' is not SemVer." >&2
40+
exit 1
41+
fi
42+
43+
- name: Setup .NET
44+
uses: actions/setup-dotnet@v4
45+
with:
46+
dotnet-version: '9.0.x'
47+
48+
- name: Set date
49+
run: |
50+
DATE=$(date +'%Y-%m-%d')
51+
echo "DATE=$DATE" >> $GITHUB_ENV
52+
53+
- name: Update CITATION.cff (version + date)
54+
run: |
55+
# Top-level
56+
sed -i "s/^version:.*/version: \"${VERSION}\"/" CITATION.cff
57+
sed -i "s/^date-released:.*/date-released: \"${DATE}\"/" CITATION.cff
58+
# preferred-citation (two-space indent)
59+
sed -i "s/^ version:.*/ version: \"${VERSION}\"/" CITATION.cff
60+
sed -i "s/^ date-released:.*/ date-released: \"${DATE}\"/" CITATION.cff
61+
62+
- name: Commit CITATION.cff to default branch
63+
run: |
64+
set -euo pipefail
65+
git config user.name "github-actions[bot]"
66+
git config user.email "github-actions[bot]@users.noreply.github.com"
67+
git add CITATION.cff
68+
69+
if ! git diff --cached --quiet; then
70+
git commit -m "chore: release ${VERSION} (update CITATION.cff)"
71+
git push origin HEAD:${DEFAULT_BRANCH}
72+
else
73+
echo "No changes to CITATION.cff."
74+
fi
75+
76+
- name: Install xmlstarlet (for parsing csproj)
77+
run: |
78+
sudo apt-get update
79+
sudo apt-get install -y xmlstarlet
80+
81+
- name: Build RELEASE_NOTES.md from PackageReleaseNotes
82+
run: |
83+
set -euo pipefail
84+
echo "The following items have been fixed in this release:" > RELEASE_NOTES.md
85+
echo "" >> RELEASE_NOTES.md
86+
87+
mapfile -t CSPROJS < <(git ls-files '*.csproj' | sort)
88+
89+
for csproj in "${CSPROJS[@]}"; do
90+
# PackageId (fallback to file name)
91+
pkg_id="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/PackageId)[1]' "$csproj" 2>/dev/null || true)"
92+
if [ -z "$pkg_id" ]; then
93+
pkg_id="$(basename "$csproj" .csproj)"
94+
fi
95+
96+
# Version (fallback to the workflow input)
97+
pkg_version="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/Version)[1]' "$csproj" 2>/dev/null || true)"
98+
if [ -z "$pkg_version" ]; then
99+
pkg_version="${VERSION}"
100+
fi
101+
102+
# Multiline PackageReleaseNotes
103+
notes="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/PackageReleaseNotes)[1]' "$csproj" 2>/dev/null || true)"
104+
notes="$(printf "%s" "$notes" | sed -e 's/\r$//')"
105+
106+
if [ -n "$notes" ]; then
107+
printf "**%s [%s]**\n" "$pkg_id" "$pkg_version" >> RELEASE_NOTES.md
108+
while IFS= read -r line; do
109+
trimmed="$(printf "%s" "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
110+
if [ -n "$trimmed" ]; then
111+
cleaned="$(printf "%s" "$trimmed" | sed 's/^- \{0,1\}//')"
112+
printf " - %s\n" "$cleaned" >> RELEASE_NOTES.md
113+
fi
114+
done <<< "$notes"
115+
echo "" >> RELEASE_NOTES.md
116+
fi
117+
done
118+
119+
echo "----- RELEASE_NOTES.md -----"
120+
cat RELEASE_NOTES.md
121+
122+
- name: Pack
123+
run: dotnet pack -c Release -o ReleaseBuilds CDP4-SDK.sln
124+
125+
- name: Push to NuGet
126+
env:
127+
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
128+
run: dotnet nuget push ReleaseBuilds/*.nupkg -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json --skip-duplicate
129+
130+
- name: Create annotated tag at this commit
131+
run: |
132+
git tag -a "${VERSION}" -m "Release ${VERSION}"
133+
git push origin "refs/tags/${VERSION}"
134+
135+
- name: Create draft GitHub release (attach EXE)
136+
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8
137+
env:
138+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
with:
140+
draft: true
141+
prerelease: ${{ env.PRERELEASE }}
142+
name: "CDP4-SDK ${{ env.VERSION }}"
143+
tag_name: ${{ env.VERSION }}
144+
body_path: RELEASE_NOTES.md

0 commit comments

Comments
 (0)