|
| 1 | +name: "Sync with upstream" |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: 20 4 * * * |
| 6 | + |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | + |
| 10 | +env: |
| 11 | + # repo to fetch changes from |
| 12 | + UPSTREAM_REPO: vllm-project/vllm |
| 13 | + # branch to sync |
| 14 | + BRANCH: main |
| 15 | + |
| 16 | +jobs: |
| 17 | + upstream-sync: |
| 18 | + name: Sync with upstream |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + pull-requests: write |
| 22 | + contents: write |
| 23 | + |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Fetch upstream repo |
| 30 | + run: | |
| 31 | + git remote add upstream https://github.com/${UPSTREAM_REPO} |
| 32 | + git fetch upstream |
| 33 | +
|
| 34 | + - name: Check diff |
| 35 | + id: diff |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + echo 'diff<<EOF' >> $GITHUB_OUTPUT |
| 39 | + git diff --stat upstream/${BRANCH} | tee -a >(cat >> $GITHUB_OUTPUT) |
| 40 | + echo 'EOF' >> $GITHUB_OUTPUT |
| 41 | +
|
| 42 | + - name: Create PR |
| 43 | + if: ${{ steps.diff.outputs.diff != '' }} |
| 44 | + env: |
| 45 | + GH_TOKEN: ${{ github.token }} |
| 46 | + run: | |
| 47 | + set -xeu |
| 48 | +
|
| 49 | + git_hash="$(git rev-parse upstream/${BRANCH})" |
| 50 | + echo "git_hash=$git_hash" >> $GITHUB_OUTPUT |
| 51 | + git_describe="$(git describe --tags upstream/${BRANCH})" |
| 52 | + echo "git_describe=$git_describe" >> $GITHUB_OUTPUT |
| 53 | +
|
| 54 | + # echo 'commits<<EOF' >> $GITHUB_OUTPUT |
| 55 | + # git log --oneline ..upstream/${BRANCH} >> $GITHUB_OUTPUT |
| 56 | + # echo 'EOF' >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + upstream_url="https://github.com/${UPSTREAM_REPO}" |
| 59 | + upstream_branch="$upstream_url/tree/${BRANCH}" |
| 60 | +
|
| 61 | + title="Sync with upstream@${git_describe}" |
| 62 | + body="Merge [${UPSTREAM_REPO}]($upstream_url):[${BRANCH}]($upstream_branch)@[${git_describe}](${upstream_url}/commit/$git_hash) into $BRANCH" |
| 63 | +
|
| 64 | + gh repo set-default $GITHUB_REPOSITORY |
| 65 | + pr_number=$(gh pr list -S "Sync with upstream@" --json number --jq '.[0].number') |
| 66 | +
|
| 67 | + if [[ -z $pr_number ]]; then |
| 68 | + echo "Creating PR" |
| 69 | + gh pr create \ |
| 70 | + --head $(echo $UPSTREAM_REPO | sed 's|/|:|g'):${BRANCH} \ |
| 71 | + --base ${BRANCH} \ |
| 72 | + --label code-sync \ |
| 73 | + --title "$title" \ |
| 74 | + --body "$body" \ |
| 75 | + --no-maintainer-edit |
| 76 | + exit 0 |
| 77 | + fi |
| 78 | +
|
| 79 | + echo "Checking if PR is up-to-date" |
| 80 | +
|
| 81 | + git fetch ${upstream_url} refs/pull/${pr_number}/head |
| 82 | + if git diff --stat --exit-code upstream/main FETCH_HEAD; then |
| 83 | + echo "PR is up-to-date" |
| 84 | + exit 0 |
| 85 | + fi |
| 86 | +
|
| 87 | + echo "Updating PR \#${pr_number}" |
| 88 | + gh pr edit \ |
| 89 | + $pr_number \ |
| 90 | + --body "$body" \ |
| 91 | + --title "$title" |
0 commit comments