Skip to content

Commit d623d69

Browse files
committed
ci: harden upstream sync workflow config
1 parent a2686c6 commit d623d69

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

.github/workflows/sync-upstream.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@ on:
44
schedule:
55
- cron: '0 7 * * *' # Every day at 07:00 UTC
66
workflow_dispatch:
7+
inputs:
8+
upstream_branch:
9+
description: 'Upstream branch to sync from (default: main)'
10+
required: false
11+
default: 'main'
12+
type: string
713

814
permissions:
915
contents: write
1016
pull-requests: write
1117

18+
concurrency:
19+
group: sync-upstream-${{ github.repository }}
20+
cancel-in-progress: true
21+
1222
jobs:
1323
sync:
1424
runs-on: ubuntu-latest
1525
env:
1626
UPSTREAM_REPO: https://github.com/garrytan/gstack.git
17-
UPSTREAM_BRANCH: main
27+
UPSTREAM_BRANCH: ${{ inputs.upstream_branch || 'main' }}
1828
SYNC_BRANCH: sync/upstream-main
1929
BASE_BRANCH: ${{ github.event.repository.default_branch }}
2030

@@ -44,6 +54,7 @@ jobs:
4454
const repo = context.repo.repo;
4555
const head = `${owner}:${process.env.SYNC_BRANCH}`;
4656
const base = process.env.BASE_BRANCH || 'main';
57+
const labels = ['upstream-sync', 'dependencies'];
4758
4859
const compare = await github.rest.repos.compareCommitsWithBasehead({
4960
owner,
@@ -65,7 +76,20 @@ jobs:
6576
});
6677
6778
if (open.data.length > 0) {
68-
core.info(`Sync PR already exists: #${open.data[0].number}`);
79+
const pr = open.data[0];
80+
await github.rest.issues.addLabels({
81+
owner,
82+
repo,
83+
issue_number: pr.number,
84+
labels
85+
});
86+
await github.rest.pulls.update({
87+
owner,
88+
repo,
89+
pull_number: pr.number,
90+
title: `chore: sync upstream (${process.env.UPSTREAM_BRANCH} -> ${base})`
91+
});
92+
core.info(`Sync PR already exists: #${pr.number}`);
6993
return;
7094
}
7195
@@ -86,4 +110,11 @@ jobs:
86110
].join('\n')
87111
});
88112
113+
await github.rest.issues.addLabels({
114+
owner,
115+
repo,
116+
issue_number: created.data.number,
117+
labels
118+
});
119+
89120
core.info(`Created PR #${created.data.number}: ${created.data.html_url}`);

0 commit comments

Comments
 (0)