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
1 change: 1 addition & 0 deletions .github/workflows/auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
github.event.pull_request.user.login == 'devstreamhq-bot[bot]' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
pull-requests: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/cflite_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ permissions: {}
jobs:
PR:
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
concurrency:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
# analyze (javascript-typescript) and analyze (actions).
analyze:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
actions: read
contents: read
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
build:
if: github.event_name != 'workflow_run' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'main')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
env:
Expand Down Expand Up @@ -69,6 +70,7 @@ jobs:
deploy:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/likes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ concurrency:
jobs:
likes:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ concurrency:
jobs:
discussions:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ permissions: {}
jobs:
validate:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand All @@ -25,6 +26,7 @@ jobs:

test:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand All @@ -41,6 +43,7 @@ jobs:

lint:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ permissions: {}
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
id-token: write
Expand Down
34 changes: 30 additions & 4 deletions .github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
github.event.issue.user.type != 'Bot' &&
github.event.issue.user.login != 'devstreamhq-bot[bot]')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
outputs:
Expand Down Expand Up @@ -96,6 +97,7 @@ jobs:
group: list-writes
cancel-in-progress: false
runs-on: ubuntu-latest
timeout-minutes: 35
permissions:
contents: read
steps:
Expand Down Expand Up @@ -188,23 +190,47 @@ jobs:
[ "$(gh pr view "$PR_URL" --json state --jq .state)" = MERGED ] && exit 0
echo "::error::$PR_URL did not merge within 15 minutes and is now closed"
exit 1
# Minted after the merge wait, so no later step runs on a token that expired during it.
- id: late_token
if: always() && steps.pr.outputs.url != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- id: late_issues_token
if: always() && steps.issues_token.outputs.token != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-issues: write
# Only now is "hidden" true, so the comment waits for the merge.
- env:
GITHUB_TOKEN: ${{ steps.issues_token.outputs.token }}
GITHUB_TOKEN: ${{ steps.late_issues_token.outputs.token || steps.issues_token.outputs.token }}
RESULT: ${{ runner.temp }}/result/result.json
run: python -m scripts.reports issue --result "$RESULT"
# A genuine failure (apply error, push, PR, merge timeout) is parked for a maintainer:
# A cancel or job timeout releases the lock, so the armed PR must not merge behind the next writer.
# Timeouts reach this step too: the runner re-evaluates later steps' if: on any job cancellation.
- if: cancelled() && steps.pr.outputs.url != ''
env:
GH_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
PR_URL: ${{ steps.pr.outputs.url }}
run: gh pr close "$PR_URL" || true # fails if it merged meanwhile
# A genuine failure (apply error, push, PR, merge timeout, cancel) is parked for a maintainer:
# needs-review stops the sweeper retrying it. The issue stays open.
- if: failure() && steps.issues_token.outputs.token != '' && steps.meta.outputs.issue != ''
- if: (failure() || cancelled()) && steps.issues_token.outputs.token != '' && steps.meta.outputs.issue != ''
env:
GITHUB_TOKEN: ${{ steps.issues_token.outputs.token }}
GITHUB_TOKEN: ${{ steps.late_issues_token.outputs.token || steps.issues_token.outputs.token }}
RESULT: ${{ runner.temp }}/result/result.json
run: python -m scripts.reports issue --result "$RESULT" --error

