File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # GitHub Actions Workflow responsible for cleaning up the 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 : [main]
9+
10+ jobs :
11+
12+ # Run cleaning process only if workflow is triggered by the non-"android-library-template" repository.
13+ template-cleanup :
14+ name : Template Cleanup
15+ runs-on : ubuntu-latest
16+ if : github.event.repository.name != 'android-library-template'
17+ permissions :
18+ contents : write
19+ steps :
20+
21+ # Check out current repository
22+ - name : Fetch Sources
23+ uses : actions/checkout@v4
24+
25+ # Cleanup project
26+ - name : Cleanup
27+ 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
45+
46+ # Commit modified files
47+ - name : Commit files
48+ run : |
49+ git config --local user.email "action@github.com"
50+ git config --local user.name "GitHub Action"
51+ git add .
52+ git commit -m "Template cleanup"
53+
54+ # Push changes
55+ - name : Push changes
56+ uses : ad-m/github-push-action@master
57+ with :
58+ branch : main
59+ github_token : ${{ secrets.GITHUB_TOKEN }}
You can’t perform that action at this time.
0 commit comments