|
| 1 | +# Workflow to cleanup projects created from this template |
| 2 | +# Adapted from workflow of the same name in https://github.com/JetBrains/intellij-platform-plugin-template |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: Template Cleanup |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + |
| 10 | +jobs: |
| 11 | + # Triggered on first push to repos created from the template |
| 12 | + template-cleanup: |
| 13 | + name: Template Cleanup |
| 14 | + permissions: |
| 15 | + contents: write |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: github.event.repository.name != 'chisel-template' |
| 18 | + steps: |
| 19 | + |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + # These are needed to make ad-m/github-push-action work |
| 24 | + # https://github.com/ad-m/github-push-action/tree/d91a481090679876dfc4178fef17f286781251df#example-workflow-file |
| 25 | + persist-credentials: false |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Cleanup |
| 29 | + run: | |
| 30 | + export LC_CTYPE=C |
| 31 | + export LANG=C |
| 32 | +
|
| 33 | + # Prepare variables |
| 34 | + NAME="${GITHUB_REPOSITORY##*/}" |
| 35 | + ORG="$GITHUB_REPOSITORY_OWNER" |
| 36 | + SAFE_ORG=$(echo $ORG | sed 's/[^a-zA-Z0-9]//g' | tr '[:upper:]' '[:lower:]') |
| 37 | + GROUP="com.github.$SAFE_ORG" |
| 38 | +
|
| 39 | + # Prepare wrapped name |
| 40 | + WRAPPED_NAME="\`${NAME}\`" |
| 41 | +
|
| 42 | + # Replace placeholders |
| 43 | + sed -i "s/%NAME%/$NAME/g" build.sbt README.md src/test/scala/gcd/* |
| 44 | + sed -i "s/%NAME%/$WRAPPED_NAME/g" build.mill |
| 45 | + sed -i "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" README.md |
| 46 | + sed -i "s/%ORGANIZATION%/$GROUP/g" build.sbt |
| 47 | +
|
| 48 | + # Remove lines marked with #REMOVE-ON-CLEANUP# |
| 49 | + sed -i '/#REMOVE-ON-CLEANUP#/d' README.md |
| 50 | +
|
| 51 | + rm -rf \ |
| 52 | + .github/workflows/template-cleanup.yml \ |
| 53 | + LICENSE |
| 54 | +
|
| 55 | + - name: Commit |
| 56 | + run: | |
| 57 | + git config --local user.email "action@github.com" |
| 58 | + git config --local user.name "GitHub Action" |
| 59 | + git add . |
| 60 | + git commit -m "Template cleanup" |
| 61 | +
|
| 62 | + - name: Push changes |
| 63 | + uses: ad-m/github-push-action@v0.8.0 |
| 64 | + with: |
| 65 | + branch: main |
| 66 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments