Update rrze-legal.php #5
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: Publish | |
on: | |
push: | |
branches: | |
- dev | |
pull_request: | |
branches: | |
- dev | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Update package.json version & update README using plugin data | |
id: version_update | |
run: | | |
# Define plugin filename | |
plugin_file="rrze-legal.php" | |
# Extract current version from plugin file | |
version=$(grep -oP 'Version:\s*\K[0-9]+\.[0-9]+\.[0-9]+' "$plugin_file") | |
if [ -z "$version" ]; then | |
echo "Version not found in plugin file. Exiting." | |
exit 1 | |
fi | |
echo "Current version: $version" | |
# Set version as an environment variable | |
echo "version=$version" >> $GITHUB_ENV | |
# Update version in package.json if it exists | |
if [ -f "package.json" ]; then | |
jq --arg new_version "$version" '.version = $new_version' package.json > tmp.json && mv tmp.json package.json | |
else | |
echo "package.json not found, skipping version update in package.json" | |
fi | |
# Extract plugin data from plugin file | |
plugin_data=$(awk '/^[ \t]*\*?[ \t]*(Plugin Name|Plugin URI|Version|Description|Author|Author URI|License|License URI|Text Domain|Domain Path|Requires at least|Requires PHP|Update URI):/ { gsub(/^[ \t]*\*?[ \t]*/, ""); print $0 }' "$plugin_file") | |
echo "$plugin_data" | |
# Write plugin data to readme.txt if it exists | |
if [ -f "readme.txt" ]; then | |
# Update readme.txt content | |
echo "$plugin_data" > readme.txt | |
else | |
echo "readme.txt not found, skipping plugin data update in readme.txt" | |
fi | |
- name: Commit version changes to dev | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add . | |
git commit -m "Publish" || echo "No changes to commit" | |
git push origin dev || { echo "Error: Push to dev branch failed"; exit 1; } | |
- name: Check if tag or release exists | |
env: | |
version: ${{ env.version }} | |
run: | | |
if git rev-parse "${{ env.version }}" >/dev/null 2>&1; then | |
echo "Tag ${{ env.version }} already exists. Skipping release." | |
exit 1 | |
fi | |
- name: Check out the main branch | |
run: | | |
git fetch origin | |
git checkout main | |
git pull origin main | |
- name: Merge dev into main | |
run: | | |
git merge origin/dev --no-ff -m "Merging from dev to main" || { echo "Error: Merge failed"; exit 1; } | |
- name: Push changes to main branch | |
run: | | |
git push origin main || { echo "Error: Push to main branch failed"; exit 1; } | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
version: ${{ env.version }} | |
with: | |
tag_name: "${{ env.version }}" | |
release_name: "v${{ env.version }}" | |
draft: false | |
prerelease: false | |
- name: Check if Release was Created | |
if: steps.create_release.outputs.id == '' | |
run: | | |
echo "Release creation failed" | |
exit 1 | |
- name: Send Matrix notification | |
env: | |
MATRIX_ACCESS_TOKEN: ${{ secrets.MATRIX_ACCESS_TOKEN }} | |
MATRIX_ROOM_ID: "%21wyUpkRsFMDGzzGmxBf%3Afau.de" # HTML-encoded room ID | |
run: | | |
response=$(curl -s -o /dev/null -w "%{http_code}" -X POST "https://matrix.fau.de/_matrix/client/r0/rooms/${MATRIX_ROOM_ID}/send/m.room.message?access_token=${MATRIX_ACCESS_TOKEN}" \ | |
-H "Content-Type: application/json" \ | |
-d "{ | |
\"msgtype\": \"m.text\", | |
\"body\": \"New release created for ${GITHUB_REPOSITORY} by ${GITHUB_ACTOR}. 🎉\" | |
}") | |
if [ "$response" -ne 200 ]; then | |
echo "Error: Failed to send notification to Matrix. HTTP status code: $response" | |
fi |