Skip to content

try iterator

try iterator #13

Workflow file for this run

name: deps-sync
on:
schedule:
- cron: 0 17 * * FRI
- cron: 10,40 17,18,19 * * FRI
workflow_dispatch:
inputs:
mode:
type: choice
options:
- main_to_deps_merge
- deps_to_main_pull_request
push:
branches:
- deps-syncer
jobs:
main_to_deps_merge:
if: contains(github.ref_name, 'deps-syncer') || github.event.inputs.mode == 'main_to_deps_merge' || github.event.schedule == '10,40 17,18,19 * * FRI'
runs-on: ubuntu-latest
steps:
- id: checkout_deps
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
ref: deps
- run: git log -n 5
- run: git config --global user.name mergebot
- run: git config --global user.email "mergebot@users.noreply.github.com"
- run: git fetch
- run: git merge --strategy-option theirs origin/main
- run: corepack enable
- run: pnpm install --no-frozen-lockfile
- run: |
GIT_STATUS=$(git status --porcelain)
if [ -z "$GIT_STATUS" ]; then
echo "no changes made. git status:"
git status
else
git add .
git commit -m 'chore: changes after pnpm install' --no-verify
fi
- run: git log -n 5
- run: |
is_ahead=$(git status | grep 'Your branch is ahead' || echo '')
if [ -z "$is_ahead" ]; then
git status
echo "no changes to push"
else
git push
fi
deps_to_main_pull_request:
if: contains(github.ref_name, 'deps-syncer') || github.event.inputs.mode == 'deps_to_main_pull_request' || github.event.schedule == '0 17 * * FRI'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
name: Create pull request
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const iterator = github.paginate.iterator(github.pulls.list, {
...context.repo,
state: 'open',
})
for await (const p of iterator) {
console.log('p', p)
}
const {data: pulls} = await github.rest.pulls.list({
...context.repo,
state: 'open',
})
const existing = pulls.find(p => p.head.ref === 'deps' && p.base.ref === 'main')
if (existing) {
console.log('PR already exists:', existing.title, existing.html_url)
return
}
await github.rest.pulls.create({
...context.repo,
title: 'chore: sync deps to main',
head: 'deps',
base: 'main',
body: 'This PR was automatically created by the deps-syncer workflow.',
})