diff --git a/README.md b/README.md index 7f2f8d4..da0fe98 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # synventis-tools -Shared Synventis developer tooling for Git, Maven, Eclipse, deployment helpers, and agent skills. +Shared Synventis developer tooling for Git, Maven, Eclipse, and agent skills. ## Eclipse Config @@ -8,13 +8,13 @@ Shared Eclipse formatter, cleanup, and import-order settings live in [`eclipse/` ## Git Tools -Git helper scripts live in [`git/`](git/), including repository cloning, subtree initialization, -SSH URL conversion, and local cleanup helpers. +Git helper scripts live in [`git/`](git/), including PR creation, subtree initialization, SSH URL +conversion, and local cleanup helpers. ## Maven Tools -Maven helper scripts live in [`mvn/`](mvn/). See [`mvn/README.md`](mvn/README.md) for release and -formatting workflows. +Maven helper scripts live in [`mvn/`](mvn/). See [`mvn/README.md`](mvn/README.md) for dependency +inspection and formatting workflows. ## Agent Skills diff --git a/bin/start-syncel-deploy.sh b/bin/start-syncel-deploy.sh deleted file mode 100755 index e56bcdb..0000000 --- a/bin/start-syncel-deploy.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -set -eo pipefail - -version="${1:-$version}" -[ -z "$version" ] && echo "version missing" && exit 1 -fesHostArr=("fes1" "fes2") -allDeployHosts="cel1 cel2 cel3" - -for deployHost in $allDeployHosts; -do - echo "deploy $version on Host $deployHost" - for fesHost in "${fesHostArr[@]}"; - do - echo '-----------------------------' - echo "remove $deployHost from $fesHost loadbalancing" - echo '-----------------------------' - ssh -t $fesHost "sudo /opt/server-tools/bin/tomcat/fes-set-workers.sh ${allDeployHosts/$deployHost/}" - done - /opt/server-tools/bin/tomcat/deploy-syncel.sh "$deployHost" "$version" -done - -for fesHost in "${fesHostArr[@]}"; -do - echo "--------------------------------------------" - echo "readd all nodes to $fesHost loadbalancing" - echo "--------------------------------------------" - ssh -t $fesHost "sudo /opt/server-tools/bin/tomcat/fes-set-workers.sh ${allDeployHosts}" -done diff --git a/git/clone-repositories.sh b/git/clone-repositories.sh deleted file mode 100755 index dba7378..0000000 --- a/git/clone-repositories.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -read -p "Enter GitHub bearer token: " bearerToken -for project in celements synventis programmonline; do - echo "Fetching $project repositories..." - curl -s --header "Authorization: Bearer $bearerToken"\ - --header "X-GitHub-Api-Version: 2022-11-28"\ - "https://api.github.com/orgs/$project/repos?page=1&per_page=100" | \ - grep "ssh_url" | awk '{print $2}' | sed -e 's:\"::g' -e 's:,$::' >> repo-list.txt -done -read -p "[ENTER] to start cloning. Change local repo names by adding it to the line in repo-list.txt" -cat repo-list.txt | while read url; do git clone $url; done diff --git a/git/create-prs.sh b/git/create-prs.sh new file mode 100755 index 0000000..2f7f5f7 --- /dev/null +++ b/git/create-prs.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +helpstr="Usage: $(basename "$0") ORG BRANCH [GH_PR_CREATE_OPTIONS...]" +org="${1:?$helpstr}" +branch="${2:?$helpstr}" +shift 2 + +repos=$(gh repo list "$org" --source --no-archived --limit 1000 \ + --json nameWithOwner --jq '.[].nameWithOwner') + +for repo in $repos; do + gh api "repos/$repo/branches/$branch" --silent >/dev/null 2>&1 || continue + pr=$(gh pr list --repo "$repo" --head "$branch" --state open \ + --json url --jq '.[0].url // empty') + [ -n "$pr" ] && echo "skip $repo: $pr" && continue + gh pr create --repo "$repo" --head "$branch" "$@" +done diff --git a/git/init-from-subtree.sh b/git/init-from-subtree.sh index ddfb736..f81a809 100755 --- a/git/init-from-subtree.sh +++ b/git/init-from-subtree.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## init a new repository from a sub directory # $1 = sub directory # $2 = github org diff --git a/git/initSshAgent.sh b/git/initSshAgent.sh index ee3d340..644aecd 100755 --- a/git/initSshAgent.sh +++ b/git/initSshAgent.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash eval $(ssh-agent) ssh-add $1 diff --git a/git/pull-and-clean.sh b/git/pull-and-clean.sh index 5bf99b6..e26155f 100755 --- a/git/pull-and-clean.sh +++ b/git/pull-and-clean.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## Marc Sladek , June-Nov 2018 ## pulls and cleans the branches of the current or given and sub git repositories in parallel diff --git a/git/repositories-to-ssh.sh b/git/repositories-to-ssh.sh index 5c33196..ca2db5c 100755 --- a/git/repositories-to-ssh.sh +++ b/git/repositories-to-ssh.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ## Marc Sladek , June 2018 ## sets the ssh url for all repositories diff --git a/jdk/dump-heap.sh b/jdk/dump-heap.sh new file mode 100755 index 0000000..b5619e3 --- /dev/null +++ b/jdk/dump-heap.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -euo pipefail +umask 077 + +service="${1:-web}" +cmd=(docker compose exec -T "$service") +dump="heap-$(date +%Y%m%d-%H%M%S).hprof" +tmpfile="/tmp/$dump" + +cleanup() { + "${cmd[@]}" rm -f "$tmpfile" +} +trap cleanup EXIT + +echo "heap dump may pause the JVM and require up to the heap size in free disk space" +"${cmd[@]}" jcmd 1 VM.flags +"${cmd[@]}" jcmd 1 GC.heap_info +"${cmd[@]}" jcmd 1 GC.heap_dump "$tmpfile" +"${cmd[@]}" cat "$tmpfile" > "$dump" +echo "heap dump written to $dump" diff --git a/jdk/profile-jfr.sh b/jdk/profile-jfr.sh new file mode 100755 index 0000000..a3e11a1 --- /dev/null +++ b/jdk/profile-jfr.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail +umask 077 + +service="${1:-web}" +cmd=(docker compose exec -T "$service") +profile="profile-$(date +%Y%m%d-%H%M%S)" +tmpfile="/tmp/${profile}.jfr" + +cleanup() { + "${cmd[@]}" jcmd 1 JFR.stop name="$profile" >/dev/null 2>&1 || true + "${cmd[@]}" rm -f "$tmpfile" || true +} +trap cleanup EXIT + +"${cmd[@]}" jcmd 1 JFR.start name="$profile" settings=profile filename="$tmpfile" maxsize=512m + +read -r -n 1 -s -p "recording; press any key to stop" && echo + +"${cmd[@]}" jcmd 1 JFR.stop name="$profile" + +"${cmd[@]}" cat "$tmpfile" > "${profile}.jfr" +echo "recording written to ${profile}.jfr" diff --git a/mvn/README.md b/mvn/README.md index 2b4f3cd..6973488 100644 --- a/mvn/README.md +++ b/mvn/README.md @@ -1,13 +1,12 @@ # Maven toolbox scripts -This folder contains a small set of scripts to automate dependency updates across multiple Maven projects in a workspace. +This folder contains helpers for inspecting Maven project dependencies and formatting Java code. ## Prerequisites - Debian/Linux with `bash` - `python3` (for `build-dependency-tree.py`) -- `git` -- `mvn` (and the Maven Versions Plugin available, since `versions:*` goals are used) +- `mvn` - Workspace layout: a directory containing multiple Maven projects with `pom.xml` files All scripts are intended to be run from this folder (they `cd` to the script directory). @@ -55,78 +54,3 @@ Create a tree file for a workspace: ```bash /mvn/build-dependency-tree.py ~/workspace > dependency.tree ``` - ---- - -## `prepare-release` - -Prepares and pushes a git branch for a maven project directory for either: - -- `--mode=release`: update dependencies to latest releases (default mode) -- `--mode=major`: bump the project version to `X.0-SNAPSHOT` and update dependencies to latest snapshots - -It expects a clean `pom.xml`. - -### Usage - -```bash -/mvn/prepare-release.sh [--mode=release] --branch= [project-dir] -/mvn/prepare-release.sh --mode=major --version= --branch= [project-dir] -``` - -### Examples - -Update the current directory project to the latest releases: - -```bash -/mvn/prepare-release.sh --branch=RELEASE -``` - -Prepare major version 7.0-SNAPSHOT for a single project: - -```bash -/mvn/prepare-release.sh --mode=major --version=7 --branch=major-7 ~/workspace/some-project -``` - ---- - -## `major-upgrade` - -Runs a major upgrade across *multiple* Maven projects in a workspace, in dependency order. - -It uses `build-dependency-tree` to generate an ordered list of project directories, then runs `prepare-release --mode=major` for each directory. Progress is checkpointed so the run can be resumed. - -### Usage - -```bash -/mvn/major-upgrade.sh [workspace_dir] -``` - -- ``: required major version number (e.g. `7`) -- `workspace_dir`: optional, defaults to `$HOME/workspace` - -### Files created - -For major version `$v` in workspace `$WS`: - -- `$WS/major-$v.tree` — dependency-ordered list of projects (generated once, reused on reruns) -- `$WS/major-$v.done.tree` — checkpoint file of already-processed directories -- `$WS/major-$v.log` — combined stdout/stderr log of all `prepare-release` runs - -### Example flow - -1. Go to your workspace directory and make sure all repos are cloned. Ensure all repos are -on a clean git state (on `dev` branch). - ```bash - cd $WS - /git/pull-and-clean.sh - ``` -2. Generate a dependency `major-$v.tree` and vet it manually. Entries can be removed if needed. - ```bash - /mvn/build-dependency-tree.py > major-$v.tree - edit major-$v.tree - ``` -3. Run the routine to process all pom's in order. If one fails, fix the repo and rerun the same command to resume. Already completed directories are skipped based on `major-$v.done.tree`. - ```bash - /mvn/major-upgrade.sh $v - ``` diff --git a/mvn/format-java.sh b/mvn/format-java.sh index ba474e3..b381c2b 100644 --- a/mvn/format-java.sh +++ b/mvn/format-java.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail # Calculate script directory @@ -8,30 +8,30 @@ echo "Formatter config: $FORMATTER_CONFIG" # Help message function show_help { - echo "Usage: $0 [options] [maven-args]" - echo "" - echo "Formats Java code using the Synventis code formatter." - echo "" - echo "Options:" - echo " -h, --help Show this help message" - echo "" - echo "All other arguments are passed to the Maven command." + echo "Usage: $0 [options] [maven-args]" + echo "" + echo "Formats Java code using the Synventis code formatter." + echo "" + echo "Options:" + echo " -h, --help Show this help message" + echo "" + echo "All other arguments are passed to the Maven command." } # Parse arguments for help for arg in "$@"; do - case $arg in - -h|--help) - show_help - exit 0 - ;; - esac + case $arg in + -h|--help) + show_help + exit 0 + ;; + esac done # Check if formatter config exists if [ ! -f "$FORMATTER_CONFIG" ]; then - echo "Error: Formatter config file not found at $FORMATTER_CONFIG" - exit 1 + echo "Error: Formatter config file not found at $FORMATTER_CONFIG" + exit 1 fi echo "`pwd`" @@ -41,10 +41,10 @@ JAVA_VERSION=$(mvn help:evaluate -Dexpression=java.version -q -DforceStdout) JAVA_MAJOR_VERSION=$(echo "$JAVA_VERSION" | sed -E 's/^1\.//' | cut -d'.' -f1) mvn net.revelc.code.formatter:formatter-maven-plugin:2.23.0:format \ - -Dconfigfile="$FORMATTER_CONFIG" \ - -Dlineending=LF \ - -Dmaven.compiler.source="$JAVA_MAJOR_VERSION" \ - -Dmaven.compiler.target="$JAVA_MAJOR_VERSION" \ - -Dformatter.overrideConfigCompilerVersion=true \ - -Dproject.build.sourceEncoding=UTF-8 \ - "$@" + -Dconfigfile="$FORMATTER_CONFIG" \ + -Dlineending=LF \ + -Dmaven.compiler.source="$JAVA_MAJOR_VERSION" \ + -Dmaven.compiler.target="$JAVA_MAJOR_VERSION" \ + -Dformatter.overrideConfigCompilerVersion=true \ + -Dproject.build.sourceEncoding=UTF-8 \ + "$@" diff --git a/mvn/major-upgrade.sh b/mvn/major-upgrade.sh deleted file mode 100755 index 7b09925..0000000 --- a/mvn/major-upgrade.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -set -euo pipefail - -v=${1:?"1. argument invalid: major version number"} -WS="${2:-"$HOME/workspace"}" -[ -d "$WS" ] || { echo "workspace '$WS' not found"; exit 1; } -TREE="$WS/major-$v.tree" -TREE_DONE="$WS/major-$v.done.tree" -LOG="$WS/major-$v.log" - -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" -cd "$SCRIPT_DIR" - -if [ ! -r "$TREE" ]; then - ./build-dependency-tree.py "$WS" > "$TREE" -fi -touch "$TREE_DONE" - -while IFS= read -r dir; do - [ -n "$dir" ] || continue - grep -Fxq -- "$dir" "$TREE_DONE" && continue - ./prepare-release.sh --mode=major --version="$v" --branch="major-$v" "$dir" \ - 2>&1 | tee -a "$LOG" - echo "$dir" >> "$TREE_DONE" -done < "$TREE" diff --git a/mvn/prepare-release.sh b/mvn/prepare-release.sh deleted file mode 100755 index 5547778..0000000 --- a/mvn/prepare-release.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash -set -euo pipefail # strict mode - -die() { echo >&2 "failed - $@"; exit 1; } - -MODE="release" # release | major -DIR="" -for arg in "$@"; do - case "$arg" in - --mode=*) MODE="${arg#*=}" ;; - --version=*) VERSION="${arg#*=}" ;; - --branch=*) BRANCH="${arg#*=}" ;; - *) [ -z "$DIR" ] || die "only one path argument allowed"; DIR="$arg" ;; - esac -done - -if [ "${MODE}" = "major" ]; then - echo "${VERSION-}" | grep -E -q '^[0-9]+$' || die "--version invalid: major version number" - VERSION="${VERSION}.0-SNAPSHOT" -elif [ "${MODE}" != "release" ]; then - die "--mode invalid: release | major" -fi -[ -n "${BRANCH-}" ] || die "--branch invalid: branch name" -[ -n "${DIR-}" ] && cd -- "$DIR" -DIR="${DIR:-$(basename "$(pwd)")}" - -echo "------------------------------------------------------------------------" -echo " prepare-${MODE} ${DIR} ${VERSION-}" -echo "------------------------------------------------------------------------" - -[ -f ./pom.xml ] || die "execute in maven project folder" -git diff --quiet ./pom.xml || die "uncommitted changes in pom.xml, please commit or stash first" - -BASE="dev" -INCLUDES="com.celements:*,com.synventis:*,ch.programmonline:*,ch.newjobplacement:*,prog.online:*,online.prog:*" - -git switch -q "${BASE}" -git pull -q origin "${BASE}" - -echo "Preparing branch '${BRANCH}' ..." -if ! git switch -c "${BRANCH}" "${BASE}" 2>/dev/null; then - git switch -q "${BRANCH}" - git pull -q origin "${BRANCH}" 2>/dev/null || true - git merge -q "${BASE}" -fi - -echo "Updating pom.xml ..." -MVN="mvn -q -Dmaven.transfer.listener=warn" -if [ "${MODE}" = "release" ]; then - # doesn't work for milestones with naming schema 'x.y-M1' - $MVN versions:use-releases -U -Dincludes="${INCLUDES}" \ - -DprocessParent=true -DfailIfNotReplaced=true -DgenerateBackupPoms=false - $MVN versions:use-latest-releases -U -Dincludes="${INCLUDES}" \ - -DprocessParent=true -DgenerateBackupPoms=false - COMMIT_MSG="[prepare-release] update dependencies to latest releases" -elif [ "${MODE}" = "major" ]; then - $MVN versions:set -DnewVersion="${VERSION}" -DgenerateBackupPoms=false - $MVN versions:use-latest-versions -U -Dincludes="${INCLUDES}" \ - -DallowSnapshots=true -DprocessParent=true -DgenerateBackupPoms=false - COMMIT_MSG="[prepare-major] update to major version ${VERSION}" -fi - -echo "Executing maven clean install ..." -$MVN validate clean install -Dmaven.test.skip=true - -echo "Pushing branch..." -git add pom.xml -if ! git diff --cached --quiet; then - git commit -m "${COMMIT_MSG}" -fi -git push -q --set-upstream origin "${BRANCH}" - -echo "------------------------------------------------------------------------" -echo " prepare-${MODE} ${DIR} DONE" -echo "------------------------------------------------------------------------" -echo