-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# GitHub Actions Workflow responsible for cleaning up the JetBrains Academy Kotlin Course Template repository from the template-specific files and configurations. | ||
# This workflow is supposed to be triggered automatically when a new template-based repository has been created. | ||
|
||
name: Template Cleanup | ||
on: | ||
push: | ||
branches: [main, test] | ||
|
||
jobs: | ||
|
||
# Run a cleaning process only if the workflow is triggered by the non-"kotlin-course-template" repository. | ||
template-cleanup: | ||
name: Template Cleanup | ||
runs-on: ubuntu-latest | ||
if: github.event.repository.name != 'kotlin-course-template' | ||
permissions: | ||
contents: write | ||
steps: | ||
|
||
# Check out current repository | ||
- name: Fetch Sources | ||
uses: actions/checkout@v4 | ||
|
||
# Cleanup project | ||
- name: Cleanup | ||
run: | | ||
export LC_CTYPE=C | ||
export LANG=C | ||
# Prepare variables | ||
NAME="${GITHUB_REPOSITORY##*/}" | ||
ACTOR=$(echo $GITHUB_ACTOR | tr '[:upper:]' '[:lower:]') | ||
SAFE_NAME=$(echo $NAME | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') | ||
SAFE_ACTOR=$(echo $ACTOR | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') | ||
GROUP="com.github.$SAFE_ACTOR.$SAFE_NAME" | ||
# Replace template package name in project files with $GROUP | ||
find src -type f -exec sed -i "s/org.jetbrains.academy.kotlin.template/$GROUP/g" {} + | ||
find src -type f -exec sed -i "s/JetBrains Academy Kotlin Course/$NAME/g" {} + | ||
find src -type f -exec sed -i "s/jetBrains-academy/$ACTOR/g" {} + | ||
# Move content | ||
mkdir -p common/src/main/kotlin/${GROUP//.//} | ||
cp -R common/src/main/kotlin/org/jetbrains/academy/kotlin/template/* common/src/main/kotlin/${GROUP//.//}/ | ||
# Cleanup | ||
rm -rf \ | ||
.github/workflows/template-cleanup.yml \ | ||
common/src/main/kotlin/org \ | ||
LICENSE | ||
# Commit modified files | ||
- name: Commit files | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git add . | ||
git commit -m "Template cleanup" | ||
# Push changes | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
branch: main | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |