Skip to content

Commit 3e6b81d

Browse files
committed
ci: add GitHub Actions workflows and test scripts
1 parent eec265b commit 3e6b81d

15 files changed

+640
-804
lines changed

.github/scripts/bump-version.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
set -Eeuo pipefail
3+
IFS=$'\n\t'
4+
5+
# Script to bump version in n8n-manager.sh and create a version commit
6+
7+
SCRIPT_FILE="n8n-manager.sh"
8+
9+
# Function to get current version
10+
get_current_version() {
11+
grep -E '^SCRIPT_VERSION=' "$SCRIPT_FILE" | cut -d'"' -f2
12+
}
13+
14+
# Function to bump version (major, minor, patch)
15+
# Expects one argument: major, minor, or patch
16+
bump_version_component() {
17+
local current_version=$1
18+
local component=$2
19+
local major minor patch
20+
21+
major=$(echo "$current_version" | cut -d. -f1)
22+
minor=$(echo "$current_version" | cut -d. -f2)
23+
patch=$(echo "$current_version" | cut -d. -f3)
24+
25+
case "$component" in
26+
major) major=$((major + 1)); minor=0; patch=0 ;;
27+
minor) minor=$((minor + 1)); patch=0 ;;
28+
patch) patch=$((patch + 1)) ;;
29+
*) echo "Error: Invalid version component '$component' specified."; exit 1 ;;
30+
esac
31+
echo "$major.$minor.$patch"
32+
}
33+
34+
# Determine version bump based on commit messages (simplified placeholder)
35+
# In a real scenario, this would involve analyzing commit messages (e.g., conventional commits)
36+
# For now, we'll default to 'patch' or take it from an environment variable
37+
BUMP_TYPE="${VERSION_BUMP_TYPE:-patch}" # Default to patch, can be overridden by env var
38+
39+
CURRENT_VERSION=$(get_current_version)
40+
NEW_VERSION=$(bump_version_component "$CURRENT_VERSION" "$BUMP_TYPE")
41+
42+
echo "Current version: $CURRENT_VERSION"
43+
echo "Bumping type: $BUMP_TYPE"
44+
echo "New version: $NEW_VERSION"
45+
46+
# Update version in script file
47+
sed -i "s/^SCRIPT_VERSION=.*/SCRIPT_VERSION=\"$NEW_VERSION\"/" "$SCRIPT_FILE"
48+
49+
# Output new version for GitHub Actions
50+
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
51+
52+
# Create a commit for the version bump
53+
# This part will be handled by the GitHub workflow using the new version
54+
55+
exit 0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -Eeuo pipefail
3+
IFS=$'\n\t'
4+
5+
# Script to generate changelog using conventional-changelog-cli
6+
7+
# Ensure conventional-changelog-cli is installed
8+
if ! command -v conventional-changelog &> /dev/null
9+
then
10+
echo "conventional-changelog-cli not found. Installing..."
11+
npm install -g conventional-changelog-cli conventional-changelog-conventionalcommits
12+
fi
13+
14+
# Generate changelog
15+
# The preset 'conventionalcommits' is a good default. Others can be specified.
16+
# It will overwrite CHANGELOG.md by default.
17+
conventional-changelog -p conventionalcommits -i CHANGELOG.md -s -r 0
18+
19+
echo "Changelog generated/updated successfully: CHANGELOG.md"
20+
21+
# The workflow will handle committing this file.
22+
23+
exit 0

.github/scripts/test-docs.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_FILE='n8n-manager.sh'
5+
README_FILE='readme.md'
6+
7+
echo "Validating README.md structure..."
8+
required_sections=("Features" "Prerequisites" "Installation" "Configuration" "Usage")
9+
10+
for section in "${required_sections[@]}"; do
11+
if grep -q "## .*$section" $README_FILE; then
12+
echo "✅ Found: $section"
13+
else
14+
echo "❌ Missing: $section"
15+
exit 1
16+
fi
17+
done
18+
19+
echo "Checking help text consistency..."
20+
./$SCRIPT_FILE --help > script-help.txt
21+
22+
if grep -q "Usage:" $README_FILE; then
23+
echo "✅ README contains usage information"
24+
else
25+
echo "❌ README missing usage information"
26+
exit 1
27+
fi
28+
29+
echo "Checking version consistency..."
30+
SCRIPT_VERSION=$(grep -E '^SCRIPT_VERSION=' $SCRIPT_FILE | cut -d'"' -f2)
31+
32+
if grep -q "$SCRIPT_VERSION" $README_FILE; then
33+
echo "✅ Version consistent: $SCRIPT_VERSION"
34+
else
35+
echo "❌ Version mismatch in README"
36+
echo "Script version: $SCRIPT_VERSION"
37+
echo "README version references:"
38+
grep -n "version\|Version" $README_FILE || echo "None found"
39+
exit 1
40+
fi

