Skip to content

Commit cc32374

Browse files
committed
ci: extract cleanup into a separate script
1 parent 5bef13b commit cc32374

4 files changed

Lines changed: 44 additions & 20 deletions

File tree

.github/workflows/cleanup.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
branches: [main]
99

1010
jobs:
11-
1211
# Run cleaning process only if workflow is triggered by the non-"android-library-template" repository.
1312
template-cleanup:
1413
name: Template Cleanup
@@ -17,31 +16,14 @@ jobs:
1716
permissions:
1817
contents: write
1918
steps:
20-
2119
# Check out current repository
2220
- name: Fetch Sources
2321
uses: actions/checkout@v4
2422

2523
# Cleanup project
2624
- name: Cleanup
2725
run: |
28-
# Prepare variables
29-
NAME="${GITHUB_REPOSITORY##*/}"
30-
SAFE_NAME=$(echo $NAME | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')
31-
32-
# Replace
33-
sed -i "s/stub/$SAFE_NAME/g" $(find . -type f -not -path "**/build/**" -not -path "**/.**")
34-
sed -i "s/Stub/$NAME/g" $(find . -type f -not -path "**/build/**" -not -path "**/.**")
35-
36-
# Move stub
37-
mv stub/src/main/kotlin/Stub.kt stub/src/main/kotlin/$NAME.kt
38-
mv stub/ $SAFE_NAME
39-
40-
# Cleanup
41-
rm .github/workflows/cleanup.yml
42-
43-
# Remove leftover empty directories
44-
find . -type d -empty -delete
26+
./cleanup.sh "${GITHUB_REPOSITORY##*/}"
4527
4628
# Commit modified files
4729
- name: Commit files

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
java-version: 17
2424
- name: Setup Gradle
2525
uses: gradle/actions/setup-gradle@v3
26+
- name: Cleanup project
27+
run: ./cleanup.sh TestTemplate
2628
- name: Run Check
2729
run: ./gradlew check detektAll detektReleaseAll
2830

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ For major changes, please open an issue first to discuss what you would like to
3939
## Checklist after repository creation (remove after checked)
4040

4141
- Update developers in [publishing plugin](buildSrc/src/main/kotlin/convention.publishing.gradle.kts)
42-
- remove `./cleanup.sh TestTemplate` from [main.yml](.github/workflows/main.yml)
42+
- remove `Cleanup` step from [main.yml](.github/workflows/main.yml)
4343

4444
[license]: ../LICENSE

cleanup.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
RESET="\033[0m"
6+
F_BOLD="\033[1m"
7+
F_BOLD_RESET="\033[22m"
8+
C_RED="\033[31m"
9+
C_GREEN="\033[32m"
10+
11+
function log_success() { printf -- "\n${F_BOLD}${C_GREEN}%s${RESET}\n" "$*"; }
12+
function log_error() { printf -- "\n${F_BOLD}${C_RED}ERROR:${F_BOLD_RESET} %s${RESET}\n" "$*"; }
13+
14+
if [[ $# -ne 1 ]]; then
15+
log_error "Please specify the actual repository name. Usage: ./cleanup.sh MyRepositoryName"
16+
exit 1
17+
fi
18+
19+
NAME="$1"
20+
SAFE_NAME="$(echo $NAME | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]')"
21+
22+
STUB="%Stub%"
23+
SAFE_STUB="%stub%"
24+
25+
# Replace
26+
sed -i "s/$SAFE_STUB/$SAFE_NAME/g" $(find . -type f -not -path "**/build/**" -not -path "**/.**")
27+
sed -i "s/$STUB/$NAME/g" $(find . -type f -not -path "**/build/**" -not -path "**/.**")
28+
29+
# Move stub
30+
mv stub/src/main/kotlin/Stub.kt stub/src/main/kotlin/$NAME.kt
31+
mv stub/ $SAFE_NAME
32+
33+
# Cleanup
34+
if [[ $GITHUB_ACTIONS ]]; then
35+
rm .github/workflows/cleanup.yml
36+
rm -- "$0"
37+
fi
38+
39+
# Remove leftover empty directories
40+
find . -type d -empty -delete

0 commit comments

Comments
 (0)