Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/scripts/check-upstream.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module.exports = async function checkUpstream({ github, context, core }) {
const { data: fork } = await github.rest.repos.get(context.repo)
const upstream = fork.parent
if (upstream?.full_name !== 'iainmcgin/cla-github-action') {
throw new Error(
'Expected iainmcgin/cla-github-action as the fork parent; verify the fork relationship before changing the monitor.'
)
}
const { data: comparison } =
await github.rest.repos.compareCommitsWithBasehead({
owner: upstream.owner.login,
repo: upstream.name,
basehead: `${upstream.default_branch}...${context.repo.owner}:${fork.default_branch}`
})

if (['ahead', 'identical'].includes(comparison.status)) {
core.info('The fork contains all upstream commits.')
return
}
if (!['behind', 'diverged'].includes(comparison.status)) {
throw new Error(`Unexpected comparison status: ${comparison.status}`)
}

const head = comparison.base_commit.sha
const marker = `<!-- upstream-monitor:${upstream.full_name}@${head} -->`
const issues = await github.paginate(github.rest.issues.listForRepo, {
...context.repo,
creator: 'github-actions[bot]',
state: 'all',
per_page: 100
})
if (
issues.some(
issue =>
!issue.pull_request &&
issue.user?.login === 'github-actions[bot]' &&
issue.body?.includes(marker)
)
) {
core.info(`Upstream commit ${head} already has a tracking issue.`)
return
}

const { data: issue } = await github.rest.issues.create({
...context.repo,
title: `Review upstream CLA action changes (${head.slice(0, 7)})`,
body: [
`\`${upstream.full_name}:${upstream.default_branch}\` has ${comparison.behind_by} commit(s) missing from this fork's \`${fork.default_branch}\` history.`,
`Upstream tip: [${head}](https://github.com/${upstream.full_name}/commit/${head}).`,
`[Compare changes](https://github.com/${context.repo.owner}/${context.repo.repo}/compare/${fork.default_branch}...${upstream.owner.login}:${head}).`,
'Review and bring in applicable changes. Record adopted changes in `CHANGELOG.md`, rebuild `dist/` when runtime code or dependencies change, and update pinned consumers after validation.',
'Closing this issue acknowledges this upstream tip. A later tip gets its own issue.',
marker
].join('\n\n')
})
core.info(`Opened ${issue.html_url}`)
}
28 changes: 28 additions & 0 deletions .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Check upstream

on:
schedule:
- cron: '17 10 * * *'
workflow_dispatch:

permissions:
contents: read
issues: write

concurrency:
group: upstream-monitor
cancel-in-progress: false

jobs:
check:
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const checkUpstream = require('./.github/scripts/check-upstream.cjs')
await checkUpstream({ github, context, core })
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commit that introduced it.

## Unreleased

- Check the parent fork daily and open one tracking issue per upstream tip with commits missing from this fork's history.
- Open Waters maintains its own fork with pinned CI actions, Node 24 checks, weekly dependency updates, and verification of the committed action bundle.
- Resolve primary authors and co-authors through GitHub's account identities, including legacy noreply and verified email addresses. Reject null author entries and commits with more than 100 authors instead of skipping contributors.
- Preserve email exemptions for linked co-authors while requiring the authenticated human PR opener to sign. Signing exemptions do not bypass the opener authorship guard or its diagnostic output. Authorship follows GitHub's recognized trailers; an unrelated committer identity does not stand in for an unlinked author.
Expand Down
141 changes: 141 additions & 0 deletions __tests__/unit/upstreamMonitor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
const checkUpstream = require('../../.github/scripts/check-upstream.cjs')

