Skip to content

Repo Sync Stalls

Repo Sync Stalls #1

name: Repo Sync Stalls
# **What it does**: This lets us know in Slack if repo-sync doesn't happen in a timely manner.
# **Why we have it**: We want repo-sync to keep the two repositories in sync with each other.
# **Who does it impact**: Open-source contributors, docs engineering.
on:
workflow_dispatch:
schedule:
- cron: '20 */2 * * *' # Run every 2nd hour at 20 minutes after
permissions:
pull-requests: read
jobs:
repo-sync-stalls:
runs-on: ubuntu-latest
steps:
- if: github.repository == 'github/docs-internal' || github.repository == 'github/docs'
name: Check if repo sync is stalled
uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975
with:
script: |
let pulls;
const owner = context.repo.owner
const repo = context.repo.repo
try {
pulls = await github.rest.pulls.list({
owner: owner,
repo: repo,
head: `${owner}:repo-sync`,
state: 'open'
});
} catch(err) {
throw err
return
}
// Remove all pull requests that don't have the
// 'automated-reposync-pr' label
pulls.data = pulls.data.filter(pr =>
pr.labels.some(label => label.name === 'automated-reposync-pr')
)
// Search for pull requests that have been open too long
pulls.data.forEach(pr => {
const timeDelta = Date.now() - Date.parse(pr.created_at);
const minutesOpen = timeDelta / 1000 / 60;
if (minutesOpen > 180) {
core.setFailed('Repo sync appears to be stalled')
}
})
- name: Send Slack notification if workflow fails
uses: someimportantcompany/github-actions-slack-message@1d367080235edfa53df415bd8e0bbab480f29bad
if: ${{ failure() }}
with:
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }}
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }}
color: failure
text: Repo sync appears to be stalled for ${{github.repository}}. See https://github.com/${{github.repository}}/pulls?q=is%3Apr+is%3Aopen+label%3Aautomated-reposync-pr