Skip to content

Commit f161049

Browse files
committed
Added Git commit hook to insert the current NuGetPackageVersion into a placeholder token {{vnext}} in the AnalyzerReleases.Shipped.md file, only if preceeded by "## Release ".
1 parent a8f65eb commit f161049

4 files changed

Lines changed: 100 additions & 2 deletions

File tree

.editorconfig

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,23 @@ indent_style = space
146146
indent_size = 4
147147
trim_trailing_whitespace = false
148148
insert_final_newline = true
149-
resharper_enforce_empty_line_at_end_of_file = true
149+
resharper_enforce_empty_line_at_end_of_file = true
150+
151+
# ========================================
152+
# Bash
153+
# ========================================
154+
[*.sh]
155+
indent_style = space
156+
indent_size = 4
157+
trim_trailing_whitespace = false
158+
insert_final_newline = true
159+
resharper_enforce_empty_line_at_end_of_file = true
160+
end_of_line = lf
161+
162+
[eng/git-hooks/*]
163+
indent_style = space
164+
indent_size = 4
165+
trim_trailing_whitespace = false
166+
insert_final_newline = true
167+
resharper_enforce_empty_line_at_end_of_file = true
168+
end_of_line = lf

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@
2727
# Git metadata
2828
.gitattributes text eol=lf
2929
.gitignore text eol=lf
30+
31+
# Ensure shell scripts always use LF
32+
*.sh text eol=lf
33+
eng/git-hooks/* text eol=lf
34+
35+
# Ensure batch scripts always use CRLF
36+
*.bat eol=crlf
37+
*.cmd eol=crlf

eng/eng.folderproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
<ItemGroup>
2323
<None Include="**/*" Exclude="**/*.folderproj;**/obj/*;**/bin/*" />
2424
</ItemGroup>
25-
</Project>
25+
</Project>

eng/git-hooks/post-commit

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/sh
2+
# eng/git-hooks/post-commit
3+
# Replaces {{vnext}} in "## Release {{vnext}}" with the NuGetPackageVersion
4+
# only if the file contains the token. Safe from infinite loops.
5+
6+
# Licensed to the Apache Software Foundation (ASF) under one
7+
# or more contributor license agreements. See the NOTICE file
8+
# distributed with this work for additional information
9+
# regarding copyright ownership. The ASF licenses this file
10+
# to you under the Apache License, Version 2.0 (the
11+
# "License"); you may not use this file except in compliance
12+
# with the License. You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing,
17+
# software distributed under the License is distributed on an
18+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19+
# KIND, either express or implied. See the License for the
20+
# specific language governing permissions and limitations
21+
# under the License.
22+
23+
file="src/Lucene.Net.CodeAnalysis.Dev/AnalyzerReleases.Shipped.md"
24+
token="{{vnext}}"
25+
26+
# Bail if already running to prevent infinite loop
27+
if [ -n "$POST_COMMIT_RUNNING" ]; then
28+
exit 0
29+
fi
30+
31+
# Bail if the file doesn't exist
32+
[ ! -f "$file" ] && exit 0
33+
34+
# Bail if the token doesn't exist in the file
35+
if ! grep -q "## Release $token" "$file"; then
36+
exit 0
37+
fi
38+
39+
# Check if nbgv tool is installed
40+
if ! command -v nbgv >/dev/null 2>&1; then
41+
cat <<EOF
42+
ERROR: The AnalyzerReleases.Shipped.md $token token replacement failed.
43+
The 'nbgv' tool is required but not installed.
44+
45+
To recover manually:
46+
47+
1. Install the nbgv tool (see the docs/make-release.md documentation)
48+
2. Run: nbgv get-version -v NuGetPackageVersion
49+
3. In $file, replace the $token token with the version returned from step 2
50+
4. Run: git add $file && git commit --amend --no-edit
51+
5. Run: nbgv get-version -v NuGetPackageVersion again to ensure the version is the same as step 2 before proceeding
52+
EOF
53+
exit 1
54+
fi
55+
56+
# Set flag to prevent recursion
57+
export POST_COMMIT_RUNNING=1
58+
59+
# Get the NuGet version
60+
version=$(nbgv get-version -v NuGetPackageVersion)
61+
echo "Replacing '$token' with '$version' in '$file'"
62+
63+
# Replace {{vnext}} only in lines starting with "## Release "
64+
sed -i.bak "/^## Release /s/$token/$version/g" "$file" && rm "$file.bak"
65+
66+
# Re-stage the file and amend the commit (this triggers post-commit again, but recursion is prevented)
67+
git add "$file"
68+
git commit --amend --no-edit
69+
70+
# Unset the flag (optional, since the script ends)
71+
unset POST_COMMIT_RUNNING

0 commit comments

Comments
 (0)