Skip to content

Commit 49f2a89

Browse files
committed
chore: update workflow
1 parent d9376bb commit 49f2a89

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

‎.github/workflows/upstream-sync.yml‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
echo "Triggered manually from the Actions tab (Run workflow)."
3939
if [ -n "$NOTE" ]; then printf 'Note: %s\n' "$NOTE"; fi
4040
41-
- name: Checkout fork
41+
- name: Checkout repository
4242
uses: actions/checkout@v5
4343
with:
4444
ref: ${{ env.BASE_BRANCH }}
@@ -55,16 +55,32 @@ jobs:
5555
git remote add upstream "$UPSTREAM_URL"
5656
git fetch upstream "$UPSTREAM_REF"
5757
58-
- name: Skip if fork already contains upstream
58+
- name: Skip if main already contains upstream
5959
id: up_to_date
6060
run: |
6161
if git merge-base --is-ancestor "upstream/${UPSTREAM_REF}" "${BASE_BRANCH}"; then
62-
echo "Fork ${BASE_BRANCH} already contains MHSanaei/3x-ui ${UPSTREAM_REF} — nothing to do."
62+
echo "${BASE_BRANCH} already contains MHSanaei/3x-ui ${UPSTREAM_REF} — nothing to do."
6363
echo "skip=true" >> "$GITHUB_OUTPUT"
6464
else
6565
echo "skip=false" >> "$GITHUB_OUTPUT"
6666
fi
6767
68+
- name: Detect changes under .github/workflows
69+
id: workflow_delta
70+
if: steps.up_to_date.outputs.skip != 'true'
71+
run: |
72+
if git diff --name-only "${BASE_BRANCH}" "upstream/${UPSTREAM_REF}" | grep -qE '^\.github/workflows/'; then
73+
echo "touches_workflows=true" >> "$GITHUB_OUTPUT"
74+
else
75+
echo "touches_workflows=false" >> "$GITHUB_OUTPUT"
76+
fi
77+
78+
- name: SYNC_PAT required when sync touches workflow files
79+
if: steps.up_to_date.outputs.skip != 'true' && steps.workflow_delta.outputs.touches_workflows == 'true' && secrets.SYNC_PAT == ''
80+
run: |
81+
echo '::error::This sync would update .github/workflows (upstream differs from your default branch). The built-in GITHUB_TOKEN cannot push those files. Add a repository secret named SYNC_PAT: create a classic personal access token with the repo and workflow scopes at https://github.com/settings/tokens, or a fine-grained token with read/write on Contents and Workflows. Re-run the workflow after saving the secret.' >&2
82+
exit 1
83+
6884
- name: Reset sync branch to upstream
6985
if: steps.up_to_date.outputs.skip != 'true'
7086
run: |

0 commit comments

Comments
 (0)