.github/scripts/test-functional.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_FILE='n8n-manager.sh'
5+
6+
echo "Creating test n8n container..."
7+
docker run -d \
8+
--name test-n8n \
9+
-p 5678:5678 \
10+
-e N8N_BASIC_AUTH_ACTIVE=true \
11+
-e N8N_BASIC_AUTH_USER=admin \
12+
-e N8N_BASIC_AUTH_PASSWORD=password \
13+
n8nio/n8n:latest
14+
15+
sleep 30
16+
docker ps
17+
18+
chmod +x $SCRIPT_FILE
19+
20+
echo "Testing container detection..."
21+
./$SCRIPT_FILE --action backup --container test-n8n --dry-run --verbose || true
22+
23+
echo "Testing help functionality..."
24+
./$SCRIPT_FILE --help
25+
26+
echo "Testing configuration file parsing..."
27+
mkdir -p ~/.config/n8n-manager
28+
echo 'CONF_VERBOSE=true' > ~/.config/n8n-manager/config
29+
./$SCRIPT_FILE --action backup --container test-n8n --dry-run || true
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e
3+
4+
INSTALL_FILE='install.sh'
5+
6+
echo "Testing installation process..."
7+
8+
chmod +x $INSTALL_FILE
9+
10+
TEST_DIR=$(mktemp -d)
11+
cd $TEST_DIR
12+
13+
cp $GITHUB_WORKSPACE/$INSTALL_FILE ./test-install.sh
14+
15+
sed -i 's|/usr/local/bin|./bin|g' ./test-install.sh
16+
sed -i 's|sudo ||g' ./test-install.sh
17+
18+
mkdir -p ./bin
19+
20+
bash ./test-install.sh || echo "Install test completed (errors expected in CI)"
21+
22+
echo "# Integration Test Results" > integration-report.md
23+
echo "" >> integration-report.md
24+
echo "- Test environment: Ubuntu Latest" >> integration-report.md
25+
echo "- Docker available: $(docker --version)" >> integration-report.md
26+
echo "- Git available: $(git --version)" >> integration-report.md
27+
echo "- Curl available: $(curl --version | head -1)" >> integration-report.md

.github/scripts/test-security.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_FILE='n8n-manager.sh'
5+
INSTALL_FILE='install.sh'
6+
7+
echo "# Security Scan Results" > security-report.md
8+
echo "" >> security-report.md
9+
10+
echo "## Potential Security Issues" >> security-report.md
11+
12+
echo "### Command Injection Risks" >> security-report.md
13+
grep -n 'eval\|exec\|[`]' $SCRIPT_FILE $INSTALL_FILE >> security-report.md || echo "None found" >> security-report.md
14+
15+
echo "" >> security-report.md
16+
echo "### Unsafe Variable Usage" >> security-report.md
17+
grep -n '\$[a-zA-Z_][a-zA-Z0-9_]*[^"]' $SCRIPT_FILE $INSTALL_FILE | head -20 >> security-report.md || echo "None found" >> security-report.md
18+
19+
echo "" >> security-report.md
20+
echo "### Hardcoded Secrets Check" >> security-report.md
21+
grep -i -n "password\|secret\|key\|token" $SCRIPT_FILE $INSTALL_FILE | grep -v "GITHUB_TOKEN\|CONF_" >> security-report.md || echo "None found" >> security-report.md

.github/scripts/test-shellcheck.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_FILE='n8n-manager.sh'
5+
INSTALL_FILE='install.sh'
6+
7+
echo "Running ShellCheck on $SCRIPT_FILE..."
8+
shellcheck -f gcc -e SC1091 -e SC2034 -e SC2154 $SCRIPT_FILE
9+
10+
echo "Running ShellCheck on $INSTALL_FILE..."
11+
shellcheck -f gcc -e SC1091 $INSTALL_FILE
12+
13+
echo "# ShellCheck Results" > shellcheck-report.md
14+
echo "" >> shellcheck-report.md
15+
echo "## Main Script ($SCRIPT_FILE)" >> shellcheck-report.md
16+
shellcheck -f diff $SCRIPT_FILE >> shellcheck-report.md 2>&1 || true
17+
echo "" >> shellcheck-report.md
18+
echo "## Install Script ($INSTALL_FILE)" >> shellcheck-report.md
19+
shellcheck -f diff $INSTALL_FILE >> shellcheck-report.md 2>&1 || true

