forked from dcflachs/compose_plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
128 lines (110 loc) · 4.75 KB
/
Copy pathsync-plugin-url.yml
File metadata and controls
128 lines (110 loc) · 4.75 KB
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
120
121
122
123
124
125
126
127
128
# .github/workflows/sync-plugin-url.yml
# Ensures the PLG pluginURL entity always points to the current branch
#
# This prevents issues when merging between dev and main where the
# pluginURL would reference the wrong branch for update checks.
#
# Triggers on push and merged PRs to main/dev to self-heal branch links.
name: Sync Plugin URL
on:
push:
branches: [main, dev]
pull_request:
types: [closed]
branches: [main, dev]
workflow_dispatch:
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
sync-url:
permissions:
contents: write
runs-on: ubuntu-latest
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
steps:
- name: Resolve target branch
id: target
run: |
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
TARGET_BRANCH="${GITHUB_REF_NAME}"
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
else
TARGET_BRANCH="${GITHUB_REF_NAME}"
fi
case "$TARGET_BRANCH" in
main|dev)
echo "target_branch=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
;;
*)
echo "Unsupported branch '$TARGET_BRANCH'; skipping."
echo "target_branch=" >> "$GITHUB_OUTPUT"
;;
esac
- name: Checkout repository
if: steps.target.outputs.target_branch != ''
uses: actions/checkout@v6
with:
ref: ${{ steps.target.outputs.target_branch }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check and fix pluginURL branch + README badge
if: steps.target.outputs.target_branch != ''
id: check
run: |
BRANCH="${{ steps.target.outputs.target_branch }}"
PLG_FILE="compose.manager.plg"
README_FILE="source/compose.manager/README.md"
NEEDS_COMMIT=false
# Ensure pluginURL uses the current branch
CURRENT_URL_BRANCH=$(sed -n 's#^<!ENTITY pluginURL "https://raw.githubusercontent.com/&github;/\([^/]*\)/&name;\.plg">$#\1#p' "$PLG_FILE")
if [[ -z "$CURRENT_URL_BRANCH" ]]; then
echo "Failed to parse pluginURL entity in $PLG_FILE"
exit 1
fi
echo "Current branch: $BRANCH"
echo "PLG pluginURL branch: $CURRENT_URL_BRANCH"
if [[ "$CURRENT_URL_BRANCH" != "$BRANCH" ]]; then
echo "Branch mismatch - fixing pluginURL..."
sed -i -E "s#^<!ENTITY pluginURL \"https://raw.githubusercontent.com/&github;/[^/]*/&name;\\.plg\">#<!ENTITY pluginURL \"https://raw.githubusercontent.com/&github;/${BRANCH}/&name;.plg\">#" "$PLG_FILE"
EXPECTED_LINE="<!ENTITY pluginURL \"https://raw.githubusercontent.com/&github;/${BRANCH}/&name;.plg\">"
if ! grep -Fxq "$EXPECTED_LINE" "$PLG_FILE"; then
echo "pluginURL rewrite verification failed"
exit 1
fi
NEEDS_COMMIT=true
else
echo "pluginURL already correct"
fi
# Ensure README disposition matches branch
if [[ "$BRANCH" == "dev" ]]; then
# dev should show beta
if grep -q "^\*\*Compose Manager Plus (Beta)\*\*$" "$README_FILE"; then
echo "README already has beta title (dev branch)"
else
echo "Setting README title to beta form for dev branch..."
sed -i '1s|^\*\*Compose Manager Plus.*\*\*$|**Compose Manager Plus (Beta)**|' "$README_FILE"
NEEDS_COMMIT=true
fi
else
# main should not show beta
if grep -q "^\*\*Compose Manager Plus (Beta)\*\*$" "$README_FILE"; then
echo "Removing beta title from README for main branch..."
sed -i '1s|^\*\*Compose Manager Plus (Beta)\*\*$|**Compose Manager Plus**|' "$README_FILE"
NEEDS_COMMIT=true
else
echo "README already has non-beta title for main branch"
fi
fi
echo "needs_commit=$NEEDS_COMMIT" >> $GITHUB_OUTPUT
- name: Commit fix
if: steps.target.outputs.target_branch != '' && steps.check.outputs.needs_commit == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add compose.manager.plg source/compose.manager/README.md
git commit -m "chore: sync pluginURL+README for ${{ steps.target.outputs.target_branch }} branch [skip ci]"
git pull --rebase origin "${{ steps.target.outputs.target_branch }}"
git push