mirror of
https://github.com/ObNitram/git-release.git
synced 2026-03-22 11:52:19 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c1038a77d | |||
| 43375912d6 | |||
| ffc9ccb8e4 | |||
| 4bcb79a413 |
@@ -30,6 +30,13 @@ jobs:
|
||||
|
||||
Minimal tool to create and publish Git release tags following the vX.Y.Z format.
|
||||
|
||||
```bash
|
||||
# Quick install
|
||||
mkdir -p ${HOME}/.local/bin
|
||||
wget -qO ${HOME}/.local/bin/git-release https://github.com/ObNitram/git-release/releases/download/${{ steps.version.outputs.version }}/git-release
|
||||
chmod +x ${HOME}/.local/bin/git-release
|
||||
```
|
||||
|
||||
See the [README](https://github.com/${{ github.repository }}/blob/${{ steps.version.outputs.version }}/README.md) for more details.
|
||||
files: |
|
||||
git-release
|
||||
43
README.md
43
README.md
@@ -2,19 +2,24 @@
|
||||
|
||||
Minimal tool to create and publish Git release tags following the vX.Y.Z format.
|
||||
|
||||
```bash
|
||||
# Quick install
|
||||
mkdir -p ${HOME}/.local/bin
|
||||
wget -qO ${HOME}/.local/bin/git-release https://github.com/ObNitram/git-release/releases/latest/download/git-release
|
||||
chmod +x ${HOME}/.local/bin/git-release
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
**Single project (default):**
|
||||
- From the repository root: `./git-release` or `git release`
|
||||
- Creates tags in the format `vX.Y.Z`
|
||||
- From the repository root: `git release`
|
||||
- Select release type: patch, minor, major, or cancel
|
||||
- Confirm the new version
|
||||
- The script creates and pushes the new tag
|
||||
|
||||
**Multi-project:**
|
||||
- From the repository root: `./git-release <projectname>` or `git release <projectname>`
|
||||
- Creates tags in the format `<projectname>-vX.Y.Z`
|
||||
- Useful for monorepos with multiple independent release cycles
|
||||
|
||||
The script creates an annotated tag and pushes it to the configured remote.
|
||||
### Multi-project support
|
||||
|
||||
For repositories with multiple projects (monorepos), you can specify the project name as an argument:
|
||||
`git release <projectname>` will create a tag with the following format `<projectname>-vX.Y.Z`
|
||||
|
||||
## Example
|
||||
```
|
||||
@@ -41,13 +46,27 @@ $ git release
|
||||
```
|
||||
|
||||
## Installation
|
||||
- Make the script executable: `chmod +x git-release`
|
||||
- (Optional) Create a hard link in your PATH :
|
||||
`ln "$(pwd)/git-release" "$HOME/.local/bin/git-release"`
|
||||
It's a single script file:
|
||||
- Download the `git-release` script from the repository.
|
||||
- Make it executable: `chmod +x git-release`
|
||||
- Place it in your PATH
|
||||
|
||||
It relies on the fact that if git does not find a command, it will look for a script named `git-<command>` in your PATH.
|
||||
So you can now run `git release` from any git repository.
|
||||
|
||||
|
||||
You can use the following commands to install it:
|
||||
```bash
|
||||
mkdir -p ${HOME}/.local/bin
|
||||
wget -qO ${HOME}/.local/bin/git-release https://github.com/ObNitram/git-release/releases/latest/download/git-release
|
||||
chmod +x ${HOME}/.local/bin/git-release
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Dependencies
|
||||
- git
|
||||
|
||||
## License
|
||||
- MIT License
|
||||
- See the repository `LICENSE` file.
|
||||
24
git-release
24
git-release
@@ -2,20 +2,29 @@
|
||||
# git-release
|
||||
# https://github.com/obnitram/git-release
|
||||
# -------------------------------------------------
|
||||
# Usage: git-release [<projectname>]
|
||||
# Usage: git-release [<projectname>] [-f]
|
||||
# Accepts tags of the form vX.Y.Z or <projectname>-vX.Y.Z (no prerelease/build).
|
||||
# Interactively bumps patch/minor/major, creates an annotated tag,
|
||||
# and pushes it to origin.
|
||||
#
|
||||
# Requirements:
|
||||
# - The last tag MUST match ^v[0-9]+\.[0-9]+\.[0-9]+$ or ^<projectname>-v[0-9]+\.[0-9]+\.[0-9]+$ (or none => starts from v0.0.0)
|
||||
# - Working tree must be clean.
|
||||
# - Working tree must be clean (unless -f is used).
|
||||
|
||||
set -euo pipefail
|
||||
trap 'echo "❌ ${0##*/} failed at line $LINENO." >&2; exit 1' ERR
|
||||
|
||||
# --- Parse optional project name argument ---
|
||||
PROJECT_NAME="${1:-}"
|
||||
# --- Parse arguments ---
|
||||
FORCE_FLAG=false
|
||||
PROJECT_NAME=""
|
||||
|
||||
for arg in "$@"; do
|
||||
if [[ "$arg" == "-f" ]]; then
|
||||
FORCE_FLAG=true
|
||||
else
|
||||
PROJECT_NAME="$arg"
|
||||
fi
|
||||
done
|
||||
if [[ -n "$PROJECT_NAME" ]]; then
|
||||
TAG_PREFIX="${PROJECT_NAME}-v"
|
||||
TAG_PATTERN="${PROJECT_NAME}-v[0-9]*.[0-9]*.[0-9]*"
|
||||
@@ -31,10 +40,13 @@ fi
|
||||
# --- Safety: ensure we are inside a Git repository ---
|
||||
git rev-parse --is-inside-work-tree >/dev/null 2>&1
|
||||
|
||||
# --- Safety: require a clean working tree ---
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
# --- Safety: require a clean working tree (unless -f flag is used) ---
|
||||
if [[ "$FORCE_FLAG" == false ]]; then
|
||||
if ! git diff-index --quiet HEAD --; then
|
||||
echo "⚠️ Uncommitted changes detected. Please commit or stash before releasing."
|
||||
echo " Or use -f flag to force the release anyway."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# --- Get strictly matching tags and pick the highest (lexicographic by version) ---
|
||||
|
||||
Reference in New Issue
Block a user