-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (86 loc) · 4.31 KB
/
Copy pathproject-setup.yml
File metadata and controls
100 lines (86 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Project Setup
on:
push:
branches: [master, main]
workflow_dispatch:
jobs:
setup:
name: Setup Project
if: ${{ !github.event.repository.is_template }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Check if already initialized
id: check
run: |
if grep -q "re.neotamia.plugintemplate" buildSrc/src/main/kotlin/plugintemplate-build.gradle.kts; then
echo "initialized=false" >> $GITHUB_OUTPUT
else
echo "initialized=true" >> $GITHUB_OUTPUT
fi
- name: Run setup script
if: steps.check.outputs.initialized == 'false'
run: |
REPO_NAME="${{ github.event.repository.name }}"
REPO_OWNER="${{ github.repository_owner }}"
# Sanitize names
LOW_OWNER=$(echo "$REPO_OWNER" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g')
LOW_NAME=$(echo "$REPO_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g')
# camelCase: my-repo -> myRepo
CAMEL_NAME=$(echo "$REPO_NAME" | sed -r 's/(^|[_-])([a-z])/\U\2/g' | sed 's/[^a-zA-Z0-9]//g' | sed 's/^./\l&/')
# PascalCase: my-repo -> MyRepo
PASCAL_NAME=$(echo "$REPO_NAME" | sed -r 's/(^|[_-])([a-z])/\U\2/g' | sed 's/[^a-zA-Z0-9]//g')
echo "Setting up project for $REPO_OWNER/$REPO_NAME"
echo "Package: re.$LOW_OWNER.$LOW_NAME"
# 1. Replace strings in all files
find . -type f -not -path '*/.*' -not -name 'project-setup.yml' > files.txt
while read -r f; do
if grep -qI . "$f"; then
sed -i "s/re\.neotamia\.plugintemplate/re.$LOW_OWNER.$LOW_NAME/g" "$f"
sed -i "s/plugin-template/$REPO_NAME/g" "$f"
sed -i "s/PluginTemplate/$PASCAL_NAME/g" "$f"
sed -i "s/pluginTemplate/$CAMEL_NAME/g" "$f"
sed -i "s/Plugin Template/$REPO_NAME/g" "$f"
sed -i "s/plugintemplate-build/$LOW_NAME-build/g" "$f"
fi
done < files.txt
rm files.txt
# 2. Replace Owner only in specific files to avoid breaking external actions
files_to_replace_owner="README.md CONTRIBUTING.md buildSrc/src/main/kotlin/plugintemplate-build.gradle.kts settings.gradle.kts"
for f in $files_to_replace_owner; do
if [ -f "$f" ]; then
sed -i "s/NeoTamia/$REPO_OWNER/g" "$f"
fi
done
# 3. Rename PluginTemplatePlugin.kt
mv modules/core/src/main/kotlin/re/neotamia/plugintemplate/core/PluginTemplatePlugin.kt "modules/core/src/main/kotlin/re/neotamia/plugintemplate/core/${PASCAL_NAME}Plugin.kt"
# 4. Rename directories to match new package
find . -type d -path "*/re/neotamia/plugintemplate" | while read -r dir; do
base_path=$(echo "$dir" | sed 's|/re/neotamia/plugintemplate$||')
new_parent="$base_path/re/$LOW_OWNER"
mkdir -p "$new_parent"
mv "$dir" "$new_parent/$LOW_NAME"
# Clean up old empty directories
rmdir "$(dirname "$dir")" 2>/dev/null || true
done
# 5. Rename plugintemplate-build.gradle.kts
mv buildSrc/src/main/kotlin/plugintemplate-build.gradle.kts "buildSrc/src/main/kotlin/$LOW_NAME-build.gradle.kts"
- name: Commit changes
if: steps.check.outputs.initialized == 'false'
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7
with:
commit_message: "chore: project setup for ${{ github.event.repository.name }}"
push_options: '--force'
- name: Remove setup workflow
if: steps.check.outputs.initialized == 'false' || github.event_name == 'workflow_dispatch'
run: rm .github/workflows/project-setup.yml
- name: Commit removal
if: steps.check.outputs.initialized == 'false' || github.event_name == 'workflow_dispatch'
uses: stefanzweifel/git-auto-commit-action@04702edda442b2e678b25b537cec683a1493fcb9 # v7
with:
commit_message: "chore: remove setup workflow"