keep-github-workflows-active 2.3.6__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/CHANGELOG.md +41 -5
  2. keep_github_workflows_active-3.0.0/PKG-INFO +280 -0
  3. keep_github_workflows_active-3.0.0/README.md +239 -0
  4. keep_github_workflows_active-3.0.0/docs/systemdesign/SECURITY.md +228 -0
  5. keep_github_workflows_active-3.0.0/docs/systemdesign/module_reference.md +249 -0
  6. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/pyproject.toml +22 -19
  7. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/__init__conf__.py +5 -5
  8. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/behaviors.py +17 -19
  9. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/cli.py +34 -22
  10. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/keep_github_workflow_active.py +222 -105
  11. keep_github_workflows_active-3.0.0/tests/test_github_api.py +235 -0
  12. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_github_integration.py +31 -32
  13. keep_github_workflows_active-2.3.6/PKG-INFO +0 -241
  14. keep_github_workflows_active-2.3.6/README.md +0 -201
  15. keep_github_workflows_active-2.3.6/docs/systemdesign/SECURITY.md +0 -303
  16. keep_github_workflows_active-2.3.6/docs/systemdesign/module_reference.md +0 -265
  17. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/.gitignore +0 -0
  18. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/LICENSE +0 -0
  19. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/__init__.py +0 -0
  20. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/__main__.py +0 -0
  21. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/doctest.env +0 -0
  22. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/py.typed +0 -0
  23. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/sanitization.py +0 -0
  24. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/src/keep_github_workflows_active/typed_click.py +0 -0
  25. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/conftest.py +0 -0
  26. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_behaviors.py +0 -0
  27. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_cli.py +0 -0
  28. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_metadata.py +0 -0
  29. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_module_entry.py +0 -0
  30. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_packaging.py +0 -0
  31. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_platform_markers.py +0 -0
  32. {keep_github_workflows_active-2.3.6 → keep_github_workflows_active-3.0.0}/tests/test_sanitization.py +0 -0
@@ -2,7 +2,43 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [2.3.6] 2026-10-15 16:35:48
5
+ ## [3.0.0] - 2026-11-27
6
+
7
+ ### Changed
8
+
9
+ - Runtime dependency floors raised: `lib_cli_exit_tools >=2.4.1 -> >=2.5.0`,
10
+ `pydantic >=2.14.1 -> >=2.14.4`.
11
+ - Supported platform is now Python 3.15 on Linux only: `requires-python = ">=3.15"`, the
12
+ classifiers name 3.15 and `Operating System :: POSIX :: Linux`, and CI runs `ubuntu-latest`
13
+ on 3.15 only (the "Activate Workflows" jobs no longer float on `3.x` or pin 3.13). The
14
+ scheduled run failed because `requires-python` still admitted 3.10 while the classifiers began
15
+ at 3.14: bmk raised the `import-linter` floor to 2.17, and `uv lock` could not resolve it for
16
+ 3.10, where 2.16 and later do not install.
17
+ - `enable-all-workflows` and `delete-old-workflow-runs` reuse one HTTPS connection per run through
18
+ a `requests.Session` (`github_session()`), instead of opening a new one for every API call
19
+ (measured against api.github.com: 128 ms per call before, 45 ms after). The listing, enable and
20
+ delete functions now take that `session` in place of `github_token`; the two entry points keep
21
+ their `owner` / `github_token` parameters.
22
+ - The skipped workflow types are one read-only table, `SKIPPED_WORKFLOWS`, holding each
23
+ `SkippedWorkflowType`'s file name prefix and skip reason; it replaces the
24
+ `SKIPPED_WORKFLOW_PREFIXES` dict and the per-type `if`/`elif` of reasons, under which a type
25
+ added without its reason branch had its workflows enabled anyway. A type without a row now fails
26
+ the test suite. The skip messages are unchanged.
27
+
28
+ ### Fixed
29
+
30
+ - A GitHub reply missing a field the tool acts on now stops the run with
31
+ `Unexpected GitHub reply for <what>: <field path>: <reason>` (or "the body is not JSON"). The
32
+ reply models used to default those fields, so a run without `id` was read as run `0` (and
33
+ `delete-old-workflow-runs` would have sent `DELETE .../actions/runs/0`), a repository without
34
+ `name` as `''`, and a reply that was not a listing at all as an empty one, reporting
35
+ "Found 0" and exiting 0.
36
+ - `notebooks/Quickstart.ipynb` installs the checkout it runs in, so CI's "Execute notebooks" job
37
+ tests the commit under test. It used to install `git+https://github.com/...` every time, which is
38
+ the pushed default branch, so a pull request's notebook run tested the code already there.
39
+ Outside a checkout (a downloaded notebook) it still installs from GitHub.
40
+
41
+ ## [2.3.6] - 2026-10-15
6
42
 