.github/scripts/test-syntax.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_FILE='n8n-manager.sh'
5+
INSTALL_FILE='install.sh'
6+
7+
echo "Validating syntax of $SCRIPT_FILE..."
8+
bash -n $SCRIPT_FILE
9+
10+
echo "Validating syntax of $INSTALL_FILE..."
11+
bash -n $INSTALL_FILE
12+
13+
echo "Testing script execution with --help flag..."
14+
chmod +x $SCRIPT_FILE
15+
./$SCRIPT_FILE --help || true
16+
17+
echo "Testing script execution with --dry-run flag..."
18+
./$SCRIPT_FILE --action backup --dry-run --verbose || true
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
set -Eeuo pipefail
3+
IFS=$'\n\t'
4+
5+
README_FILE="README.md"
6+
SCRIPT_FILE="n8n-manager.sh"
7+
8+
# Function to update a badge in README.md
9+
# Arguments: <badge_name_placeholder> <badge_url>
10+
update_badge() {
11+
local placeholder="$1"
12+
local url="$2"
13+
# Ensure the placeholder exists before attempting to replace
14+
if grep -q "<!-- $placeholder -->" "$README_FILE"; then
15+
# Using awk for more robust replacement across lines if needed
16+
awk -v placeholder="$placeholder" -v url="$url" '
17+
BEGIN {p_start = "<!-- " placeholder " -->"; p_end = "<!-- " placeholder "_END -->"}
18+
$0 ~ p_start {print; print url; in_block=1; next}
19+
$0 ~ p_end {print; in_block=0; next}
20+
!in_block {print}
21+
' "$README_FILE" > tmp_readme.md && mv tmp_readme.md "$README_FILE"
22+
echo "Updated badge: $placeholder"
23+
else
24+
echo "Warning: Placeholder '$placeholder' not found in $README_FILE."
25+
fi
26+
}
27+
28+
# Get script version
29+
SCRIPT_VERSION=$(grep -E '^SCRIPT_VERSION=' "$SCRIPT_FILE" | cut -d'"' -f2)
30+
if [ -z "$SCRIPT_VERSION" ]; then
31+
echo "Error: Could not extract SCRIPT_VERSION from $SCRIPT_FILE" >&2
32+
exit 1
33+
fi
34+
35+
# Get other dynamic info (placeholders for now, can be expanded)
36+
REPO_NAME="$(basename -s .git "$(git config --get remote.origin.url)")"
37+
OWNER_NAME="$(git config --get remote.origin.url | sed -n 's|.*github.com/\([^/]*\)/.*|\1|p')"
38+
LAST_COMMIT_DATE_FORMATTED=$(date -u +"%Y-%m-%d") # Simplified, actual last commit date is better
39+
LICENSE_TYPE="MIT" # Assuming MIT, can be made dynamic
40+
41+
# Generate badge URLs (examples)
42+
VERSION_BADGE_URL="[![Version](https://img.shields.io/badge/version-$SCRIPT_VERSION-blue.svg)](https://github.com/$OWNER_NAME/$REPO_NAME/releases/tag/v$SCRIPT_VERSION)"
43+
LICENSE_BADGE_URL="[![License](https://img.shields.io/badge/license-$LICENSE_TYPE-green.svg)](LICENSE)"
44+
LAST_COMMIT_BADGE_URL="[![Last Commit](https://img.shields.io/badge/last%20commit-$LAST_COMMIT_DATE_FORMATTED-orange.svg)](https://github.com/$OWNER_NAME/$REPO_NAME/commits/main)"
45+
# Add more badges as needed (e.g., open issues, stars, build status from ci.yml)
46+
# BUILD_STATUS_BADGE_URL="[![Build Status](https://github.com/$OWNER_NAME/$REPO_NAME/actions/workflows/ci.yml/badge.svg)](https://github.com/$OWNER_NAME/$REPO_NAME/actions/workflows/ci.yml)"
47+
48+
# Update badges in README
49+
update_badge "BADGE_VERSION" "$VERSION_BADGE_URL"
50+
update_badge "BADGE_LICENSE" "$LICENSE_BADGE_URL"
51+
update_badge "BADGE_LAST_COMMIT" "$LAST_COMMIT_BADGE_URL"
52+
# update_badge "BADGE_BUILD_STATUS" "$BUILD_STATUS_BADGE_URL"
53+
54+
echo "README badges update process completed."
55+
56+
# The workflow will handle committing this file.
57+
58+
exit 0

0 commit comments

Comments
 (0)