|
| 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