7
43
  ### Fixed
8
44
 
@@ -23,7 +59,7 @@
23
59
  (`pytest_runtest_setup` in `tests/conftest.py`); registered in `pyproject.toml` alone they skipped
24
60
  nothing, so a test trusting its marker ran everywhere. `tests/test_platform_markers.py` pins it.
25
61
 
26
- ## [2.3.5] 2026-10-12 22:50:01
62
+ ## [2.3.5] - 2026-10-12
27
63
 
28
64
  ### Added
29
65
  - Python 3.15 is a supported version: declared in the classifiers, so CI and `make test-all` run it.
@@ -36,7 +72,7 @@
36
72
  a plain `pip install` from PyPI does not.
37
73
  - `rtoml` floor raised to 0.14.0, the first release with Python 3.15 wheels.
38
74
 
39
- ## [2.3.4] 2026-10-05 19:35:58
75
+ ## [2.3.4] - 2026-10-05
40
76
 
41
77
  ### Fixed
42
78
  - `python -m keep_github_workflows_active` now runs `cli.main()` like the console scripts; a usage error (bad flag, unknown command) exits 2 instead of 1.
@@ -44,7 +80,7 @@
44
80
  ### Changed
45
81
  - Raised dependency and dev tool floors to their current releases.
46
82
 
47
- ## [2.3.3] 2026-07-24
83
+ ## [2.3.3] - 2026-07-24
48
84
 
49
85
  ### Changed
50
86
  - Added the curated bitranox `[tool.ruff.lint].select` (pycodestyle/pyflakes/isort/bugbear/pylint/bandit/etc.) plus a Pydantic `flake8-type-checking.runtime-evaluated-base-classes` entry; ruff 0.16's ~920-rule default (no explicit `select`) was about to reflood CI with unrelated rule families.
@@ -56,7 +92,7 @@
56
92
  ### Fixed
57
93
  - CI: `make test` was red under the latest `ruff` (0.16 default rule explosion on a no-`select` repo); the fixes above make it pass again.
58
94
 
59
- ## [2.3.2] 2026-06-14
95
+ ## [2.3.2] - 2026-06-14
60
96
 
61
97
  ### Changed
62
98
  - Added a `typed_click.py` facade wrapping rich-click's `option` / `version_option` decorators behind explicit, fully-known signatures, keeping the CLI strict-clean under pyright 1.1.410 (`reportUnknownMemberType`) without disabling the rule (ignore isolated to the facade).
