Merge pull request #11 from VeyronSakai/fix/cleanup-pr-template #21
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
# GitHub Actions Workflow responsible for cleaning up the Roslyn Analyzer 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. | |
# This workflow made with reference to https://github.com/JetBrains/intellij-platform-plugin-template | |
name: Template Cleanup | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
# Run cleaning process only if workflow is triggered by the non-RoslynAnalyzerTemplate repository. | |
template-cleanup: | |
name: Template Cleanup | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
if: github.event.repository.name != 'RoslynAnalyzerTemplate' | |
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" | |
# Rename template project directories | |
find . -type d -name 'RoslynAnalyzerTemplate*' -print0 | while IFS= read -r -d '' file | |
do | |
mv "$file" "${file/RoslynAnalyzerTemplate/$NAME}" | |
done | |
find . -type f -name 'RoslynAnalyzerTemplate*' -print0 | while IFS= read -r -d '' file | |
do | |
mv "$file" "${file/RoslynAnalyzerTemplate/$NAME}" | |
done | |
# Replace template name in project files | |
find . -type f \( -name "*.sln" -or -name "*.csproj" -or -name "*.cs" \) -exec sed -i "s/DeNA/$GITHUB_REPOSITORY_OWNER/g" {} + | |
find . -type f \( -name "*.sln" -or -name "*.csproj" -or -name "*.cs" \) -exec sed -i "s/RoslynAnalyzerTemplate/$NAME/g" {} + | |
find . -type f -name "AnalyzerReleases.*.md" -exec sed -i "s/RoslynAnalyzerTemplate/$NAME/g" {} + | |
# Replace placeholders in the template-cleanup files | |
sed -i "s/%NAME%/$NAME/g" .github/template-cleanup/* | |
sed -i "s/%REPOSITORY%/${GITHUB_REPOSITORY/\//\\/}/g" .github/template-cleanup/* | |
sed -i "s/%GROUP%/$GROUP/g" .github/template-cleanup/* | |
# Move content | |
cp -R .github/template-cleanup/* . | |
# Cleanup | |
rm -rf \ | |
.github/template-cleanup \ | |
.github/workflows/template-cleanup.yml \ | |
.github/CODEOWNERS \ | |
.github/pull_request_template.md \ | |
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: ${{ github.ref }} | |
github_token: ${{ secrets.GITHUB_TOKEN }} |