|
| 1 | +# GitHub Actions Workflow responsible for cleaning up the Advent of Code Kotlin Template repository from |
| 2 | +# the template-specific files and configurations. This workflow is supposed to be triggered automatically |
| 3 | +# when a new template-based repository has been created. |
| 4 | + |
| 5 | +name: Template Cleanup |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + |
| 13 | + # Run cleaning process only if workflow is triggered by the .../advent-of-code-kotlin-template repository. |
| 14 | + template-cleanup: |
| 15 | + name: Template Cleanup |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.event.repository.name != 'advent-of-code-kotlin-template' |
| 18 | + steps: |
| 19 | + |
| 20 | + # Check out current repository |
| 21 | + - name: Fetch Sources |
| 22 | + |
| 23 | + |
| 24 | + # Cleanup project |
| 25 | + - name: Cleanup |
| 26 | + run: | |
| 27 | + export LC_CTYPE=C |
| 28 | + export LANG=C |
| 29 | +
|
| 30 | + # Prepare variables |
| 31 | + NAME="${GITHUB_REPOSITORY##*/}" |
| 32 | + ACTOR=$(echo $GITHUB_ACTOR | tr '[:upper:]' '[:lower:]') |
| 33 | + SAFE_NAME=$(echo $NAME | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') |
| 34 | + SAFE_ACTOR=$(echo $ACTOR | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') |
| 35 | + GROUP="com.github.$SAFE_ACTOR.$SAFE_NAME" |
| 36 | +
|
| 37 | + # Replace placeholders in the template-cleanup files |
| 38 | + sed -i "s/%NAME%/$NAME/g" .github/template-cleanup/* |
| 39 | + sed -i "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" .github/template-cleanup/* |
| 40 | + sed -i "s/%GROUP%/$GROUP/g" .github/template-cleanup/* |
| 41 | +
|
| 42 | + # Replace template package name in project files with $GROUP |
| 43 | + find src -type f -exec sed -i "s/com.github.hsz.aoc/$GROUP/g" {} + |
| 44 | + find src -type f -exec sed -i "s/Template/$NAME/g" {} + |
| 45 | + find src -type f -exec sed -i "s/JetBrains/$ACTOR/g" {} + |
| 46 | +
|
| 47 | + # Move content |
| 48 | + mkdir -p src/main/kotlin/${GROUP//.//} |
| 49 | + mkdir -p src/test/kotlin/${GROUP//.//} |
| 50 | + cp -R .github/template-cleanup/* . |
| 51 | + cp -R src/main/kotlin/com/github/hsz/aoc/* src/main/kotlin/${GROUP//.//}/ |
| 52 | + cp -R src/test/kotlin/com/github/hsz/aoc/* src/test/kotlin/${GROUP//.//}/ |
| 53 | +
|
| 54 | + # Cleanup |
| 55 | + rm -rf \ |
| 56 | + .github/readme \ |
| 57 | + .github/template-cleanup \ |
| 58 | + .github/workflows/template-cleanup.yml \ |
| 59 | + CODE_OF_CONDUCT.md \ |
| 60 | + LICENSE |
| 61 | + |
| 62 | + find . -type d -empty -delete |
| 63 | +
|
| 64 | + # Commit modified files |
| 65 | + - name: Commit files |
| 66 | + run: | |
| 67 | + git config --local user.email "[email protected]" |
| 68 | + git config --local user.name "GitHub Action" |
| 69 | + git add . |
| 70 | + git commit -m "Template cleanup" |
| 71 | +
|
| 72 | + # Push changes |
| 73 | + - name: Push changes |
| 74 | + uses: ad-m/github-push-action@master |
| 75 | + with: |
| 76 | + branch: main |
| 77 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments