diff --git a/README.md b/README.md index 2987254..47dd5c2 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Minimal Bash tools for Arch Linux maintenance and Git release automation. This repository contains two small Bash scripts: - `fullupgrade`: updates an Arch Linux system and performs cleanup -- `makerelease.sh`: merges `dev` into `main` and creates a release tag +- `makerelease.sh`: automates a Git release from `dev` to `main` The project is intentionally small and focused on a simple, opinionated workflow. @@ -42,37 +42,52 @@ sudo ./fullupgrade ## `makerelease.sh` -`makerelease.sh` automates a simple Git release workflow: +`makerelease.sh` automates a Git release workflow: 1. checks that the current branch is `dev` -2. switches to `main` -3. merges `dev` into `main` -4. pushes `main` -5. creates an annotated tag using the provided version and message -6. pushes tags -7. switches back to `dev` +2. verifies the working tree is clean +3. optionally computes a new version from an increment shortcut +4. switches to `main` +5. merges `dev` into `main` +6. pushes `main` +7. creates an annotated tag +8. pushes tags +9. switches back to the original branch on exit ### Usage ```bash -./makerelease.sh VERSION "Release message" +./makerelease.sh VERSION +./makerelease.sh +0.0.1 +./makerelease.sh +0.1 +./makerelease.sh +1 +./makerelease.sh --dry-run VERSION +./makerelease.sh --dry-run +0.0.1 +./makerelease.sh --dry-run +0.1 +./makerelease.sh --dry-run +1 ``` -### Example +### Examples ```bash -./makerelease.sh 1.2.0 "Release 1.2.0" +./makerelease.sh 1.2.0 +./makerelease.sh --dry-run +0.0.1 ``` ### Notes - Run the script from a clean, local Git repository. - Make sure the `dev` branch contains the changes you want to release. +- `VERSION` is used directly as the tag name. +- If `VERSION` starts with `+`, it is treated as an increment based on the latest existing tag. - The script may fail if Git state is unexpected or if a tag already exists. +- The tag message is automatically generated as `Release `. ## Status -This repository is intentionally minimal. `fullupgrade` is hardened with `set -euo pipefail`, while `makerelease.sh` may still need additional validation and safeguards. +This repository is intentionally minimal. +- `fullupgrade` is hardened with `set -euo pipefail`. +- `makerelease.sh` now includes clean-tree checks, duplicate tag protection, increment shortcuts, dry-run support, and a trap to return to the original branch on exit. ## License diff --git a/makerelease.sh b/makerelease.sh index b0d6b33..7389810 100755 --- a/makerelease.sh +++ b/makerelease.sh @@ -1,32 +1,124 @@ #!/bin/bash -declare -r VERSION=${1} -declare -r MESSAGE=${2} +set -euo pipefail + declare -r TAGBRANCH=main declare CURRENTBRANCH="" +declare ORIGBRANCH="" +declare -r ARG1="${1:-}" +declare -r ARG2="${2:-}" +declare is_dry_run=false +declare release_input="" showHelp() { - echo makerelease version + cat <<'EOF' +Usage: + makerelease.sh VERSION + makerelease.sh +0.0.1 + makerelease.sh +0.1 + makerelease.sh +1 + makerelease.sh --dry-run VERSION + makerelease.sh --dry-run +0.0.1 + makerelease.sh --dry-run +0.1 + makerelease.sh --dry-run +1 + +Creates an annotated Git tag from the current dev branch. + +If VERSION starts with +, it is treated as an increment: +- +0.0.1 increments patch +- +0.1 increments minor +- +1 increments major + +Use --dry-run to show the computed release version without running Git actions. + +Requirements: +- run from a clean Git working tree +- current branch must be dev +- main branch must exist locally +EOF } -if [ "${VERSION}" == "" ]; then +cleanup() { + if [ -n "${ORIGBRANCH}" ] && [ "${CURRENTBRANCH}" != "${ORIGBRANCH}" ]; then + git checkout "${ORIGBRANCH}" >/dev/null 2>&1 || true + fi +} + +trap cleanup EXIT + +if [ "${ARG1}" = "--dry-run" ] || [ "${ARG1}" = "-n" ]; then + is_dry_run=true + release_input="${ARG2:-}" +else + release_input="${ARG1}" +fi + +if [ -z "${release_input}" ]; then showHelp echo "" echo "no version provided!" exit 1 fi -CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD) +if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + echo "You are not inside a Git repository!" + exit 1 +fi -if [ ! "${CURRENTBRANCH}" == "dev" ]; then +if [ -n "$(git status --porcelain)" ]; then + echo "Working tree is not clean!" + echo "Commit or stash your changes before creating a release." + exit 1 +fi + +CURRENTBRANCH=$(git rev-parse --abbrev-ref HEAD) +ORIGBRANCH="${CURRENTBRANCH}" + +if [ "${CURRENTBRANCH}" != "dev" ]; then echo "You are not in dev branch!" echo "Use dev branch to make a release!" exit 1 fi +release_tag="${release_input}" +if [ "${release_input}" != "${release_input#+}" ]; then + current_tag="$(git describe --tags --abbrev=0 2>/dev/null || true)" + if [ -z "${current_tag}" ]; then + echo "No existing tag found to increment from!" + exit 1 + fi + case "${release_input}" in + +1) + release_tag="$(printf '%s' "${current_tag}" | awk -F. 'BEGIN{OFS="."} { $1+=1; $2=0; $3=0; print }')" + ;; + +0.1) + release_tag="$(printf '%s' "${current_tag}" | awk -F. 'BEGIN{OFS="."} { $2+=1; $3=0; print }')" + ;; + +0.0.1) + release_tag="$(printf '%s' "${current_tag}" | awk -F. 'BEGIN{OFS="."} { $3+=1; print }')" + ;; + *) + echo "Unsupported increment syntax: ${release_input}" + exit 1 + ;; + esac +fi + +if git rev-parse -q --verify "refs/tags/${release_tag}" >/dev/null; then + echo "Tag ${release_tag} already exists!" + exit 1 +fi + +if [ "${is_dry_run}" = true ]; then + echo "Dry run: computed release tag ${release_tag}" + exit 0 +fi + git checkout "${TAGBRANCH}" -git merge "${CURRENTBRANCH}" +CURRENTBRANCH="${TAGBRANCH}" +git merge "${ORIGBRANCH}" git push -git tag -a "${VERSION}" -m "${MESSAGE}" +git tag -a "${release_tag}" -m "Release ${release_tag}" git push --tags -git checkout "${CURRENTBRANCH}" + +echo "Created release tag ${release_tag}" diff --git a/project.md b/project.md new file mode 100644 index 0000000..aad913c --- /dev/null +++ b/project.md @@ -0,0 +1,86 @@ +# Project Status — fullupgrade + +Last updated: 2026-04-27 + +## Project goal +This repository contains two Bash scripts for system administration and Git release management: +- `fullupgrade`: Arch Linux maintenance script +- `makerelease.sh`: Git release automation script + +The project is intentionally minimal and centered on these two scripts. + +## Current structure +- `fullupgrade`: system update and cleanup +- `makerelease.sh`: release workflow from `dev` to `main` +- `README.md`: English documentation with usage, warnings, and examples +- `LICENSE`: GPLv3 + +## Current analysis + +### 1) `fullupgrade` +Current behavior: +- updates `archlinux-keyring` +- runs `pacman -Syu --noconfirm` +- removes orphaned packages only when any are found +- cleans the pacman cache + +Notes: +- the script already uses `set -euo pipefail` +- it checks for root privileges before running package operations +- it can have a significant system impact + +Recommendations: +- keep documenting the system impact clearly +- consider whether `pacman -Sc` is the right cache cleanup level for every use case + +### 2) `makerelease.sh` +Current behavior: +- supports explicit versions like `1.2.3` +- supports version increments with `+0.0.1`, `+0.1`, and `+1` +- supports `--dry-run` to print the computed release version +- checks that the current branch is `dev` +- verifies the working tree is clean +- checks that the target tag does not already exist +- checks out `main` +- merges `dev` into `main` +- pushes the branch +- creates an annotated tag +- pushes tags +- attempts to return to the original branch on exit + +Notes: +- the script uses `set -euo pipefail` +- the release tag message is now generated automatically as `Release ` +- the script no longer requires a separate release message argument +- the current increment logic assumes simple dotted numeric tags + +Recommendations: +- consider whether tags may need a `v` prefix in the future +- consider validating the version format more strictly if release rules grow +- keep the dry-run behavior documented and aligned with the script + +### 3) `README.md` +Current status: +- the README documents both scripts in English +- it now includes release increments and dry-run usage for `makerelease.sh` + +Recommendations: +- keep it aligned with the actual script behavior +- add more examples only if they improve clarity + +## Project tracking rules +This file should be updated whenever: +- script behavior changes +- documentation changes materially +- new constraints or design decisions are introduced +- release workflow rules evolve + +## Current priorities +1. Secure the Bash scripts +2. Keep documentation aligned with the scripts +3. Make the release workflow more robust + +## Maintenance notes +- Always keep the README, the scripts, and this file consistent. +- If a script changes, update this note immediately. +- If a new usage rule appears, document it here.