@lekman/devops-toolkit-tasks 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +101 -42
- package/dist/build.js +499 -0
- package/dist/help.js +151 -0
- package/dist/register.js +1273 -0
- package/package.json +29 -20
- package/tasks/core.yml +45 -0
- package/tasks/package.yml +28 -0
- package/common/ai.yml +0 -106
- package/common/aws.yml +0 -41
- package/common/docker.yml +0 -68
- package/common/git.yml +0 -295
- package/common/modules.yml +0 -41
- package/common/security.yml +0 -22
- package/docs/README.md +0 -238
package/package.json
CHANGED
|
@@ -1,31 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lekman/devops-toolkit-tasks",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Shared
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Shared Task (taskfile.dev) files: a help page built from the Taskfile, and a build that detects the languages a repository uses",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./package.json": "./package.json"
|
|
8
|
+
},
|
|
5
9
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"README.md"
|
|
10
|
+
"dist/*.js",
|
|
11
|
+
"tasks/*.yml",
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
9
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "bun build bin/help.ts bin/build.ts bin/register.ts --target=bun --outdir dist && bun run sync",
|
|
17
|
+
"sync": "bun scripts/copy-tasks.ts",
|
|
18
|
+
"typecheck": "tsc --noEmit",
|
|
19
|
+
"lint": "eslint src/ bin/ scripts/ tests/",
|
|
20
|
+
"test": "bun test",
|
|
21
|
+
"test:coverage": "bun test --reporter=junit --reporter-outfile=junit.xml --coverage --coverage-reporter=lcov"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@lekman/devops-toolkit": "workspace:*",
|
|
25
|
+
"@lekman/eslint-config": "workspace:*",
|
|
26
|
+
"@types/bun": "^1.3.11",
|
|
27
|
+
"eslint": "^10.2.0",
|
|
28
|
+
"typescript": "^6.0"
|
|
29
|
+
},
|
|
10
30
|
"publishConfig": {
|
|
11
31
|
"registry": "https://registry.npmjs.org/",
|
|
12
32
|
"access": "public"
|
|
13
33
|
},
|
|
34
|
+
"license": "MIT",
|
|
14
35
|
"repository": {
|
|
15
36
|
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/lekman/devops-toolkit.git"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"prepublishOnly": "npm run test",
|
|
20
|
-
"test": "exit 0",
|
|
21
|
-
"version": "git add -A tasks",
|
|
22
|
-
"build": "exit 0"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"task",
|
|
26
|
-
"devops",
|
|
27
|
-
"automation"
|
|
28
|
-
],
|
|
29
|
-
"author": "SecNord",
|
|
30
|
-
"license": "UNLICENSED"
|
|
37
|
+
"url": "git+https://github.com/lekman/devops-toolkit.git",
|
|
38
|
+
"directory": "packages/tasks"
|
|
39
|
+
}
|
|
31
40
|
}
|
package/tasks/core.yml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://taskfile.dev/schema.json
|
|
2
|
+
version: "3"
|
|
3
|
+
|
|
4
|
+
# The tasks every repository gets: a help page and a build. Include this
|
|
5
|
+
# file with `flatten: true` and `dir: .`, so `task`, `task help` and
|
|
6
|
+
# `task build` work at the top level:
|
|
7
|
+
#
|
|
8
|
+
# includes:
|
|
9
|
+
# core:
|
|
10
|
+
# taskfile: node_modules/@lekman/devops-toolkit-tasks/tasks/core.yml
|
|
11
|
+
# dir: .
|
|
12
|
+
# flatten: true
|
|
13
|
+
#
|
|
14
|
+
# Flattening keeps a task's name as written here, so the build is
|
|
15
|
+
# `core:build`, with `build` as its alias.
|
|
16
|
+
|
|
17
|
+
vars:
|
|
18
|
+
# How to run the package's two programs. An installed package has them in
|
|
19
|
+
# dist/, beside the tasks/ folder that holds this file. This
|
|
20
|
+
# repository passes its TypeScript sources instead (see Taskfile.yml).
|
|
21
|
+
TASKS_HELP: '{{.TASKS_HELP | default (printf "bun \"%s/../dist/help.js\"" .TASKFILE_DIR)}}'
|
|
22
|
+
TASKS_BUILD: '{{.TASKS_BUILD | default (printf "bun \"%s/../dist/build.js\"" .TASKFILE_DIR)}}'
|
|
23
|
+
# The line above the help page. Defaults to the repository folder's name.
|
|
24
|
+
HELP_TITLE: "{{.HELP_TITLE | default (base .ROOT_DIR)}}"
|
|
25
|
+
# The folder that holds the Python project, as CI's `python-dir` input.
|
|
26
|
+
PYTHON_DIR: '{{.PYTHON_DIR | default "."}}'
|
|
27
|
+
|
|
28
|
+
tasks:
|
|
29
|
+
default:
|
|
30
|
+
desc: Show every task, grouped by the Taskfile that defines it
|
|
31
|
+
aliases: [help, h]
|
|
32
|
+
silent: true
|
|
33
|
+
cmds:
|
|
34
|
+
- >-
|
|
35
|
+
{{.TASKS_HELP}} --dir "{{.ROOT_DIR}}" --task "{{.TASK_EXE}}"
|
|
36
|
+
--title "{{.HELP_TITLE}}"
|
|
37
|
+
|
|
38
|
+
core:build:
|
|
39
|
+
desc: Build what the repository declares (Node, Python), detected as CI does; -- --dry-run shows the plan
|
|
40
|
+
aliases: [build]
|
|
41
|
+
silent: true
|
|
42
|
+
cmds:
|
|
43
|
+
- >-
|
|
44
|
+
{{.TASKS_BUILD}} --dir "{{.ROOT_DIR}}" --python-dir "{{.PYTHON_DIR}}"
|
|
45
|
+
{{.CLI_ARGS}}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://taskfile.dev/schema.json
|
|
2
|
+
version: "3"
|
|
3
|
+
|
|
4
|
+
# Onboards the repository's publishable packages to their registries.
|
|
5
|
+
# Include it under a namespace, with `dir: .`:
|
|
6
|
+
#
|
|
7
|
+
# includes:
|
|
8
|
+
# package:
|
|
9
|
+
# taskfile: node_modules/@lekman/devops-toolkit-tasks/tasks/package.yml
|
|
10
|
+
# dir: .
|
|
11
|
+
# aliases: [pkg]
|
|
12
|
+
#
|
|
13
|
+
# `task package:register` prints a checklist per package. With
|
|
14
|
+
# `-- --apply` it makes the changes it can, asking before each, and prints
|
|
15
|
+
# the pages and values for the steps only the owner can take.
|
|
16
|
+
|
|
17
|
+
vars:
|
|
18
|
+
# How to run the package's program; see core.yml.
|
|
19
|
+
TASKS_REGISTER: '{{.TASKS_REGISTER | default (printf "bun \"%s/../dist/register.js\"" .TASKFILE_DIR)}}'
|
|
20
|
+
|
|
21
|
+
tasks:
|
|
22
|
+
register:
|
|
23
|
+
desc: Check what each package needs to publish from CI; -- --apply sets up what it can, asking first
|
|
24
|
+
aliases: [reg]
|
|
25
|
+
silent: true
|
|
26
|
+
interactive: true
|
|
27
|
+
cmds:
|
|
28
|
+
- '{{.TASKS_REGISTER}} --dir "{{.ROOT_DIR}}" {{.CLI_ARGS}}'
|
package/common/ai.yml
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
version: "3"
|
|
2
|
-
|
|
3
|
-
vars:
|
|
4
|
-
# Color codes for output
|
|
5
|
-
CYAN: '\033[0;36m'
|
|
6
|
-
GREEN: '\033[0;32m'
|
|
7
|
-
YELLOW: '\033[0;33m'
|
|
8
|
-
RED: '\033[0;31m'
|
|
9
|
-
NC: '\033[0m' # No Color
|
|
10
|
-
|
|
11
|
-
tasks:
|
|
12
|
-
# Setup AI development tools
|
|
13
|
-
setup:
|
|
14
|
-
desc: Setup AI development tools (Claude, Codex, Cursor, GitHub Copilot, Task Master)
|
|
15
|
-
silent: true
|
|
16
|
-
cmds:
|
|
17
|
-
- |
|
|
18
|
-
# Check if npm is installed
|
|
19
|
-
if ! command -v npm &> /dev/null; then
|
|
20
|
-
echo -e "{{.RED}}Error: npm is not installed{{.NC}}"
|
|
21
|
-
echo "Please install Node.js and npm first:"
|
|
22
|
-
echo " brew install node"
|
|
23
|
-
exit 1
|
|
24
|
-
fi
|
|
25
|
-
|
|
26
|
-
# Function to check and install npm package
|
|
27
|
-
check_and_install_npm() {
|
|
28
|
-
local package=$1
|
|
29
|
-
local version=$(npm list -g $package 2>/dev/null | grep $package || echo "")
|
|
30
|
-
|
|
31
|
-
if [ -z "$version" ]; then
|
|
32
|
-
echo -e "{{.CYAN}}Installing $package...{{.NC}}"
|
|
33
|
-
npm install -g $package --silent
|
|
34
|
-
else
|
|
35
|
-
echo -e "{{.CYAN}}Updating $package to latest version...{{.NC}}"
|
|
36
|
-
npm install -g $package@latest --silent
|
|
37
|
-
fi
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
# Install/Update npm packages
|
|
41
|
-
check_and_install_npm "@anthropic-ai/claude-code"
|
|
42
|
-
check_and_install_npm "@openai/codex"
|
|
43
|
-
check_and_install_npm "task-master-ai"
|
|
44
|
-
|
|
45
|
-
# Check if Cursor is installed
|
|
46
|
-
if [ ! -d "/Applications/Cursor.app" ]; then
|
|
47
|
-
echo -e "{{.CYAN}}Installing Cursor...{{.NC}}"
|
|
48
|
-
# Download and install Cursor
|
|
49
|
-
curl -L "https://download.cursor.sh/mac" -o /tmp/cursor.dmg
|
|
50
|
-
hdiutil attach /tmp/cursor.dmg
|
|
51
|
-
cp -R "/Volumes/Cursor/Cursor.app" /Applications/
|
|
52
|
-
hdiutil detach "/Volumes/Cursor"
|
|
53
|
-
rm /tmp/cursor.dmg
|
|
54
|
-
else
|
|
55
|
-
echo -e "{{.GREEN}}Cursor is already installed{{.NC}}"
|
|
56
|
-
echo -e "{{.YELLOW}}Note: Please check for updates manually in the Cursor app{{.NC}}"
|
|
57
|
-
fi
|
|
58
|
-
|
|
59
|
-
# Check if Cursor CLI is available
|
|
60
|
-
if ! command -v cursor &> /dev/null; then
|
|
61
|
-
echo -e "{{.YELLOW}}Note: Cursor CLI not found. Some extension management features may be limited.{{.NC}}"
|
|
62
|
-
echo "To enable CLI features, please:"
|
|
63
|
-
echo "1. Open Cursor"
|
|
64
|
-
echo "2. Go to Settings"
|
|
65
|
-
echo "3. Enable 'Install Command Line Tools'"
|
|
66
|
-
else
|
|
67
|
-
# Install GitHub Copilot extension
|
|
68
|
-
echo -e "{{.CYAN}}Installing GitHub Copilot extension...{{.NC}}"
|
|
69
|
-
cursor --install-extension GitHub.copilot --force > /dev/null 2>&1
|
|
70
|
-
|
|
71
|
-
# Check for workspace recommended extensions
|
|
72
|
-
if [ -d ".vscode" ] && [ -f ".vscode/extensions.json" ]; then
|
|
73
|
-
# Extract recommended extensions
|
|
74
|
-
recommended_extensions=$(jq -r '.recommendations[]' .vscode/extensions.json 2>/dev/null)
|
|
75
|
-
|
|
76
|
-
if [ ! -z "$recommended_extensions" ]; then
|
|
77
|
-
echo -e "{{.CYAN}}Found workspace recommended extensions:{{.NC}}"
|
|
78
|
-
echo "$recommended_extensions"
|
|
79
|
-
|
|
80
|
-
# Ask user if they want to install recommended extensions
|
|
81
|
-
echo -n "Do you want to install these workspace recommended extensions? (y/N) "
|
|
82
|
-
read answer
|
|
83
|
-
|
|
84
|
-
if [[ "$answer" =~ ^[Yy]$ ]]; then
|
|
85
|
-
echo -e "{{.CYAN}}Installing workspace recommended extensions...{{.NC}}"
|
|
86
|
-
for ext in $recommended_extensions; do
|
|
87
|
-
echo -e "{{.CYAN}}Installing $ext...{{.NC}}"
|
|
88
|
-
cursor --install-extension "$ext" --force > /dev/null 2>&1
|
|
89
|
-
done
|
|
90
|
-
echo -e "{{.GREEN}}Workspace recommended extensions installed!{{.NC}}"
|
|
91
|
-
else
|
|
92
|
-
echo -e "{{.YELLOW}}Skipping workspace recommended extensions.{{.NC}}"
|
|
93
|
-
fi
|
|
94
|
-
else
|
|
95
|
-
echo -e "{{.YELLOW}}No recommended extensions found in workspace.{{.NC}}"
|
|
96
|
-
fi
|
|
97
|
-
fi
|
|
98
|
-
fi
|
|
99
|
-
|
|
100
|
-
echo -e "{{.GREEN}}AI development tools setup complete!{{.NC}}"
|
|
101
|
-
echo -e "{{.YELLOW}}Note: Some tools may require additional configuration:{{.NC}}"
|
|
102
|
-
echo "1. Cursor: Sign in to your account"
|
|
103
|
-
echo "2. GitHub Copilot: Sign in to your GitHub account in Cursor"
|
|
104
|
-
echo "3. Claude Code: Configure your API key"
|
|
105
|
-
echo "4. OpenAI Codex: Configure your API key"
|
|
106
|
-
echo "5. Task Master: Configure your API key"
|
package/common/aws.yml
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
version: "3"
|
|
2
|
-
|
|
3
|
-
vars:
|
|
4
|
-
AWS_REGION: '{{.AWS_REGION | default "eu-north-1"}}'
|
|
5
|
-
AWS_PROFILE: '{{.AWS_PROFILE | default "web.development"}}'
|
|
6
|
-
ECR_REGISTRY: '{{.ECR_REGISTRY | default "066281862119.dkr.ecr.eu-north-1.amazonaws.com/secnord/shared-images"}}'
|
|
7
|
-
|
|
8
|
-
tasks:
|
|
9
|
-
# Check AWS authentication
|
|
10
|
-
check-auth:
|
|
11
|
-
desc: Check AWS authentication
|
|
12
|
-
silent: true
|
|
13
|
-
cmds:
|
|
14
|
-
- aws sts get-caller-identity --profile {{.AWS_PROFILE}} --no-cli-pager
|
|
15
|
-
|
|
16
|
-
# Configure Docker to use AWS credentials
|
|
17
|
-
configure-docker:
|
|
18
|
-
desc: Configure Docker to use AWS credentials
|
|
19
|
-
silent: true
|
|
20
|
-
cmds:
|
|
21
|
-
- |
|
|
22
|
-
if [ ! -f ~/.docker/config.json ]; then
|
|
23
|
-
mkdir -p ~/.docker
|
|
24
|
-
echo '{"credsStore": "ecr-login"}' > ~/.docker/config.json
|
|
25
|
-
fi
|
|
26
|
-
- aws ecr get-login-password --region {{.AWS_REGION}} --profile {{.AWS_PROFILE}} --no-cli-pager | docker login --username AWS --password-stdin {{.ECR_REGISTRY}}
|
|
27
|
-
|
|
28
|
-
# Create ECR repository if it doesn't exist
|
|
29
|
-
ensure-ecr-repository:
|
|
30
|
-
desc: Ensure ECR repository exists
|
|
31
|
-
silent: true
|
|
32
|
-
vars:
|
|
33
|
-
REPOSITORY_NAME: "{{.REPOSITORY_NAME}}"
|
|
34
|
-
cmds:
|
|
35
|
-
- |
|
|
36
|
-
if ! aws ecr describe-repositories --repository-names "{{.REPOSITORY_NAME}}" --region {{.AWS_REGION}} --profile {{.AWS_PROFILE}} --no-cli-pager >/dev/null 2>&1; then
|
|
37
|
-
echo "Creating ECR repository {{.REPOSITORY_NAME}}..."
|
|
38
|
-
aws ecr create-repository --repository-name "{{.REPOSITORY_NAME}}" --region {{.AWS_REGION}} --profile {{.AWS_PROFILE}} --no-cli-pager
|
|
39
|
-
else
|
|
40
|
-
echo "ECR repository {{.REPOSITORY_NAME}} already exists"
|
|
41
|
-
fi
|
package/common/docker.yml
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
version: "3"
|
|
2
|
-
|
|
3
|
-
vars:
|
|
4
|
-
DOCKER_SOCKET: /var/run/docker.sock
|
|
5
|
-
|
|
6
|
-
tasks:
|
|
7
|
-
# Check if Docker is running and start it if needed
|
|
8
|
-
ensure-docker-running:
|
|
9
|
-
desc: Ensure Docker daemon is running
|
|
10
|
-
silent: true
|
|
11
|
-
cmds:
|
|
12
|
-
- |
|
|
13
|
-
if ! docker info >/dev/null 2>&1; then
|
|
14
|
-
echo "Docker is not running. Starting Docker..."
|
|
15
|
-
open -a Docker
|
|
16
|
-
# Wait for Docker to start
|
|
17
|
-
while ! docker info >/dev/null 2>&1; do
|
|
18
|
-
echo "Waiting for Docker to start..."
|
|
19
|
-
sleep 2
|
|
20
|
-
done
|
|
21
|
-
echo "Docker is now running"
|
|
22
|
-
fi
|
|
23
|
-
|
|
24
|
-
# Build a Docker image
|
|
25
|
-
build-image:
|
|
26
|
-
desc: Build a Docker image
|
|
27
|
-
silent: true
|
|
28
|
-
vars:
|
|
29
|
-
IMAGE_NAME:
|
|
30
|
-
sh: echo "{{.IMAGE_NAME}}"
|
|
31
|
-
IMAGE_TAG:
|
|
32
|
-
sh: echo "{{.IMAGE_TAG}}"
|
|
33
|
-
DOCKERFILE_PATH:
|
|
34
|
-
sh: echo "{{.DOCKERFILE_PATH}}"
|
|
35
|
-
cmds:
|
|
36
|
-
- task: ensure-docker-running
|
|
37
|
-
- echo "Building image {{.IMAGE_NAME}}:{{.IMAGE_TAG}} from {{.DOCKERFILE_PATH}}"
|
|
38
|
-
- docker build -t {{.IMAGE_NAME}}:{{.IMAGE_TAG}} {{.DOCKERFILE_PATH}}
|
|
39
|
-
|
|
40
|
-
# Tag a Docker image
|
|
41
|
-
tag-image:
|
|
42
|
-
desc: Tag a Docker image
|
|
43
|
-
silent: true
|
|
44
|
-
vars:
|
|
45
|
-
SOURCE_IMAGE:
|
|
46
|
-
sh: echo "{{.SOURCE_IMAGE}}"
|
|
47
|
-
SOURCE_TAG:
|
|
48
|
-
sh: echo "{{.SOURCE_TAG}}"
|
|
49
|
-
TARGET_IMAGE:
|
|
50
|
-
sh: echo "{{.TARGET_IMAGE}}"
|
|
51
|
-
TARGET_TAG:
|
|
52
|
-
sh: echo "{{.TARGET_TAG}}"
|
|
53
|
-
cmds:
|
|
54
|
-
- echo "Tagging image {{.SOURCE_IMAGE}}:{{.SOURCE_TAG}} as {{.TARGET_IMAGE}}:{{.TARGET_TAG}}"
|
|
55
|
-
- docker tag {{.SOURCE_IMAGE}}:{{.SOURCE_TAG}} {{.TARGET_IMAGE}}:{{.TARGET_TAG}}
|
|
56
|
-
|
|
57
|
-
# Push a Docker image
|
|
58
|
-
push-image:
|
|
59
|
-
desc: Push a Docker image to registry
|
|
60
|
-
silent: true
|
|
61
|
-
vars:
|
|
62
|
-
IMAGE_NAME:
|
|
63
|
-
sh: echo "{{.IMAGE_NAME}}"
|
|
64
|
-
IMAGE_TAG:
|
|
65
|
-
sh: echo "{{.IMAGE_TAG}}"
|
|
66
|
-
cmds:
|
|
67
|
-
- echo "Pushing image {{.IMAGE_NAME}}:{{.IMAGE_TAG}}"
|
|
68
|
-
- docker push {{.IMAGE_NAME}}:{{.IMAGE_TAG}}
|
package/common/git.yml
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
version: "3"
|
|
2
|
-
|
|
3
|
-
vars:
|
|
4
|
-
# Color codes for output
|
|
5
|
-
CYAN: '\033[0;36m'
|
|
6
|
-
GREEN: '\033[0;32m'
|
|
7
|
-
YELLOW: '\033[0;33m'
|
|
8
|
-
RED: '\033[0;31m'
|
|
9
|
-
NC: '\033[0m' # No Color
|
|
10
|
-
# Valid workflow statuses
|
|
11
|
-
VALID_STATUSES: "queued completed in_progress requested waiting action_required cancelled failure neutral skipped stale startup_failure success timed_out"
|
|
12
|
-
|
|
13
|
-
tasks:
|
|
14
|
-
# Change to repository root
|
|
15
|
-
cd-root:
|
|
16
|
-
desc: Change to the repository root directory
|
|
17
|
-
silent: true
|
|
18
|
-
cmds:
|
|
19
|
-
- |
|
|
20
|
-
ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
21
|
-
if [ -z "$ROOT_DIR" ]; then
|
|
22
|
-
echo "Error: Not in a git repository"
|
|
23
|
-
exit 1
|
|
24
|
-
fi
|
|
25
|
-
cd "$ROOT_DIR"
|
|
26
|
-
|
|
27
|
-
# Get repository root path
|
|
28
|
-
get-root:
|
|
29
|
-
desc: Get the absolute path to the repository root
|
|
30
|
-
silent: true
|
|
31
|
-
cmds:
|
|
32
|
-
- |
|
|
33
|
-
ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
34
|
-
if [ -z "$ROOT_DIR" ]; then
|
|
35
|
-
echo "Error: Not in a git repository"
|
|
36
|
-
exit 1
|
|
37
|
-
fi
|
|
38
|
-
echo "$ROOT_DIR"
|
|
39
|
-
|
|
40
|
-
# Delete local branches that don't have a remote counterpart
|
|
41
|
-
prune:
|
|
42
|
-
desc: Delete local branches that don't have a remote counterpart
|
|
43
|
-
silent: true
|
|
44
|
-
vars:
|
|
45
|
-
BASE_DIR: '{{.BASE_DIR | default "."}}'
|
|
46
|
-
cmds:
|
|
47
|
-
- |
|
|
48
|
-
# Find all .git directories and iterate over them
|
|
49
|
-
find "{{.BASE_DIR}}" -type d -name ".git" | while read -r git_dir; do
|
|
50
|
-
# Get the parent directory of the .git folder
|
|
51
|
-
repo_dir=$(dirname "$git_dir")
|
|
52
|
-
|
|
53
|
-
echo -e "{{.CYAN}}Processing:{{.NC}} $repo_dir"
|
|
54
|
-
|
|
55
|
-
# Navigate to the repository directory
|
|
56
|
-
cd "$repo_dir" || {
|
|
57
|
-
echo "Failed to navigate to $repo_dir. Skipping."
|
|
58
|
-
continue
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
# Get the default branch name
|
|
62
|
-
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
|
|
63
|
-
|
|
64
|
-
# Switch to the default branch
|
|
65
|
-
git checkout "$default_branch" >/dev/null 2>&1
|
|
66
|
-
git fetch -p >/dev/null 2>&1
|
|
67
|
-
|
|
68
|
-
# Fetch local branches that are gone on remote
|
|
69
|
-
git branch -vv | grep ': gone]' | while read -r line; do
|
|
70
|
-
# Remove the leading star if present
|
|
71
|
-
branch=$(echo "$line" | sed 's/^\* //;s/^[[:space:]]*//;s/[[:space:]]*$//' | cut -d ' ' -f 1)
|
|
72
|
-
echo -e "{{.RED}}Branch to delete: $branch{{.NC}}"
|
|
73
|
-
git branch -D "$branch"
|
|
74
|
-
done
|
|
75
|
-
|
|
76
|
-
echo -e "{{.GREEN}}Done{{.NC}}"
|
|
77
|
-
|
|
78
|
-
cd "$OLDPWD" || {
|
|
79
|
-
echo "Failed to navigate back. Exiting."
|
|
80
|
-
exit 1
|
|
81
|
-
}
|
|
82
|
-
done
|
|
83
|
-
|
|
84
|
-
echo "All repositories processed."
|
|
85
|
-
aliases: [clean-branches, clb]
|
|
86
|
-
|
|
87
|
-
# Fetch and prune remote branches
|
|
88
|
-
fetch-prune:
|
|
89
|
-
desc: Fetch and prune remote branches
|
|
90
|
-
silent: true
|
|
91
|
-
cmds:
|
|
92
|
-
- git fetch -p
|
|
93
|
-
aliases: [fp]
|
|
94
|
-
|
|
95
|
-
# Switch to default branch
|
|
96
|
-
switch-default:
|
|
97
|
-
desc: Switch to the default branch
|
|
98
|
-
silent: true
|
|
99
|
-
cmds:
|
|
100
|
-
- |
|
|
101
|
-
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
|
|
102
|
-
git checkout "$default_branch"
|
|
103
|
-
aliases: [sd]
|
|
104
|
-
|
|
105
|
-
# List all branches
|
|
106
|
-
list-branches:
|
|
107
|
-
desc: List all branches with their status
|
|
108
|
-
silent: true
|
|
109
|
-
cmds:
|
|
110
|
-
- git --no-pager branch -vv
|
|
111
|
-
aliases: [lb]
|
|
112
|
-
|
|
113
|
-
# Delete GitHub workflow runs
|
|
114
|
-
delete-runs:
|
|
115
|
-
desc: Delete GitHub workflow runs for a branch with specific status
|
|
116
|
-
silent: true
|
|
117
|
-
vars:
|
|
118
|
-
BRANCH: '{{.BRANCH | default ""}}'
|
|
119
|
-
STATUS: '{{.STATUS | default "failure"}}'
|
|
120
|
-
cmds:
|
|
121
|
-
- |
|
|
122
|
-
# Check if gh CLI is installed
|
|
123
|
-
if ! command -v gh &> /dev/null; then
|
|
124
|
-
echo -e "{{.RED}}GitHub CLI (gh) is not installed{{.NC}}"
|
|
125
|
-
echo "Please install it first:"
|
|
126
|
-
echo " brew install gh"
|
|
127
|
-
echo "Then authenticate:"
|
|
128
|
-
echo " gh auth login"
|
|
129
|
-
exit 1
|
|
130
|
-
fi
|
|
131
|
-
|
|
132
|
-
# Check if authenticated with GitHub
|
|
133
|
-
if ! gh auth status &> /dev/null; then
|
|
134
|
-
echo -e "{{.RED}}Not authenticated with GitHub{{.NC}}"
|
|
135
|
-
echo "Please run:"
|
|
136
|
-
echo " gh auth login"
|
|
137
|
-
exit 1
|
|
138
|
-
fi
|
|
139
|
-
|
|
140
|
-
# Validate status
|
|
141
|
-
if [[ ! "{{.VALID_STATUSES}}" =~ {{.STATUS}} ]]; then
|
|
142
|
-
echo -e "{{.RED}}Invalid status: {{.STATUS}}{{.NC}}"
|
|
143
|
-
echo "Use one of:"
|
|
144
|
-
echo " {{.VALID_STATUSES}}"
|
|
145
|
-
exit 1
|
|
146
|
-
fi
|
|
147
|
-
|
|
148
|
-
# Get repository info from GitHub
|
|
149
|
-
repo_owner=$(gh repo view --json owner --jq '.owner.login')
|
|
150
|
-
repo_name=$(gh repo view --json name --jq '.name')
|
|
151
|
-
|
|
152
|
-
# If no branch specified, use current branch
|
|
153
|
-
branch="{{.BRANCH}}"
|
|
154
|
-
if [ -z "$branch" ]; then
|
|
155
|
-
branch=$(git rev-parse --abbrev-ref HEAD)
|
|
156
|
-
fi
|
|
157
|
-
|
|
158
|
-
echo -e "{{.CYAN}}Using repository: $repo_owner/$repo_name{{.NC}}"
|
|
159
|
-
|
|
160
|
-
# Handle all branches case
|
|
161
|
-
if [ "$branch" == "all" ] || [ "$branch" == "-all" ] || [ "$branch" == "--all" ] || [ "$branch" == "-a" ]; then
|
|
162
|
-
echo -e "{{.CYAN}}Processing runs in all branches...{{.NC}}"
|
|
163
|
-
workflow_runs=$(gh run list -R "$repo_owner/$repo_name" -a -s {{.STATUS}} --limit 100 --json databaseId)
|
|
164
|
-
else
|
|
165
|
-
echo -e "{{.CYAN}}Processing runs in branch $branch...{{.NC}}"
|
|
166
|
-
workflow_runs=$(gh run list -R "$repo_owner/$repo_name" -b "$branch" -a -s {{.STATUS}} --limit 100 --json databaseId)
|
|
167
|
-
fi
|
|
168
|
-
|
|
169
|
-
# Parse and delete runs
|
|
170
|
-
run_ids=$(echo "$workflow_runs" | jq -r '.[].databaseId')
|
|
171
|
-
deleted=0
|
|
172
|
-
for run_id in $run_ids; do
|
|
173
|
-
gh run delete $run_id
|
|
174
|
-
deleted=$((deleted+1))
|
|
175
|
-
done
|
|
176
|
-
|
|
177
|
-
# Report results
|
|
178
|
-
if [ $deleted -eq 0 ]; then
|
|
179
|
-
echo -e "{{.YELLOW}}No runs found with status {{.STATUS}} in branch $branch{{.NC}}"
|
|
180
|
-
else
|
|
181
|
-
echo -e "{{.GREEN}}Deleted $deleted runs with status {{.STATUS}} in branch $branch{{.NC}}"
|
|
182
|
-
fi
|
|
183
|
-
aliases: [dr]
|
|
184
|
-
|
|
185
|
-
# Git hooks management
|
|
186
|
-
hooks:setup:
|
|
187
|
-
desc: Set up git hooks with Jira integration
|
|
188
|
-
silent: true
|
|
189
|
-
vars:
|
|
190
|
-
JIRA_KEY: '{{.JIRA_KEY | default ""}}'
|
|
191
|
-
cmds:
|
|
192
|
-
- |
|
|
193
|
-
# Check if git is installed
|
|
194
|
-
if ! command -v git &> /dev/null; then
|
|
195
|
-
echo -e "{{.RED}}Error: Git CLI tools are missing. Please install them before running this script.{{.NC}}"
|
|
196
|
-
exit 1
|
|
197
|
-
fi
|
|
198
|
-
|
|
199
|
-
# Check if .git directory exists
|
|
200
|
-
if [ ! -d ".git" ]; then
|
|
201
|
-
echo -e "{{.RED}}Error: This script must be run from the workspace root folder.{{.NC}}"
|
|
202
|
-
exit 1
|
|
203
|
-
fi
|
|
204
|
-
|
|
205
|
-
# Get Jira key if not provided
|
|
206
|
-
jira_key="{{.JIRA_KEY}}"
|
|
207
|
-
if [ -z "$jira_key" ]; then
|
|
208
|
-
echo -e "{{.CYAN}}Please enter the Jira project key:{{.NC}}"
|
|
209
|
-
read jira_key
|
|
210
|
-
fi
|
|
211
|
-
|
|
212
|
-
# Validate Jira key
|
|
213
|
-
if [[ ! $jira_key =~ ^[a-zA-Z0-9]+$ ]]; then
|
|
214
|
-
echo -e "{{.RED}}Error: Jira project key must be alphanumeric.{{.NC}}"
|
|
215
|
-
exit 1
|
|
216
|
-
fi
|
|
217
|
-
|
|
218
|
-
echo -e "{{.CYAN}}Jira key: $jira_key{{.NC}}"
|
|
219
|
-
echo -e "{{.CYAN}}Configuring Jira Smart Commit git hooks...{{.NC}}"
|
|
220
|
-
|
|
221
|
-
# Create prepare-commit-msg hook from template
|
|
222
|
-
sed "s/JIRA_KEY_PLACEHOLDER/$jira_key/g" tasks/common/templates/prepare-commit-msg.template > .git/hooks/prepare-commit-msg
|
|
223
|
-
|
|
224
|
-
# Configure git to use the hooks
|
|
225
|
-
git config --local core.hooksPath .git/hooks/
|
|
226
|
-
|
|
227
|
-
# Make sure the script is executable
|
|
228
|
-
chmod +x .git/hooks/prepare-commit-msg
|
|
229
|
-
|
|
230
|
-
echo -e "{{.GREEN}}Git hooks configured.{{.NC}}"
|
|
231
|
-
aliases: [hs]
|
|
232
|
-
|
|
233
|
-
hooks:remove:
|
|
234
|
-
desc: Remove git hooks configuration
|
|
235
|
-
silent: true
|
|
236
|
-
cmds:
|
|
237
|
-
- |
|
|
238
|
-
# Check if git is installed
|
|
239
|
-
if ! command -v git &> /dev/null; then
|
|
240
|
-
echo -e "{{.RED}}Error: Git CLI tools are missing. Please install them before running this script.{{.NC}}"
|
|
241
|
-
exit 1
|
|
242
|
-
fi
|
|
243
|
-
|
|
244
|
-
# Check if .git directory exists
|
|
245
|
-
if [ ! -d ".git" ]; then
|
|
246
|
-
echo -e "{{.RED}}Error: This script must be run from the workspace root folder.{{.NC}}"
|
|
247
|
-
exit 1
|
|
248
|
-
fi
|
|
249
|
-
|
|
250
|
-
# Remove prepare-commit-msg hook
|
|
251
|
-
rm -f .git/hooks/prepare-commit-msg
|
|
252
|
-
|
|
253
|
-
# Reset git hooks path
|
|
254
|
-
git config --local --unset core.hooksPath
|
|
255
|
-
|
|
256
|
-
echo -e "{{.GREEN}}Git hooks removed.{{.NC}}"
|
|
257
|
-
aliases: [hr]
|
|
258
|
-
|
|
259
|
-
hooks:status:
|
|
260
|
-
desc: Show git hooks configuration status
|
|
261
|
-
silent: true
|
|
262
|
-
cmds:
|
|
263
|
-
- |
|
|
264
|
-
# Check if git is installed
|
|
265
|
-
if ! command -v git &> /dev/null; then
|
|
266
|
-
echo -e "{{.RED}}Error: Git CLI tools are missing. Please install them before running this script.{{.NC}}"
|
|
267
|
-
exit 1
|
|
268
|
-
fi
|
|
269
|
-
|
|
270
|
-
# Check if .git directory exists
|
|
271
|
-
if [ ! -d ".git" ]; then
|
|
272
|
-
echo -e "{{.RED}}Error: This script must be run from the workspace root folder.{{.NC}}"
|
|
273
|
-
exit 1
|
|
274
|
-
fi
|
|
275
|
-
|
|
276
|
-
echo -e "{{.CYAN}}Git hooks status:{{.NC}}"
|
|
277
|
-
|
|
278
|
-
# Check if prepare-commit-msg hook exists
|
|
279
|
-
if [ -f ".git/hooks/prepare-commit-msg" ]; then
|
|
280
|
-
echo -e "{{.GREEN}}✓ prepare-commit-msg hook is installed{{.NC}}"
|
|
281
|
-
# Show Jira project key
|
|
282
|
-
jira_key=$(grep "JIRA_PROJECT_KEY=" .git/hooks/prepare-commit-msg | cut -d"'" -f2)
|
|
283
|
-
echo -e "{{.CYAN}} Jira project key: $jira_key{{.NC}}"
|
|
284
|
-
else
|
|
285
|
-
echo -e "{{.YELLOW}}✗ prepare-commit-msg hook is not installed{{.NC}}"
|
|
286
|
-
fi
|
|
287
|
-
|
|
288
|
-
# Check git hooks path configuration
|
|
289
|
-
hooks_path=$(git config --local core.hooksPath)
|
|
290
|
-
if [ -n "$hooks_path" ]; then
|
|
291
|
-
echo -e "{{.GREEN}}✓ Git hooks path is configured: $hooks_path{{.NC}}"
|
|
292
|
-
else
|
|
293
|
-
echo -e "{{.YELLOW}}✗ Git hooks path is not configured{{.NC}}"
|
|
294
|
-
fi
|
|
295
|
-
aliases: [hst]
|
package/common/modules.yml
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
version: "3"
|
|
2
|
-
|
|
3
|
-
vars:
|
|
4
|
-
# Color codes for output
|
|
5
|
-
CYAN: '\033[0;36m'
|
|
6
|
-
GREEN: '\033[0;32m'
|
|
7
|
-
YELLOW: '\033[0;33m'
|
|
8
|
-
RED: '\033[0;31m'
|
|
9
|
-
NC: '\033[0m' # No Color
|
|
10
|
-
|
|
11
|
-
tasks:
|
|
12
|
-
# Update shared tools to latest version
|
|
13
|
-
update-tools:
|
|
14
|
-
desc: Update @lekman/devops-toolkit-tasks to the latest version
|
|
15
|
-
silent: true
|
|
16
|
-
cmds:
|
|
17
|
-
- |
|
|
18
|
-
# Get repository root
|
|
19
|
-
ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
20
|
-
if [ -z "$ROOT_DIR" ]; then
|
|
21
|
-
echo -e "{{.YELLOW}}Warning: Not in a git repository{{.NC}}"
|
|
22
|
-
exit 0
|
|
23
|
-
fi
|
|
24
|
-
cd "$ROOT_DIR"
|
|
25
|
-
|
|
26
|
-
# Check if package.json exists
|
|
27
|
-
if [ ! -f "package.json" ]; then
|
|
28
|
-
echo -e "{{.YELLOW}}Warning: No package.json found in repository root{{.NC}}"
|
|
29
|
-
exit 0
|
|
30
|
-
fi
|
|
31
|
-
|
|
32
|
-
# Check if @lekman/devops-toolkit-tasks is in package.json
|
|
33
|
-
if ! grep -q "@lekman/devops-toolkit-tasks" package.json; then
|
|
34
|
-
echo -e "{{.YELLOW}}Warning: @lekman/devops-toolkit-tasks not found in package.json{{.NC}}"
|
|
35
|
-
exit 0
|
|
36
|
-
fi
|
|
37
|
-
|
|
38
|
-
echo -e "{{.CYAN}}Updating @lekman/devops-toolkit-tasks to latest version...{{.NC}}"
|
|
39
|
-
npm install --save-dev @lekman/devops-toolkit-tasks@latest
|
|
40
|
-
echo -e "{{.GREEN}}Update complete{{.NC}}"
|
|
41
|
-
aliases: [ut]
|