fix(sync-plugin-url): enhance branch detection and pluginURL synchron… #27
This file contains hidden or 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/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 |