Replace MarkItUp in includes #9
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
name: Replace MarkItUp in includes | |
on: | |
workflow_dispatch: | |
inputs: | |
base_branch: | |
description: 'The base branch for the pull request (e.g. main, master, develop)' | |
required: true | |
default: 'main' | |
jobs: | |
replace_markitup: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set up PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.1' | |
- name: Find and Replace in .inc files | |
run: | | |
find lib -type f -name '*.inc' -print0 | while IFS= read -r -d $'\0' file; do | |
if grep -q "markitup::" "$file"; then | |
echo "Processing: $file" | |
# Überprüfe ob die Datei bereits die <?php und use Anweisung enthält | |
if ! grep -q "^<\?php.*use FriendsOfRedaxo\\\\MarkItUp\\\\MarkItUp;.*$" "$file"; then | |
echo "Adding '<?php' and use statement at the beginning of $file" | |
sed -i '1s/^/<?php\nuse FriendsOfRedaxo\\MarkItUp\\MarkItUp;\n/' "$file" | |
else | |
echo "<?php and use statement already present in $file" | |
fi | |
# Ersetze das MarkItUp (nachdem <?php eingefügt wurde) | |
sed -i 's/markitup::MarkItUp::/MarkItUp::/g' "$file" | |
sed -i 's/markitup::/MarkItUp::/g' "$file" | |
else | |
echo "Skipping $file, no markitup:: found" | |
fi | |
done | |
- name: Configure Git | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email '[email protected]' | |
- name: Create Branch and Commit Changes | |
run: | | |
git checkout -b refactor/markitup-replace | |
git add . | |
git commit -m "Refactor: Replace markitup:: and add use statement" | |
echo "Branch created, changes commited" | |
- name: Push Branch | |
run: | | |
git push --force origin refactor/markitup-replace | |
echo "Branch 'refactor/markitup-replace' pushed to remote" | |
- name: Create Pull Request | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
console.log('Attempting to create pull request...') | |
const { data: pr } = await github.rest.pulls.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: 'Refactor: Replace markitup:: and add use statement', | |
head: 'refactor/markitup-replace', | |
base: '${{ github.event.inputs.base_branch }}', | |
body: 'This pull request replaces `markitup::MarkItUp::` with `MarkItUp::` in all `.inc` files under `lib/` and adds `<?php` and `use FriendsOfRedaxo\\MarkItUp\\MarkItUp;` at the beginning if not present.', | |
}); | |
console.log(`Pull request created: ${pr.html_url}`); |