From 06b574851d25eaab83f74c1174d7de9bcaae228a Mon Sep 17 00:00:00 2001 From: Naveen Kumar Date: Mon, 21 Sep 2026 13:46:59 +0800 Subject: [PATCH 1/3] ci: standardize secure cost-conscious automation --- .github/AUTOMATION.md | 7 +++++++ .github/dependabot.yml | 12 ++++++++++++ .github/workflows/ci.yml | 42 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 .github/AUTOMATION.md create mode 100644 .github/dependabot.yml diff --git a/.github/AUTOMATION.md b/.github/AUTOMATION.md new file mode 100644 index 0000000..d810e52 --- /dev/null +++ b/.github/AUTOMATION.md @@ -0,0 +1,7 @@ +# Repository automation + +All code changes go through pull requests. Draft PRs skip expensive CI; mark a PR ready to validate its latest revision. Superseded PR runs cancel. Documentation-only changes skip product checks; no paid runner waits or duplicate main-branch validation. + +Prepare a release by opening a PR with the version bump and release notes. A manual merge or an explicit instruction to a local agent to release authorizes publication after all required checks pass. “Prepare a release” stops at the PR. Never bypass checks or automatically merge dependency or release PRs. Repositories without a publishing destination do not need artificial releases. + +Routine dependencies are grouped weekly; security updates remain immediate. Production schedules and existing external publishing approval gates remain in force. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4934bf1 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directories: ["/"] + schedule: + interval: weekly + day: monday + open-pull-requests-limit: 1 + groups: + routine: + applies-to: version-updates + patterns: ["*"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd7bcd4..ab82cc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,49 @@ name: CI on: - push: - branches: [main] + workflow_dispatch: pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: + changes: + if: github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false + runs-on: ubuntu-latest + timeout-minutes: 3 + outputs: + relevant: ${{ steps.paths.outputs.relevant }} + steps: + - id: paths + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then + echo 'relevant=true' >> "$GITHUB_OUTPUT" + exit 0 + fi + gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files" --jq '.[].filename' > paths.txt + if grep -Ev '^(docs/|README[^/]*\.md$|CHANGELOG[^/]*\.md$|LICENSE[^/]*$|\.github/AUTOMATION\.md$)' paths.txt | grep -q .; then + echo 'relevant=true' >> "$GITHUB_OUTPUT" + else + echo 'relevant=false' >> "$GITHUB_OUTPUT" + fi + check: + if: ((github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false)) && needs.changes.outputs.relevant == 'true' + needs: changes runs-on: ubuntu-latest + timeout-minutes: 20 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - name: Manifest is in sync with the repo run: python3 scripts/build-catalog.py --check @@ -47,7 +81,7 @@ jobs: fi echo "no SDK imports" - - uses: ludeeus/action-shellcheck@master + - uses: ludeeus/action-shellcheck@00b27aa7cb85167568cb48a3838b75f4265f2bca # master with: severity: warning format: gcc From 1fee478fb0ff8e244535e225686fdc3a340cc64a Mon Sep 17 00:00:00 2001 From: Naveen Kumar Date: Mon, 21 Sep 2026 14:15:51 +0800 Subject: [PATCH 2/3] ci: enforce reviewed releases and minimal required validation --- .github/dependabot.yml | 15 ++++++++------- .github/workflows/ci.yml | 41 ++++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4934bf1..1b5d9e3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,12 +1,13 @@ version: 2 updates: - - package-ecosystem: github-actions - directories: ["/"] +- package-ecosystem: github-actions + directories: + - / + patterns: + - '*' + multi-ecosystem-group: routine +multi-ecosystem-groups: + routine: schedule: interval: weekly day: monday - open-pull-requests-limit: 1 - groups: - routine: - applies-to: version-updates - patterns: ["*"] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab82cc2..90debd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,18 +24,27 @@ jobs: - id: paths env: GH_TOKEN: ${{ github.token }} + EXPECTED_HEAD: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | if [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then echo 'relevant=true' >> "$GITHUB_OUTPUT" exit 0 fi - gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files" --jq '.[].filename' > paths.txt - if grep -Ev '^(docs/|README[^/]*\.md$|CHANGELOG[^/]*\.md$|LICENSE[^/]*$|\.github/AUTOMATION\.md$)' paths.txt | grep -q .; then - echo 'relevant=true' >> "$GITHUB_OUTPUT" - else - echo 'relevant=false' >> "$GITHUB_OUTPUT" - fi + gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" > pr.json + gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files?per_page=100" > files.json + python3 - <<'PYTHON' + import json, os, re + pr = json.load(open('pr.json')) + files = [f for page in json.load(open('files.json')) for f in page] + complete = 0 < len(files) == pr['changed_files'] < 3000 + same_head = pr['head']['sha'] == os.environ['EXPECTED_HEAD'] + docs = re.compile(r'^(docs/|README[^/]*\.md$|CHANGELOG[^/]*\.md$|LICENSE[^/]*$|\.github/AUTOMATION\.md$)') + paths = [path for f in files for path in (f['filename'], f.get('previous_filename', f['filename']))] + relevant = not (complete and same_head and all(docs.search(path) for path in paths)) + with open(os.environ['GITHUB_OUTPUT'], 'a') as output: + output.write(f'relevant={str(relevant).lower()}\n') + PYTHON check: if: ((github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false)) && needs.changes.outputs.relevant == 'true' @@ -128,3 +137,23 @@ jobs: if find . -path ./.git -prune -o \( -name '*.py' -o -name '*.ts' -o -name '*.swift' \) -not -path './scripts/*' -perm -u+x -print | grep .; then echo "::error::plugins must ship non-executable"; exit 1 fi + + required: + name: Required CI + if: always() && (github.event_name == 'workflow_dispatch' || github.event.pull_request.draft == false) + needs: ["changes", "check"] + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - env: + NEEDS: ${{ toJSON(needs) }} + run: | + python3 - <<'PYTHON' + import json, os + jobs = json.loads(os.environ['NEEDS']) + assert jobs['changes']['result'] == 'success', 'Path detection failed' + relevant = jobs.pop('changes')['outputs']['relevant'] + assert relevant in ('true', 'false') + expected = 'success' if relevant == 'true' else 'skipped' + assert all(job['result'] == expected for job in jobs.values()), jobs + PYTHON From 1bbca8de2a97b6319e2ec666f221eb368eed40d2 Mon Sep 17 00:00:00 2001 From: Naveen Kumar Date: Mon, 21 Sep 2026 14:24:55 +0800 Subject: [PATCH 3/3] fix: bind CI and releases to reviewed immutable revisions --- .github/workflows/ci.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90debd0..b581796 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,8 @@ jobs: - id: paths env: GH_TOKEN: ${{ github.token }} + EXPECTED_BASE: ${{ github.event.pull_request.base.sha }} + EXPECTED_BASE_REF: ${{ github.event.pull_request.base.ref }} EXPECTED_HEAD: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | @@ -33,15 +35,20 @@ jobs: fi gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" > pr.json gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files?per_page=100" > files.json + gh api "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER" > pr-after.json python3 - <<'PYTHON' import json, os, re pr = json.load(open('pr.json')) + after = json.load(open('pr-after.json')) files = [f for page in json.load(open('files.json')) for f in page] complete = 0 < len(files) == pr['changed_files'] < 3000 - same_head = pr['head']['sha'] == os.environ['EXPECTED_HEAD'] + stable = all(p['head']['sha'] == os.environ['EXPECTED_HEAD'] + and p['base']['sha'] == os.environ['EXPECTED_BASE'] + and p['base']['ref'] == os.environ['EXPECTED_BASE_REF'] + and p['changed_files'] == pr['changed_files'] for p in (pr, after)) docs = re.compile(r'^(docs/|README[^/]*\.md$|CHANGELOG[^/]*\.md$|LICENSE[^/]*$|\.github/AUTOMATION\.md$)') paths = [path for f in files for path in (f['filename'], f.get('previous_filename', f['filename']))] - relevant = not (complete and same_head and all(docs.search(path) for path in paths)) + relevant = not (complete and stable and all(docs.search(path) for path in paths)) with open(os.environ['GITHUB_OUTPUT'], 'a') as output: output.write(f'relevant={str(relevant).lower()}\n') PYTHON