describe('upstream monitor', () => {
const context = { repo: { owner: 'openwatersio', repo: 'cla-github-action' } }
const core = { info: jest.fn() }
const github = {
rest: {
repos: { get: jest.fn(), compareCommitsWithBasehead: jest.fn() },
issues: { listForRepo: jest.fn(), create: jest.fn() }
},
paginate: jest.fn()
}
const head = 'a'.repeat(40)
const marker = `<!-- upstream-monitor:iainmcgin/cla-github-action@${head} -->`

beforeEach(() => {
jest.resetAllMocks()
github.rest.repos.get.mockResolvedValue({
data: {
default_branch: 'master',
parent: {
owner: { login: 'iainmcgin' },
name: 'cla-github-action',
full_name: 'iainmcgin/cla-github-action',
default_branch: 'master'
}
}
})
github.rest.repos.compareCommitsWithBasehead.mockResolvedValue({
data: { status: 'diverged', behind_by: 2, base_commit: { sha: head } }
})
github.paginate.mockResolvedValue([])
github.rest.issues.create.mockResolvedValue({
data: { html_url: 'issue-url' }
})
})

it.each([undefined, { full_name: 'cla-assistant/github-action' }])(
'fails clearly instead of watching a missing or different parent: %s',
async parent => {
github.rest.repos.get.mockResolvedValue({
data: { default_branch: 'master', parent }
})
await expect(checkUpstream({ github, context, core })).rejects.toThrow(
'Expected iainmcgin/cla-github-action as the fork parent'
)
expect(
github.rest.repos.compareCommitsWithBasehead
).not.toHaveBeenCalled()
expect(github.rest.issues.create).not.toHaveBeenCalled()
}
)

it.each(['ahead', 'identical'])(
'does not open an issue when the fork is %s',
async status => {
github.rest.repos.compareCommitsWithBasehead.mockResolvedValue({
data: { status, behind_by: 0, base_commit: { sha: head } }
})
await checkUpstream({ github, context, core })
expect(github.rest.issues.create).not.toHaveBeenCalled()
expect(github.paginate).not.toHaveBeenCalled()
}
)

it.each(['behind', 'diverged'])(
'opens an issue when the fork has %s history',
async status => {
github.rest.repos.compareCommitsWithBasehead.mockResolvedValue({
data: { status, behind_by: 2, base_commit: { sha: head } }
})
await checkUpstream({ github, context, core })
expect(github.rest.repos.compareCommitsWithBasehead).toHaveBeenCalledWith(
{
owner: 'iainmcgin',
repo: 'cla-github-action',
basehead: 'master...openwatersio:master'
}
)
expect(github.rest.issues.create).toHaveBeenCalledWith({
...context.repo,
title: expect.stringContaining(head.slice(0, 7)),
body: expect.stringContaining(marker)
})
expect(github.rest.issues.create.mock.calls[0][0].body).toContain(
`/compare/master...iainmcgin:${head}`
)
}
)

it.each(['open', 'closed'])(
'does not duplicate an %s issue for the same upstream tip',
async state => {
github.paginate.mockResolvedValue([
{ state, body: marker, user: { login: 'github-actions[bot]' } }
])
await checkUpstream({ github, context, core })
expect(github.paginate).toHaveBeenCalledWith(
github.rest.issues.listForRepo,
{
...context.repo,
creator: 'github-actions[bot]',
state: 'all',
per_page: 100
}
)
expect(github.rest.issues.create).not.toHaveBeenCalled()
}
)

it('opens a new issue for a new tip even after an older alert was closed', async () => {
github.paginate.mockResolvedValue([
{
state: 'closed',
body: marker.replace(head, 'b'.repeat(40)),
user: { login: 'github-actions[bot]' }
}
])
await checkUpstream({ github, context, core })
expect(github.rest.issues.create).toHaveBeenCalledTimes(1)
})

it('does not let human issues or pull requests suppress an alert', async () => {
github.paginate.mockResolvedValue([
{ body: marker, user: { login: 'mallory' } },
{ body: marker, user: { login: 'github-actions[bot]' }, pull_request: {} }
])
await checkUpstream({ github, context, core })
expect(github.rest.issues.create).toHaveBeenCalledTimes(1)
})

it('fails visibly on comparison errors without inventing an upstream alert', async () => {
github.rest.repos.compareCommitsWithBasehead.mockRejectedValue(
new Error('API unavailable')
)
await expect(checkUpstream({ github, context, core })).rejects.toThrow(
'API unavailable'
)
expect(github.rest.issues.create).not.toHaveBeenCalled()
})
})
10 changes: 10 additions & 0 deletions docs/open-waters.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ Keep signature-only commits out of application build lanes. If two runs try to u
Confirm the App installation and each token expose only `.cla.json` for writing. Check that existing signature IDs and comment metadata survive, and verify a signature commit reaches `main` with the App's identity. Signing checks must fail visibly when storage rejects a write.

The repository-specific workflow changes require a PR merge before `pull_request_target` and `issue_comment` use them. A workflow PR runs the current default-branch CLA workflow until it merges.

## Upstream updates

The `Check upstream` workflow is scheduled daily at 10:17 UTC and supports manual runs. It verifies that the parent fork is `iainmcgin/cla-github-action` and compares both default branches (currently `master`). Commits already present in our history need no alert; missing upstream commits open an issue with the upstream tip and a comparison link.

GitHub Issues must be enabled. Each upstream tip gets at most one bot-created issue, including closed issues, so closing an alert acknowledges that tip. Later upstream tips get new issues. The workflow uses the ordinary Actions token with Contents read and Issues write permissions; it does not use the signature App or its private key. API errors fail the workflow visibly.

Alerts compare the full upstream history with this fork; cherry-picked or deliberately declined commits can appear again in later comparison ranges. Keep the bot's hidden marker in each issue body to preserve deduplication.

The schedule becomes available after the workflow reaches the default branch. Run `Check upstream` manually after merging and confirm the comparison result in Actions. GitHub [disables public-repository schedules after 60 days without repository activity](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule). If the fork has been idle, check the workflow's state in Actions and re-enable it before relying on scheduled alerts.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test": "jest",
"build": "tsc && ncc build lib/main.js",
"buildAndAdd": "npm run build && git add .",
"format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\"",
"format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\"",
"format": "prettier --write \"src/**/*.ts\" \"__tests__/**/*.ts\" \".github/scripts/**/*.cjs\"",
"format:check": "prettier --check \"src/**/*.ts\" \"__tests__/**/*.ts\" \".github/scripts/**/*.cjs\"",
"lint:knip": "knip",
"lint:publint": "publint",
"lint": "npm run format:check && npm run lint:knip && npm run lint:publint",
Expand Down
Loading