-
Notifications
You must be signed in to change notification settings - Fork 15
144 lines (122 loc) · 4.92 KB
/
release.yml
File metadata and controls
144 lines (122 loc) · 4.92 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
name: Nuget-Release
on:
workflow_dispatch:
inputs:
version:
description: 'SemVer (e.g., 1.2.3 or 1.2.3-beta.1)'
required: true
type: string
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.DEFAULT_BRANCH }}
- name: Validate version (SemVer)
id: semver
run: |
set -euo pipefail
VERSION="${{ github.event.inputs.version }}"
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z\.-]+)?$ ]]; then
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
if [[ "$VERSION" == *-* ]]; then
echo "PRERELEASE=true" >> "$GITHUB_ENV"
else
echo "PRERELEASE=false" >> "$GITHUB_ENV"
fi
else
echo "Provided version '$VERSION' is not SemVer." >&2
exit 1
fi
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Set date
run: |
DATE=$(date +'%Y-%m-%d')
echo "DATE=$DATE" >> $GITHUB_ENV
- name: Update CITATION.cff (version + date)
run: |
# Top-level
sed -i "s/^version:.*/version: \"${VERSION}\"/" CITATION.cff
sed -i "s/^date-released:.*/date-released: \"${DATE}\"/" CITATION.cff
# preferred-citation (two-space indent)
sed -i "s/^ version:.*/ version: \"${VERSION}\"/" CITATION.cff
sed -i "s/^ date-released:.*/ date-released: \"${DATE}\"/" CITATION.cff
- name: Commit CITATION.cff to default branch
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CITATION.cff
if ! git diff --cached --quiet; then
git commit -m "chore: release ${VERSION} (update CITATION.cff)"
git push origin HEAD:${DEFAULT_BRANCH}
else
echo "No changes to CITATION.cff."
fi
- name: Install xmlstarlet (for parsing csproj)
run: |
sudo apt-get update
sudo apt-get install -y xmlstarlet
- name: Build RELEASE_NOTES.md from PackageReleaseNotes
run: |
set -euo pipefail
echo "The following items have been fixed in this release:" > RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
mapfile -t CSPROJS < <(git ls-files '*.csproj' | sort)
for csproj in "${CSPROJS[@]}"; do
# PackageId (fallback to file name)
pkg_id="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/PackageId)[1]' "$csproj" 2>/dev/null || true)"
if [ -z "$pkg_id" ]; then
pkg_id="$(basename "$csproj" .csproj)"
fi
# Version (fallback to the workflow input)
pkg_version="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/Version)[1]' "$csproj" 2>/dev/null || true)"
if [ -z "$pkg_version" ]; then
pkg_version="${VERSION}"
fi
# Multiline PackageReleaseNotes
notes="$(xmlstarlet sel -t -v '(//Project/PropertyGroup/PackageReleaseNotes)[1]' "$csproj" 2>/dev/null || true)"
notes="$(printf "%s" "$notes" | sed -e 's/\r$//')"
if [ -n "$notes" ]; then
printf "**%s [%s]**\n" "$pkg_id" "$pkg_version" >> RELEASE_NOTES.md
while IFS= read -r line; do
trimmed="$(printf "%s" "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
if [ -n "$trimmed" ]; then
cleaned="$(printf "%s" "$trimmed" | sed 's/^- \{0,1\}//')"
printf " - %s\n" "$cleaned" >> RELEASE_NOTES.md
fi
done <<< "$notes"
echo "" >> RELEASE_NOTES.md
fi
done
echo "----- RELEASE_NOTES.md -----"
cat RELEASE_NOTES.md
- name: Pack
run: dotnet pack -c Release -o ReleaseBuilds ReqIFSharp.sln
- name: Push to NuGet
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ReleaseBuilds/*.nupkg -k "$NUGET_API_KEY" -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Create annotated tag at this commit
run: |
git tag -a "${VERSION}" -m "Release ${VERSION}"
git push origin "refs/tags/${VERSION}"
- name: Create draft GitHub release (attach EXE)
uses: softprops/action-gh-release@72f2c25fcb47643c292f7107632f7a47c1df5cd8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: true
prerelease: ${{ env.PRERELEASE }}
name: "ReqIFSharp ${{ env.VERSION }}"
tag_name: ${{ env.VERSION }}
body_path: RELEASE_NOTES.md