Skip to content

Commit

Permalink
Try to change project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
nbirillo committed Oct 24, 2023
1 parent 84607eb commit 168dbda
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/template-cleanup.yml
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 }}

0 comments on commit 168dbda

Please sign in to comment.