respond:
needs: decide
if: needs.decide.outputs.has == 'true' && needs.decide.outputs.hide != 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand Down
22 changes: 20 additions & 2 deletions .github/workflows/rot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ concurrency:
jobs:
rot:
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: read
steps:
Expand Down Expand Up @@ -88,12 +89,29 @@ jobs:
[ "$(gh pr view "$PR_URL" --json state --jq .state)" = MERGED ] && exit 0
echo "::error::$PR_URL did not merge within 15 minutes and is now closed"
exit 1
# Minted after the merge wait, so no later step runs on a token that expired during it.
- id: late_token
if: always() && steps.pr.outputs.url != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
permission-discussions: write
- if: steps.plan.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
GITHUB_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
run: python -m scripts.rot finish --plan "$RUNNER_TEMP/plan.json"
# Only after finish has moved a renamed entry's thread to its new key, or this would open a second one.
- if: steps.plan.outputs.changed == 'true'
env:
GITHUB_TOKEN: ${{ steps.token.outputs.token }}
GITHUB_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
run: python -m scripts.on_merge
# A cancel or job timeout releases the lock, so the armed PR must not merge behind the next writer.
# Timeouts reach this step too: the runner re-evaluates later steps' if: on any job cancellation.
- if: cancelled() && steps.pr.outputs.url != ''
env:
GH_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
PR_URL: ${{ steps.pr.outputs.url }}
run: gh pr close "$PR_URL" || true # fails if it merged meanwhile
1 change: 1 addition & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
# containers, and only its approved actions as steps.
analysis:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
# Upload the results to code scanning.
security-events: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/stars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions: {}
jobs:
stars:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand Down
36 changes: 31 additions & 5 deletions .github/workflows/submit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
decide:
if: github.event_name == 'workflow_dispatch' || contains(github.event.issue.labels.*.name, 'submission')
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
outputs:
Expand Down Expand Up @@ -71,6 +72,7 @@ jobs:
needs: decide
if: needs.decide.outputs.ok == 'true'
runs-on: ubuntu-latest
timeout-minutes: 35
permissions:
contents: read
steps:
Expand Down Expand Up @@ -162,9 +164,25 @@ jobs:
[ "$(gh pr view "$PR_URL" --json state --jq .state)" = MERGED ] && exit 0
echo "::error::$PR_URL did not merge within 15 minutes and is now closed"
exit 1
# Minted after the merge wait, so no later step runs on a token that expired during it.
- id: late_token
if: always() && steps.pr.outputs.url != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-contents: write
permission-pull-requests: write
- id: late_issues_token
if: always() && steps.issues_token.outputs.token != ''
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
permission-issues: write
- if: steps.apply.outputs.branch != ''
env:
GH_TOKEN: ${{ steps.issues_token.outputs.token }}
GH_TOKEN: ${{ steps.late_issues_token.outputs.token || steps.issues_token.outputs.token }}
RESULT: ${{ runner.temp }}/result/result.json
ISSUE: ${{ steps.meta.outputs.issue }}
run: |
Expand All @@ -189,19 +207,26 @@ jobs:
run: python -m scripts.on_merge
- if: steps.apply.outputs.branch == ''
env:
GH_TOKEN: ${{ steps.issues_token.outputs.token }}
GH_TOKEN: ${{ steps.late_issues_token.outputs.token || steps.issues_token.outputs.token }}
RESULT: ${{ runner.temp }}/result/result.json
ISSUE: ${{ steps.meta.outputs.issue }}
run: |
python -m scripts.submit comment --result "$RESULT" --kind rejected > "$RUNNER_TEMP/comment.md"
gh issue comment "$ISSUE" --body-file "$RUNNER_TEMP/comment.md"
gh issue edit "$ISSUE" --add-label rejected
gh issue close "$ISSUE" --reason "not planned"
# A genuine failure (apply error, push, PR, merge timeout) is parked for a human:
# A cancel or job timeout releases the lock, so the armed PR must not merge behind the next writer.
# Timeouts reach this step too: the runner re-evaluates later steps' if: on any job cancellation.
- if: cancelled() && steps.pr.outputs.url != ''
env:
GH_TOKEN: ${{ steps.late_token.outputs.token || steps.token.outputs.token }}
PR_URL: ${{ steps.pr.outputs.url }}
run: gh pr close "$PR_URL" || true # fails if it merged meanwhile
# A genuine failure (apply error, push, PR, merge timeout, cancel) is parked for a human:
# the sweeper skips needs-review, so it can't retry forever. The issue stays open.
- if: failure() && steps.issues_token.outputs.token != '' && steps.meta.outputs.issue != ''
- if: (failure() || cancelled()) && steps.issues_token.outputs.token != '' && steps.meta.outputs.issue != ''
env:
GH_TOKEN: ${{ steps.issues_token.outputs.token }}
GH_TOKEN: ${{ steps.late_issues_token.outputs.token || steps.issues_token.outputs.token }}
RESULT: ${{ runner.temp }}/result/result.json
ISSUE: ${{ steps.meta.outputs.issue }}
run: |
Expand All @@ -213,6 +238,7 @@ jobs:
needs: decide
if: needs.decide.outputs.ok == 'false'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/sweep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ concurrency:
jobs:
sweep:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
Expand Down
42 changes: 37 additions & 5 deletions scripts/devstream/gh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import random
import re
import socket
import time
import urllib.error
import urllib.parse
Expand All @@ -9,6 +11,9 @@
MAX_SLEEP = 600
MAX_HOPS = 5
TIMEOUT = 30
ATTEMPTS = 3
TRANSIENT = (502, 503, 504)
NETWORK = (urllib.error.URLError, TimeoutError, ConnectionError)