@@ -0,0 +1,280 @@
1
+ Metadata-Version: 2.5
2
+ Name: keep_github_workflows_active
3
+ Version: 3.0.0
4
+ Summary: Keep the GitHub Actions workflows of a user's or organisation's repositories enabled and delete their old workflow runs
5
+ Project-URL: Homepage, https://github.com/bitranox/keep_github_workflows_active
6
+ Project-URL: Repository, https://github.com/bitranox/keep_github_workflows_active.git
7
+ Project-URL: Issues, https://github.com/bitranox/keep_github_workflows_active/issues
8
+ Author-email: bitranox <bitranox@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: automation,cli,github,github-actions,workflows
12
+ Classifier: Environment :: Console
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.15
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.15
20
+ Requires-Dist: lib-cli-exit-tools>=2.5.0
21
+ Requires-Dist: pydantic>=2.14.4
22
+ Requires-Dist: requests>=2.34.2
23
+ Requires-Dist: rich-click>=1.9.9
24
+ Provides-Extra: dev
25
+ Requires-Dist: bandit>=1.9.4; extra == 'dev'
26
+ Requires-Dist: build>=1.6.1; extra == 'dev'
27
+ Requires-Dist: certifi>=2026.10.23; extra == 'dev'
28
+ Requires-Dist: click>=8.5.1; extra == 'dev'
29
+ Requires-Dist: hatchling>=1.33.0; extra == 'dev'
30
+ Requires-Dist: import-linter>=2.17; extra == 'dev'
31
+ Requires-Dist: pip-audit>=2.10.1; extra == 'dev'
32
+ Requires-Dist: pyright[nodejs]>=1.1.414; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=7.1.0; extra == 'dev'
34
+ Requires-Dist: pytest-xdist>=3.8.0; extra == 'dev'
35
+ Requires-Dist: pytest>=9.2.0; extra == 'dev'
36
+ Requires-Dist: rtoml>=0.14.0; extra == 'dev'
37
+ Requires-Dist: ruff>=0.17.6; extra == 'dev'
38
+ Requires-Dist: textual>=8.2.8; extra == 'dev'
39
+ Requires-Dist: twine>=7.0.0; extra == 'dev'
40
+ Description-Content-Type: text/markdown
41
+
42
+ # keep_github_workflows_active
43
+
44
+ <!-- Badges -->
45
+ [![CI](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/default_cicd_public.yml/badge.svg)](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/default_cicd_public.yml)
46
+ [![CodeQL](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/codeql.yml/badge.svg)](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/codeql.yml)
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
48
+ [![Open in Codespaces](https://img.shields.io/badge/Codespaces-Open-blue?logo=github&logoColor=white&style=flat-square)](https://codespaces.new/bitranox/keep_github_workflows_active?quickstart=1)
49
+ [![PyPI](https://img.shields.io/pypi/v/keep_github_workflows_active.svg)](https://pypi.org/project/keep_github_workflows_active/)
50
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/keep_github_workflows_active.svg)](https://pypi.org/project/keep_github_workflows_active/)
51
+ [![Code Style: Ruff](https://img.shields.io/badge/Code%20Style-Ruff-46A3FF?logo=ruff&labelColor=000)](https://docs.astral.sh/ruff/)
52
+ [![codecov](https://codecov.io/gh/bitranox/keep_github_workflows_active/graph/badge.svg?token=UFBaUDIgRk)](https://codecov.io/gh/bitranox/keep_github_workflows_active)
53
+ [![Maintainability](https://qlty.sh/badges/041ba2c1-37d6-40bb-85a0-ec5a8a0aca0c/maintainability.svg)](https://qlty.sh/gh/bitranox/projects/keep_github_workflows_active)
54
+ [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
55
+
56
+ > **CI cadence:** the `CI` workflow runs on every push and pull request to `main`/`master` and
57
+ > daily at 03:17 UTC; `CodeQL` runs on push, pull request and Mondays at 08:00 UTC.
58
+
59
+
60
+ ## Overview
61
+
62
+ `keep_github_workflows_active` keeps the GitHub Actions workflows of an owner's repositories
63
+ enabled and prunes their old workflow runs. GitHub disables scheduled workflows in repositories
64
+ without recent activity (per GitHub's Actions docs); running this tool on a schedule re-enables
65
+ them.
66
+
67
+ It has two jobs, one CLI command each:
68
+
69
+ 1. **`enable-all-workflows`** - for every repository of the owner, send the "enable workflow"
70
+ request for each of its workflow files. Workflow files whose names start with
71
+ `pages-build-deployment` (cannot be enabled), `dependabot` (managed by Dependabot) or
72
+ `update-graph` (managed by the dependency graph) are skipped.
73
+ 2. **`delete-old-workflow-runs`** - for every repository of the owner, keep the newest runs (the
74
+ highest run ids across all of the repository's workflows; 50 by default, `--keep` to change)
75
+ and delete the rest.
76
+
77
+ Repositories are listed from `/orgs/<owner>/repos`; when GitHub answers 404 (the owner is not an
78
+ organisation), from `/users/<owner>/repos` instead. Per GitHub's REST docs, the user endpoint
79
+ lists the user's public repositories.
80
+
81
+ This repository runs both commands from `.github/workflows/activate_workflows.yml`, whose
82
+ `activate` job runs only on the weekly schedule (Fridays at 03:47 UTC); push and pull request
83
+ runs of that workflow only run the tests.
84
+
85
+
86
+ ## Prerequisites
87
+
88
+ ### Generate an access token
89
+
90
+ The commands authenticate with a personal access token, sent as `Authorization: Bearer <token>`.
91
+ You can create one on the GitHub settings page:
92
+
93
+ - [Personal access tokens](https://github.com/settings/personal-access-tokens)
94
+
95
+ Give the token the permissions GitHub's REST docs list for the endpoints the tool calls:
96
+
97
+ | Endpoint | Used by |
98
+ |-------------------------------------------------------------|----------------------------|
99
+ | `GET /orgs/<owner>/repos`, then `GET /users/<owner>/repos` | both commands |
100
+ | `GET /repos/<owner>/<repo>/actions/workflows` | `enable-all-workflows` |
101
+ | `PUT /repos/<owner>/<repo>/actions/workflows/<file>/enable` | `enable-all-workflows` |
102
+ | `GET /repos/<owner>/<repo>/actions/runs` | `delete-old-workflow-runs` |
103
+ | `DELETE /repos/<owner>/<repo>/actions/runs/<run_id>` | `delete-old-workflow-runs` |
104
+
105
+ Tokens can expire; renew yours before its expiry date to keep the scheduled runs working.
106
+
107
+ ### Store the token as a repository secret
108
+
109
+ Add the token to the repository's secrets so GitHub Actions can inject it at
110
+ runtime:
111
+
112
+ - [Repository secrets](https://github.com/bitranox/keep_github_workflows_active/settings/secrets/actions)
113
+
114
+ Define the following secrets:
115
+
116
+ - `SECRET_GITHUB_OWNER` - the user or organisation whose repositories should be scanned.
117
+ - `SECRET_GITHUB_TOKEN` - the personal access token you generated.
118
+
119
+ ### Where the commands look for the owner and token
120
+
121
+ `--owner` and `--token` on the command line win. Without them, each value is looked up in this
122
+ order, and the first non-empty value is used:
123
+
124
+ 1. the environment variable (`SECRET_GITHUB_OWNER` / `SECRET_GITHUB_TOKEN`);
125
+ 2. the file named by `KEEP_GITHUB_WORKFLOWS_ACTIVE_DOTENV_PATH`, if that variable is set;
126
+ 3. `.env` in the current working directory;
127
+ 4. `.env` in the installed package directory;
128
+ 5. `.env` two levels above the package directory (the repository root when running from a
129
+ source checkout or an editable install).
130
+
131
+ A `.env` file holds `KEY=value` lines; blank lines and lines starting with `#` are skipped, and
132
+ surrounding quotes are removed from the value. When no value is found the command stops with
133
+ `Missing required configuration: SECRET_GITHUB_OWNER` (or `..._TOKEN`).
134
+
135
+ ### Which tests call the live GitHub API
136
+
137
+ `make test` and CI never call the live API: the tests that do are marked `integration` and
138
+ `local_only` (`tests/test_github_integration.py`), which `make test` excludes, and they skip
139
+ whenever the `CI` environment variable is set. `make testintegration` runs them locally against
140
+ the configured account; they list repositories, workflows and runs and call
141
+ `enable_all_workflows` and `enable_workflow`, which re-enable that account's workflows. No test
142
+ deletes workflow runs.
143
+
144
+
145
+ ## Installation
146
+
147
+ Install the package from PyPI:
148
+
149
+ ```bash
150
+ pip install keep_github_workflows_active
151
+ ```
152
+
153
+ Installing from a checkout, from a built wheel, with pipx or with uv is described in
154
+ [INSTALL.md](INSTALL.md). Every install puts two console scripts on your `PATH`,
155
+ `keep_github_workflows_active` and `keep-github-workflows-active`, which run the same CLI.
156
+
157
+ ### Supported platform: Python 3.15 on Linux
158
+
159
+ - The package requires **Python 3.15 or newer** (`requires-python = ">=3.15"`)
160
+ and is built and tested for **Linux** only.
161
+ - Continuous integration runs on GitHub's `ubuntu-latest` runner with CPython
162
+ 3.15; the CI matrix comes from the `Programming Language :: Python :: 3.15`
163
+ classifier and `[tool.ci].os` in `pyproject.toml`.
164
+ - Runtime dependencies: `rich-click` (CLI), `lib_cli_exit_tools` (exit codes and traceback
165
+ output), `requests` (GitHub API calls) and `pydantic` (parsing GitHub's replies).
166
+
167
+ ### Why we recommend uv: supply-chain protection
168
+
169
+ This repository commits a `uv.lock`. It pins every package the project needs, transitive
170
+ dependencies included, to an exact version and to the hashes of that version's files. The
171
+ `exclude-newer` setting under `[tool.uv]` in `pyproject.toml` adds a cooldown: uv leaves any
172
+ release younger than that out of the lock. CI installs from the lock, so a hijacked release that
173
+ gets pulled again within the cooldown never reaches our builds, and a file whose hash does not
174
+ match is refused.
175
+
176
+ That protection stays in this repository. The installable package declares only lower bounds
177
+ (`>=`) for its dependencies, so a plain `pip install` takes the newest release of every transitive
178
+ dependency at the moment you run it. If one of them was hijacked an hour earlier, you get the
179
+ hijacked version. `pipx install` and `uv tool install` without options do the same.
180
+
181
+ To install the command line tool with a cooldown of your own (uv then skips any release younger
182
+ than 7 days, transitive ones included), or to run the exact tree our CI tests:
183
+
184
+ ```bash
185
+ uv tool install --exclude-newer "7 days" keep_github_workflows_active
186
+ git clone https://github.com/bitranox/keep_github_workflows_active.git && cd keep_github_workflows_active && uv sync --locked && uv run keep_github_workflows_active --help
187
+ ```
188
+
189
+ If you depend on keep_github_workflows_active in your own project, give that project the same cooldown (7 days here, as
190
+ an example) and commit the `uv.lock` that `uv add keep_github_workflows_active` writes:
191
+
192
+ ```toml
193
+ [tool.uv]
194
+ exclude-newer = "7 days"
195
+ ```
196
+
197
+ ## Usage
198
+
199
+ Run the two maintenance commands from a scheduled GitHub Actions workflow, as
200
+ `.github/workflows/activate_workflows.yml` does, or by hand:
201
+
202
+ ```bash
203
+ keep-github-workflows-active enable-all-workflows [--owner <owner>] [--token <token>]
204
+ keep-github-workflows-active delete-old-workflow-runs [--owner <owner>] [--token <token>] [--keep <n>]
205
+ ```
206
+
207
+ | Option | Commands | Meaning |
208
+ |-----------|----------------------------|-------------------------------------------------------------------------|
209
+ | `--owner` | both | user or organisation; defaults to `SECRET_GITHUB_OWNER` (lookup above) |
210
+ | `--token` | both | personal access token; defaults to `SECRET_GITHUB_TOKEN` (lookup above) |
211
+ | `--keep` | `delete-old-workflow-runs` | runs to keep per repository, default `50` |
212
+
213
+ Each command opens one HTTPS session for the whole run and reuses its connection for every API
214
+ call. Lists are read 100 entries per page, following GitHub's pagination links.
215
+
216
+ A command stops with a non-zero exit code when:
217
+
218
+ - GitHub answers an error status while listing repositories, workflows or runs, or while enabling
219
+ a workflow (`ERROR reading ...` / `ERROR enabling ...`);
220
+ - a reply does not have the shape the tool acts on, for example a run without `id` or a listing
221
+ that is not a list (`Unexpected GitHub reply for <what>: <field>: <reason>`, or
222
+ `... the body is not JSON`);
223
+ - a delete request fails at the network level (`ERROR deleting workflow run ID ...`).
224
+
225
+ The other commands are diagnostics:
226
+
227
+ ```bash
228
+ keep-github-workflows-active --version
229
+ keep-github-workflows-active info # print package metadata
230
+ keep-github-workflows-active hello # print "Hello World"
231
+ keep-github-workflows-active fail # raise a RuntimeError (short error output)
232
+ keep-github-workflows-active --traceback fail # the same with the full traceback
233
+ python -m keep_github_workflows_active --help # same CLI as the console scripts
234
+ ```
235
+
236
+ Without a subcommand the CLI prints its help.
237
+
238
+ ### Python API
239
+
240
+ The functions behind the commands live in `keep_github_workflows_active.keep_github_workflow_active`:
241
+
242
+ ```python
243
+ from keep_github_workflows_active import keep_github_workflow_active as kgwa
244
+
245
+ token = kgwa.get_github_token() # same lookup as the CLI
246
+ kgwa.enable_all_workflows(owner="example-org", github_token=token)
247
+ kgwa.delete_old_workflow_runs(owner="example-org", github_token=token, number_of_workflow_runs_to_keep=50)
248
+
249
+ # The single-step functions take a session from github_session():
250
+ with kgwa.github_session(token) as session:
251
+ for repository in kgwa.get_repositories(owner="example-org", session=session):
252
+ run_ids = kgwa.get_workflow_runs(owner="example-org", repository=repository, session=session)
253
+ ```
254
+
255
+ The package root exports only the diagnostic helpers (`emit_greeting`,
256
+ `raise_intentional_failure`, `noop_main`, `print_info`, `CANONICAL_GREETING`).
257
+
258
+
259
+ ## Security
260
+
261
+ The token travels only in the `Authorization` header of the session that `github_session()`
262
+ builds; no log message contains it. Every log message of the GitHub module passes through
263
+ `sanitization.sanitize_message()`, which replaces token-like text with `[REDACTED]`:
264
+
265
+ - GitHub tokens (`ghp_...`, `gho_...`, `ghs_...` and the other `gh?_` prefixes)
266
+ - hexadecimal strings of 40 or more characters
267
+ - base64-like strings of 40 or more characters
268
+
269
+ For complete security documentation including incident response procedures, see
270
+ [SECURITY.md](docs/systemdesign/SECURITY.md).
271
+
272
+ ## Further documentation
273
+
274
+ - [Install Guide](INSTALL.md)
275
+ - [Development Handbook](DEVELOPMENT.md)
276
+ - [Contributor Guide](CONTRIBUTING.md)
277
+ - [Changelog](CHANGELOG.md)
278
+ - [Module Reference](docs/systemdesign/module_reference.md)
279
+ - [Security Documentation](docs/systemdesign/SECURITY.md)
280
+ - [License](LICENSE)
@@ -0,0 +1,239 @@
1
+ # keep_github_workflows_active
2
+
3
+ <!-- Badges -->
4
+ [![CI](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/default_cicd_public.yml/badge.svg)](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/default_cicd_public.yml)
5
+ [![CodeQL](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/codeql.yml/badge.svg)](https://github.com/bitranox/keep_github_workflows_active/actions/workflows/codeql.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+ [![Open in Codespaces](https://img.shields.io/badge/Codespaces-Open-blue?logo=github&logoColor=white&style=flat-square)](https://codespaces.new/bitranox/keep_github_workflows_active?quickstart=1)
8
+ [![PyPI](https://img.shields.io/pypi/v/keep_github_workflows_active.svg)](https://pypi.org/project/keep_github_workflows_active/)
9
+ [![PyPI - Downloads](https://img.shields.io/pypi/dm/keep_github_workflows_active.svg)](https://pypi.org/project/keep_github_workflows_active/)
10
+ [![Code Style: Ruff](https://img.shields.io/badge/Code%20Style-Ruff-46A3FF?logo=ruff&labelColor=000)](https://docs.astral.sh/ruff/)
11
+ [![codecov](https://codecov.io/gh/bitranox/keep_github_workflows_active/graph/badge.svg?token=UFBaUDIgRk)](https://codecov.io/gh/bitranox/keep_github_workflows_active)
12
+ [![Maintainability](https://qlty.sh/badges/041ba2c1-37d6-40bb-85a0-ec5a8a0aca0c/maintainability.svg)](https://qlty.sh/gh/bitranox/projects/keep_github_workflows_active)
13
+ [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
14
+
15
+ > **CI cadence:** the `CI` workflow runs on every push and pull request to `main`/`master` and
16
+ > daily at 03:17 UTC; `CodeQL` runs on push, pull request and Mondays at 08:00 UTC.
17
+
18
+
19
+ ## Overview
20
+
21
+ `keep_github_workflows_active` keeps the GitHub Actions workflows of an owner's repositories
22
+ enabled and prunes their old workflow runs. GitHub disables scheduled workflows in repositories
23
+ without recent activity (per GitHub's Actions docs); running this tool on a schedule re-enables
24
+ them.
25
+
26
+ It has two jobs, one CLI command each:
27
+
28
+ 1. **`enable-all-workflows`** - for every repository of the owner, send the "enable workflow"
29
+ request for each of its workflow files. Workflow files whose names start with
30
+ `pages-build-deployment` (cannot be enabled), `dependabot` (managed by Dependabot) or
31
+ `update-graph` (managed by the dependency graph) are skipped.
32
+ 2. **`delete-old-workflow-runs`** - for every repository of the owner, keep the newest runs (the
33
+ highest run ids across all of the repository's workflows; 50 by default, `--keep` to change)
34
+ and delete the rest.
35
+
36
+ Repositories are listed from `/orgs/<owner>/repos`; when GitHub answers 404 (the owner is not an
37
+ organisation), from `/users/<owner>/repos` instead. Per GitHub's REST docs, the user endpoint
38
+ lists the user's public repositories.
39
+
40
+ This repository runs both commands from `.github/workflows/activate_workflows.yml`, whose
41
+ `activate` job runs only on the weekly schedule (Fridays at 03:47 UTC); push and pull request
42
+ runs of that workflow only run the tests.
43
+
44
+
45
+ ## Prerequisites
46
+
47
+ ### Generate an access token
48
+
49
+ The commands authenticate with a personal access token, sent as `Authorization: Bearer <token>`.
50
+ You can create one on the GitHub settings page:
51
+
52
+ - [Personal access tokens](https://github.com/settings/personal-access-tokens)
53
+
54
+ Give the token the permissions GitHub's REST docs list for the endpoints the tool calls:
55
+
56
+ | Endpoint | Used by |
57
+ |-------------------------------------------------------------|----------------------------|
58
+ | `GET /orgs/<owner>/repos`, then `GET /users/<owner>/repos` | both commands |
59
+ | `GET /repos/<owner>/<repo>/actions/workflows` | `enable-all-workflows` |
60
+ | `PUT /repos/<owner>/<repo>/actions/workflows/<file>/enable` | `enable-all-workflows` |
61
+ | `GET /repos/<owner>/<repo>/actions/runs` | `delete-old-workflow-runs` |
62
+ | `DELETE /repos/<owner>/<repo>/actions/runs/<run_id>` | `delete-old-workflow-runs` |
63
+
64
+ Tokens can expire; renew yours before its expiry date to keep the scheduled runs working.
65
+
66
+ ### Store the token as a repository secret
67
+
68
+ Add the token to the repository's secrets so GitHub Actions can inject it at
69
+ runtime:
70
+
71
+ - [Repository secrets](https://github.com/bitranox/keep_github_workflows_active/settings/secrets/actions)
72
+
73
+ Define the following secrets:
74
+
75
+ - `SECRET_GITHUB_OWNER` - the user or organisation whose repositories should be scanned.
76
+ - `SECRET_GITHUB_TOKEN` - the personal access token you generated.
77
+
78
+ ### Where the commands look for the owner and token
79
+
80
+ `--owner` and `--token` on the command line win. Without them, each value is looked up in this
81
+ order, and the first non-empty value is used:
82
+
83
+ 1. the environment variable (`SECRET_GITHUB_OWNER` / `SECRET_GITHUB_TOKEN`);
84
+ 2. the file named by `KEEP_GITHUB_WORKFLOWS_ACTIVE_DOTENV_PATH`, if that variable is set;
85
+ 3. `.env` in the current working directory;
86
+ 4. `.env` in the installed package directory;
87
+ 5. `.env` two levels above the package directory (the repository root when running from a
88
+ source checkout or an editable install).
89
+
90
+ A `.env` file holds `KEY=value` lines; blank lines and lines starting with `#` are skipped, and
91
+ surrounding quotes are removed from the value. When no value is found the command stops with
92
+ `Missing required configuration: SECRET_GITHUB_OWNER` (or `..._TOKEN`).
93
+
94
+ ### Which tests call the live GitHub API
95
+
96
+ `make test` and CI never call the live API: the tests that do are marked `integration` and
97
+ `local_only` (`tests/test_github_integration.py`), which `make test` excludes, and they skip
98
+ whenever the `CI` environment variable is set. `make testintegration` runs them locally against
99
+ the configured account; they list repositories, workflows and runs and call
100
+ `enable_all_workflows` and `enable_workflow`, which re-enable that account's workflows. No test
101
+ deletes workflow runs.
102
+
103
+
104
+ ## Installation
105
+
106
+ Install the package from PyPI:
107
+
108
+ ```bash
109
+ pip install keep_github_workflows_active
110
+ ```
111
+
112
+ Installing from a checkout, from a built wheel, with pipx or with uv is described in
113
+ [INSTALL.md](INSTALL.md). Every install puts two console scripts on your `PATH`,
114
+ `keep_github_workflows_active` and `keep-github-workflows-active`, which run the same CLI.
115
+
116
+ ### Supported platform: Python 3.15 on Linux
117
+
118
+ - The package requires **Python 3.15 or newer** (`requires-python = ">=3.15"`)
119
+ and is built and tested for **Linux** only.
120
+ - Continuous integration runs on GitHub's `ubuntu-latest` runner with CPython
121
+ 3.15; the CI matrix comes from the `Programming Language :: Python :: 3.15`
122
+ classifier and `[tool.ci].os` in `pyproject.toml`.
123
+ - Runtime dependencies: `rich-click` (CLI), `lib_cli_exit_tools` (exit codes and traceback
124
+ output), `requests` (GitHub API calls) and `pydantic` (parsing GitHub's replies).
125
+
126
+ ### Why we recommend uv: supply-chain protection
127
+
128
+ This repository commits a `uv.lock`. It pins every package the project needs, transitive
129
+ dependencies included, to an exact version and to the hashes of that version's files. The
130
+ `exclude-newer` setting under `[tool.uv]` in `pyproject.toml` adds a cooldown: uv leaves any
131
+ release younger than that out of the lock. CI installs from the lock, so a hijacked release that
132
+ gets pulled again within the cooldown never reaches our builds, and a file whose hash does not
133
+ match is refused.
134
+
135
+ That protection stays in this repository. The installable package declares only lower bounds
136
+ (`>=`) for its dependencies, so a plain `pip install` takes the newest release of every transitive
137
+ dependency at the moment you run it. If one of them was hijacked an hour earlier, you get the
138
+ hijacked version. `pipx install` and `uv tool install` without options do the same.
139
+
140
+ To install the command line tool with a cooldown of your own (uv then skips any release younger
141
+ than 7 days, transitive ones included), or to run the exact tree our CI tests:
142
+
143
+ ```bash
144
+ uv tool install --exclude-newer "7 days" keep_github_workflows_active
145
+ git clone https://github.com/bitranox/keep_github_workflows_active.git && cd keep_github_workflows_active && uv sync --locked && uv run keep_github_workflows_active --help
146
+ ```
147
+
148
+ If you depend on keep_github_workflows_active in your own project, give that project the same cooldown (7 days here, as
149
+ an example) and commit the `uv.lock` that `uv add keep_github_workflows_active` writes:
150
+
151
+ ```toml
152
+ [tool.uv]
153
+ exclude-newer = "7 days"
154
+ ```
155
+
156
+ ## Usage
157
+
158
+ Run the two maintenance commands from a scheduled GitHub Actions workflow, as
159
+ `.github/workflows/activate_workflows.yml` does, or by hand:
160
+
161
+ ```bash
162
+ keep-github-workflows-active enable-all-workflows [--owner <owner>] [--token <token>]
163
+ keep-github-workflows-active delete-old-workflow-runs [--owner <owner>] [--token <token>] [--keep <n>]
164
+ ```
165
+
166
+ | Option | Commands | Meaning |
167
+ |-----------|----------------------------|-------------------------------------------------------------------------|
168
+ | `--owner` | both | user or organisation; defaults to `SECRET_GITHUB_OWNER` (lookup above) |
169
+ | `--token` | both | personal access token; defaults to `SECRET_GITHUB_TOKEN` (lookup above) |
170
+ | `--keep` | `delete-old-workflow-runs` | runs to keep per repository, default `50` |
171
+
172
+ Each command opens one HTTPS session for the whole run and reuses its connection for every API
173
+ call. Lists are read 100 entries per page, following GitHub's pagination links.
174
+
175
+ A command stops with a non-zero exit code when:
176
+
177
+ - GitHub answers an error status while listing repositories, workflows or runs, or while enabling
178
+ a workflow (`ERROR reading ...` / `ERROR enabling ...`);
179
+ - a reply does not have the shape the tool acts on, for example a run without `id` or a listing
180
+ that is not a list (`Unexpected GitHub reply for <what>: <field>: <reason>`, or
181
+ `... the body is not JSON`);
182
+ - a delete request fails at the network level (`ERROR deleting workflow run ID ...`).
183
+
184
+ The other commands are diagnostics:
185
+
186
+ ```bash
187
+ keep-github-workflows-active --version
188
+ keep-github-workflows-active info # print package metadata
189
+ keep-github-workflows-active hello # print "Hello World"
190
+ keep-github-workflows-active fail # raise a RuntimeError (short error output)
191
+ keep-github-workflows-active --traceback fail # the same with the full traceback
192
+ python -m keep_github_workflows_active --help # same CLI as the console scripts
193
+ ```
194
+
195
+ Without a subcommand the CLI prints its help.
196
+
197
+ ### Python API
198
+
199
+ The functions behind the commands live in `keep_github_workflows_active.keep_github_workflow_active`:
200
+
201
+ ```python
202
+ from keep_github_workflows_active import keep_github_workflow_active as kgwa
203
+
204
+ token = kgwa.get_github_token() # same lookup as the CLI
205
+ kgwa.enable_all_workflows(owner="example-org", github_token=token)
206
+ kgwa.delete_old_workflow_runs(owner="example-org", github_token=token, number_of_workflow_runs_to_keep=50)
207
+
208
+ # The single-step functions take a session from github_session():
209
+ with kgwa.github_session(token) as session:
210
+ for repository in kgwa.get_repositories(owner="example-org", session=session):
211
+ run_ids = kgwa.get_workflow_runs(owner="example-org", repository=repository, session=session)
212
+ ```
213
+
214
+ The package root exports only the diagnostic helpers (`emit_greeting`,
215
+ `raise_intentional_failure`, `noop_main`, `print_info`, `CANONICAL_GREETING`).
216
+
217
+
218
+ ## Security
219
+
220
+ The token travels only in the `Authorization` header of the session that `github_session()`
221
+ builds; no log message contains it. Every log message of the GitHub module passes through
222
+ `sanitization.sanitize_message()`, which replaces token-like text with `[REDACTED]`:
223
+
224
+ - GitHub tokens (`ghp_...`, `gho_...`, `ghs_...` and the other `gh?_` prefixes)
225
+ - hexadecimal strings of 40 or more characters
226
+ - base64-like strings of 40 or more characters
227
+
228
+ For complete security documentation including incident response procedures, see
229
+ [SECURITY.md](docs/systemdesign/SECURITY.md).
230
+
231
+ ## Further documentation
232
+
233
+ - [Install Guide](INSTALL.md)
234
+ - [Development Handbook](DEVELOPMENT.md)
235
+ - [Contributor Guide](CONTRIBUTING.md)
236
+ - [Changelog](CHANGELOG.md)
237
+ - [Module Reference](docs/systemdesign/module_reference.md)
238
+ - [Security Documentation](docs/systemdesign/SECURITY.md)
239
+ - [License](LICENSE)