-
Notifications
You must be signed in to change notification settings - Fork 2
119 lines (102 loc) · 4.13 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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