class GitHubError(Exception):
Expand Down Expand Up @@ -69,14 +74,40 @@ def _rate_limit_reset(status, headers) -> int | None:
return int(time.time()) + int(retry)
return int(headers.get("x-ratelimit-reset") or time.time() + 60)

def _request(self, method, path, params=None, body=None):
@staticmethod
def _retryable(method, read, status=None, exc=None) -> bool:
"""read: a GET or a GraphQL query. PUT, PATCH and DELETE give the same result twice (contents PUTs are sha-guarded)."""
if exc is None:
return (method != "POST" or read) and (status in TRANSIENT or (read and status == 500))
if read:
return True
# Anything else may have reached GitHub; a POST or mutation sent twice duplicates an issue, thread or comment.
return isinstance(getattr(exc, "reason", None), (ConnectionRefusedError, socket.gaierror))

def _backoff(self, fails):
self.sleep(2 ** (fails - 1) * (1 + random.random() / 2))

def _request(self, method, path, params=None, body=None, read=None):
"""Return (headers, parsed json) or None on 404."""
read = method == "GET" if read is None else read
if params:
path += ("&" if "?" in path else "?") + urllib.parse.urlencode(params)
retried = False
hops = 0
fails = 0
while True:
status, headers, raw = self._send(method, self.base + path, body)
try:
status, headers, raw = self._send(method, self.base + path, body)
except NETWORK as e:
fails += 1
if fails >= ATTEMPTS or not self._retryable(method, read, exc=e):
raise
self._backoff(fails)
continue
if self._retryable(method, read, status) and fails + 1 < ATTEMPTS:
fails += 1
self._backoff(fails)
continue
reset = self._rate_limit_reset(status, headers)
if reset is not None:
if reset - time.time() > MAX_SLEEP or retried:
Expand Down Expand Up @@ -147,13 +178,14 @@ def patch(self, path, body):
def put(self, path, body):
return self._write("PUT", path, body)

def delete(self, path):
return self._write("DELETE", path, None)
def delete(self, path, body=None):
return self._write("DELETE", path, body)

def graphql(self, query: str, variables: dict, allow_not_found: bool = False) -> dict:
"""allow_not_found returns data with nulls where only NOT_FOUND errors occurred."""
self.last_redirect = None
r = self._request("POST", "/graphql", body={"query": query, "variables": variables})
r = self._request("POST", "/graphql", body={"query": query, "variables": variables},
read=not query.lstrip().startswith("mutation"))
if r is None:
raise GitHubError(404, "graphql endpoint not found")
out = r[1] or {}
Expand Down
Loading
Loading