From 20d831cf368f7a55b428829a5ae58a1f3435068e Mon Sep 17 00:00:00 2001 From: Matthias Kay Date: Fri, 10 Jan 2025 07:59:22 +0100 Subject: [PATCH 1/4] SIMULATE --- .gitignore | 5 ++++- simulate.sh | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100755 simulate.sh diff --git a/.gitignore b/.gitignore index 62c8935..65e7ded 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -.idea/ \ No newline at end of file +.idea/ + +# output of simulate.sh +simulate-*/ diff --git a/simulate.sh b/simulate.sh new file mode 100755 index 0000000..8d4ef32 --- /dev/null +++ b/simulate.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +path=$(mktemp -d -t simulate-XXXXX -p .) + +echo "Creating a new repository in $path" +git init "$path" + +cd "$path" +cp ../update_workflows.sh . + +./update_workflows.sh github-only --force . + +eche "Creating the word list file" + +touch workflow.txt From 04ca9ab7b4a91a639d87bfe7ca3a3f27511e0dd1 Mon Sep 17 00:00:00 2001 From: Matthias Kay Date: Fri, 10 Jan 2025 08:54:02 +0100 Subject: [PATCH 2/4] script --- .config/dictionaries/workflow.txt | 3 +- .../workflows/scripts/check_dictionaries.sh | 3 +- README.md | 7 ++++ simulate.sh | 34 ++++++++++++++++--- update_workflows.sh | 25 ++++++++++---- 5 files changed, 58 insertions(+), 14 deletions(-) diff --git a/.config/dictionaries/workflow.txt b/.config/dictionaries/workflow.txt index 70a47bf..bacf05e 100644 --- a/.config/dictionaries/workflow.txt +++ b/.config/dictionaries/workflow.txt @@ -1,3 +1,2 @@ -codeowners -hapag +Hapag nullglob diff --git a/.github/workflows/scripts/check_dictionaries.sh b/.github/workflows/scripts/check_dictionaries.sh index 9865565..5085053 100755 --- a/.github/workflows/scripts/check_dictionaries.sh +++ b/.github/workflows/scripts/check_dictionaries.sh @@ -1,12 +1,11 @@ #!/bin/bash +set -euo pipefail # # Based on the idea outlined in https://github.com/streetsidesoftware/cspell/issues/2536#issuecomment-1126077282 # but with a few modifications to fit the needs of our project. # -set -euo pipefail - MISSPELLED_WORDS_PATH="misspelled-words.txt" CSPELL_CONFIGURATION_FILE=$(find . -name "cspell.json" | head -n 1) diff --git a/README.md b/README.md index 69a1ae1..97425c2 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,13 @@ marked with `USE_WORKFLOW` which are valid within this repository only. Make sure that this block is well formatted, otherwise the update script will fail in the related repository due to prettier. +### Simulate the update + +Use the `simulate.sh` script to check the changes before applying them to the repository. The script + +- creates a new repository called `simulate-*` and applies the changes there +- updates the `workflow.txt` dictionary in your current branch + ### Spell Checker 1. Add the words to the `.config/dictionaries/workflow.txt` file. diff --git a/simulate.sh b/simulate.sh index 8d4ef32..c0b2910 100755 --- a/simulate.sh +++ b/simulate.sh @@ -1,16 +1,42 @@ #!/usr/bin/env bash set -euo pipefail +DICTIONARIES_PATH=".config/dictionaries" + path=$(mktemp -d -t simulate-XXXXX -p .) +path_origin=$(mktemp -d -t simulate-origin-XXXXX -p .) + +echo "Creating the remote repository in $path_origin" +( + git init --initial-branch main "$path_origin" + + cd "$path_origin" + touch README.md + git add README.md + git commit -m "xxx" +) echo "Creating a new repository in $path" -git init "$path" +git init --initial-branch main "$path" cd "$path" +git remote add origin "../$path_origin" +git fetch origin main +git checkout main + cp ../update_workflows.sh . -./update_workflows.sh github-only --force . +./update_workflows.sh github-only --force . --dry-run --local-workflow-path ../ +# script is now located in .github/ +rm update_workflows.sh + +echo "Creating the word list file" + +# don't use the cspell.json file to get the list of misspelled words we need to add to the dictionary +mv .config/cspell.json .config/cspell.json.temp -eche "Creating the word list file" +# renovate: datasource=github-releases depName=streetsidesoftware/cspell +cspell_version="v8.17.1" +npx cspell@${cspell_version:1} . --dot --no-progress --no-summary --unique --words-only --no-exit-code --exclude ".git/**" --exclude ".idea/**" --exclude "$DICTIONARIES_PATH/**" | sort --ignore-case --unique > ../.config/dictionaries/workflow.txt -touch workflow.txt +echo "Dictionary workflow.txt updated in your branch. Please review and commit the changes." diff --git a/update_workflows.sh b/update_workflows.sh index 36981d3..db72eab 100755 --- a/update_workflows.sh +++ b/update_workflows.sh @@ -7,6 +7,7 @@ release_type="auto" force_execution="false" repository_path=$(pwd) dry_run="false" +local_workflow_path="" branch_name="update-workflows-$(date +%s)" @@ -31,7 +32,7 @@ function restart_script_if_newer_version_available() { repository_path=$1 latest_template_path=$2 - current_sha=$(sha256sum "$repository_path/.github/update_workflows.sh" | cut -d " " -f 1) + current_sha=$(sha256sum "$repository_path/.github/update_workflows.sh" | cut -d " " -f 1 || echo "missing") new_sha=$(sha256sum "$latest_template_path/update_workflows.sh" | cut -d " " -f 1) if [ "$current_sha" != "$new_sha" ]; then @@ -114,6 +115,11 @@ function ensure_and_set_parameters_or_exit() { shift shift ;; + --local-workflow-path) + local_workflow_path=$2 + shift + shift + ;; --release-type) release_type=$2 shift @@ -189,13 +195,17 @@ ensure_repo_preconditions_or_exit cd "$repository_path" || exit 8 -echo "Fetching the latest version of the workflows" +latest_template_path=$local_workflow_path -latest_template_path=$(mktemp -d -t repository-templates-XXXXX) -gh repo clone https://github.com/Hapag-Lloyd/Workflow-Templates.git "$latest_template_path" -- -b main -q +if [ -z "$latest_template_path" ]; then + echo "Cloning the latest version of the workflows" + + latest_template_path=$(mktemp -d -t repository-templates-XXXXX) + gh repo clone https://github.com/Hapag-Lloyd/Workflow-Templates.git "$latest_template_path" -- -b main -q -if [ "$force_execution" != "true" ]; then restart_script_if_newer_version_available "$repository_path" "$latest_template_path" +else + echo "Using the local workflow path $latest_template_path and do not check for a newer version of the script" fi echo "Updating the workflows in $repository_path" @@ -370,4 +380,7 @@ pre-commit install -c .config/.pre-commit-config.yaml create_commit_and_pr . -rm -rf "$latest_template_path" +# do not remove the latest template path if it was provided as a parameter +if [ -z "$local_workflow_path" ]; then + rm -rf "$latest_template_path" +fi From 0a574102a86109ccac637329152fffbc5fabd6db Mon Sep 17 00:00:00 2001 From: Matthias Kay Date: Fri, 10 Jan 2025 08:59:02 +0100 Subject: [PATCH 3/4] script --- .config/dictionaries/project.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/dictionaries/project.txt b/.config/dictionaries/project.txt index 971e21f..79b78a4 100644 --- a/.config/dictionaries/project.txt +++ b/.config/dictionaries/project.txt @@ -1,6 +1,7 @@ amannn aquasecurity buildx +codeowners conventionalcommits cpus dockerhub From a22ed9c05fe66b36fe131b138e7608331c3b9bdc Mon Sep 17 00:00:00 2001 From: Matthias Kay Date: Fri, 10 Jan 2025 09:01:17 +0100 Subject: [PATCH 4/4] script --- simulate.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/simulate.sh b/simulate.sh index c0b2910..1ce281b 100755 --- a/simulate.sh +++ b/simulate.sh @@ -39,4 +39,6 @@ mv .config/cspell.json .config/cspell.json.temp cspell_version="v8.17.1" npx cspell@${cspell_version:1} . --dot --no-progress --no-summary --unique --words-only --no-exit-code --exclude ".git/**" --exclude ".idea/**" --exclude "$DICTIONARIES_PATH/**" | sort --ignore-case --unique > ../.config/dictionaries/workflow.txt +mv .config/cspell.json.temp .config/cspell.json + echo "Dictionary workflow.txt updated in your branch. Please review and commit the changes."