keep-github-workflows-active 2.3.6__py3-none-any.whl → 3.0.0__py3-none-any.whl

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.
@@ -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)
@@ -1,15 +1,15 @@
1
1
  keep_github_workflows_active/__init__.py,sha256=AlRr46bcAznN5xCoFiwEyc65m6kbfGBB5l30iIzq-Q4,399
2
- keep_github_workflows_active/__init__conf__.py,sha256=ng31BIHdVbHRfIxHhAM-8NzcIttfteQj8yZn2_qdEbY,2592
2
+ keep_github_workflows_active/__init__conf__.py,sha256=HxW7P5O63clifWEnIR_fw6XIehyaY3rwQRi1ybikPQI,2662
3
3
  keep_github_workflows_active/__main__.py,sha256=HVAzfYkGNoQYMiMgjCOkLVetgQWXE8NmzyySFuuUx8Q,361
4
- keep_github_workflows_active/behaviors.py,sha256=6ck9W-QIwHox6j93XHFL57f_YRwgDkxooa6FtxmnPdw,3733
5
- keep_github_workflows_active/cli.py,sha256=eqeMrqBltwHvmNPyz8i5az5_0dVPnJbb4Mloa4vmZn0,19070
4
+ keep_github_workflows_active/behaviors.py,sha256=8OzfwgMl5FIxqst9tFPAwnoTUCc5Mvj_3WmeOoOGhrk,3651
5
+ keep_github_workflows_active/cli.py,sha256=9PVl0T4Y-0QzNAqQzBQBUQJezFLH6mjLn2E5ppep2AM,19790
6
6
  keep_github_workflows_active/doctest.env,sha256=WmDSq0QN1PFXpP4jq7JW_Kz-k5PT5uS8KzLrAEmJNC8,25
7
- keep_github_workflows_active/keep_github_workflow_active.py,sha256=c8FfZuYmwv27eG6D2gGauX-oLiYsx61cCGabal-6UJM,25952
7
+ keep_github_workflows_active/keep_github_workflow_active.py,sha256=ljM3LKrkc2F17oGcgIwueZPRWZ2MsIBs8uB9Ygw8SeE,31375
8
8
  keep_github_workflows_active/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  keep_github_workflows_active/sanitization.py,sha256=cuG2Lbn0Ca4h6NP2f7Z2rSwio_3c_wy3dNsofUwaGOc,10115
10
10
  keep_github_workflows_active/typed_click.py,sha256=VLZgUkCZ6AFnf6StvoztK3JVYj9lZmgPSNY2Wjb3B8g,2183
11
- keep_github_workflows_active-2.3.6.dist-info/METADATA,sha256=YbOtKGMrsFzyNKik7f3J5jhaOYd_JaZY4K01p3-d5FM,11096
12
- keep_github_workflows_active-2.3.6.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
13
- keep_github_workflows_active-2.3.6.dist-info/entry_points.txt,sha256=6B8ytwKR2VIAj6IXUYhF957dlfulwTPPLR39RBXwCM0,156
14
- keep_github_workflows_active-2.3.6.dist-info/licenses/LICENSE,sha256=6s9SL2InRrwynPjJYiER7ONHBshbGj_yC5EBzfo7l9I,1072
15
- keep_github_workflows_active-2.3.6.dist-info/RECORD,,
11
+ keep_github_workflows_active-3.0.0.dist-info/METADATA,sha256=LVOWAtxBzMAsVU5WDuueJYOqPIrWwKZpkI8FbVdG3OU,14304
12
+ keep_github_workflows_active-3.0.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
13
+ keep_github_workflows_active-3.0.0.dist-info/entry_points.txt,sha256=6B8ytwKR2VIAj6IXUYhF957dlfulwTPPLR39RBXwCM0,156
14
+ keep_github_workflows_active-3.0.0.dist-info/licenses/LICENSE,sha256=6s9SL2InRrwynPjJYiER7ONHBshbGj_yC5EBzfo7l9I,1072
15
+ keep_github_workflows_active-3.0.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.32.4
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,241 +0,0 @@
1
- Metadata-Version: 2.5
2
- Name: keep_github_workflows_active
3
- Version: 2.3.6
4
- Summary: Template for python apps with registered cli commands
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: ansi,cli,logging,rich,terminal
12
- Classifier: Environment :: Console
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3 :: Only
17
- Classifier: Programming Language :: Python :: 3.14
18
- Classifier: Programming Language :: Python :: 3.15
19
- Classifier: Typing :: Typed
20
- Requires-Python: >=3.10
21
- Requires-Dist: lib-cli-exit-tools>=2.4.1
22
- Requires-Dist: pydantic>=2.14.1
23
- Requires-Dist: requests>=2.34.2
24
- Requires-Dist: rich-click>=1.9.9
25
- Provides-Extra: dev
26
- Requires-Dist: bandit>=1.9.4; extra == 'dev'
27
- Requires-Dist: build>=1.6.1; extra == 'dev'
28
- Requires-Dist: click>=8.5.0; extra == 'dev'
29
- Requires-Dist: hatchling>=1.32.4; extra == 'dev'
30
- Requires-Dist: import-linter>=2.15; 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>=9.1.1; extra == 'dev'
35
- Requires-Dist: rtoml>=0.14.0; extra == 'dev'
36
- Requires-Dist: ruff>=0.17.0; extra == 'dev'
37
- Requires-Dist: textual>=8.2.8; extra == 'dev'
38
- Requires-Dist: twine>=7.0.0; extra == 'dev'
39
- Description-Content-Type: text/markdown
40
-
41
- # keep_github_workflows_active
42
-
43
- <!-- Badges -->
44
- [![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)
45
- [![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)
46
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
47
- [![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)
48
- [![PyPI](https://img.shields.io/pypi/v/keep_github_workflows_active.svg)](https://pypi.org/project/keep_github_workflows_active/)
49
- [![PyPI - Downloads](https://img.shields.io/pypi/dm/keep_github_workflows_active.svg)](https://pypi.org/project/keep_github_workflows_active/)
50
- [![Code Style: Ruff](https://img.shields.io/badge/Code%20Style-Ruff-46A3FF?logo=ruff&labelColor=000)](https://docs.astral.sh/ruff/)
51
- [![codecov](https://codecov.io/gh/bitranox/keep_github_workflows_active/graph/badge.svg?token=UFBaUDIgRk)](https://codecov.io/gh/bitranox/keep_github_workflows_active)
52
- [![Maintainability](https://qlty.sh/badges/041ba2c1-37d6-40bb-85a0-ec5a8a0aca0c/maintainability.svg)](https://qlty.sh/gh/bitranox/projects/keep_github_workflows_active)
53
- [![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
54
-
55
- > **CI cadence:** The GitHub Actions CI workflow runs automatically every Monday at 07:00 UTC, in addition to push and pull request triggers.
56
-
57
-
58
- ## Overview
59
-
60
- `keep_github_workflows_active` is an automation helper that tends to every
61
- GitHub Actions workflow in a user's repositories. It exists to remove the
62
- routine maintenance burden that accrues when repositories go quiet and Actions
63
- start to disable schedules automatically.
64
-
65
- The automation focuses on two responsibilities:
66
-
67
- 1. **Keep all workflows active** – iterate every repository owned by the
68
- configured user and flip disabled workflows back to the active state so
69
- cron-based automation continues to run.
70
- 2. **Delete stale workflow runs** – retain an operator-defined number of the
71
- freshest runs per workflow and delete older artifacts so storage quotas and
72
- repository hygiene remain under control.
73
-
74
- Both behaviors run as part of repository automation (for example on a nightly
75
- schedule) once the required GitHub token is in place.
76
-
77
-
78
- ## Prerequisites
79
-
80
- ### Generate an access token
81
-
82
- The automation requires a fine-grained personal access token with repository
83
- scope. You can create one by visiting the GitHub self-service page:
84
-
85
- - [Generate fine-grained personal access token](https://github.com/settings/personal-access-tokens)
86
-
87
- When configuring the token, grant at least the following permissions:
88
-
89
- - **Actions:** Read/Write (needed to toggle workflow states and delete runs).
90
- - **Metadata:** Read (lets the script discover repositories you own).
91
-
92
- Tokens expire automatically. Renew them before the expiry hits to keep the
93
- automation alive. The previous test token that powered the repository expired on
94
- **January 19, 2025**, so any current setup must already use a newer credential.
95
-
96
- ### Store the token as a repository secret
97
-
98
- Add the token to the repository's secrets so GitHub Actions can inject it at
99
- runtime:
100
-
101
- - [Repository secrets](https://github.com/bitranox/keep_github_workflows_active/settings/secrets/actions)
102
-
103
- Define the following secrets:
104
-
105
- - `SECRET_GITHUB_OWNER` – GitHub username whose repositories should be scanned.
106
- - `SECRET_GITHUB_TOKEN` – the fine-grained personal access token you generated.
107
-
108
- Keeping the credentials inside secrets ensures the nightly cleanup workflow can
109
- authenticate without hard-coding sensitive values in the repository.
110
-
111
- For local development you can place the same keys inside a `.env` file at the
112
- repository root. The automation reads from the environment first and falls back
113
- to `.env` when running outside GitHub Actions.
114
-
115
- > **Note:** the included tests and CLI commands exercise the live GitHub API.
116
- > When `SECRET_GITHUB_OWNER` and `SECRET_GITHUB_TOKEN` point at a real account,
117
- > running `make test` (or the workflow maintenance commands directly) will
118
- > re-enable workflows and prune old workflow runs across the configured
119
- > repositories.
120
-
121
-
122
- ## Installation
123
-
124
- Install the package locally when you want to run the CLI helpers or contribute
125
- changes:
126
-
127
- ```bash
128
- pip install keep_github_workflows_active
129
- ```
130
-
131
- Alternative flows (pipx, uv, editable installs, or source builds) are described
132
- in [INSTALL.md](INSTALL.md). All supported options expose both the
133
- `keep_github_workflows_active` and `keep-github-workflows-active` entry points on
134
- your `PATH`.
135
-
136
- ### Python 3.13+ baseline
137
-
138
- - The package targets **Python 3.13 and newer**. Older interpreters are no
139
- longer supported; the codebase relies on modern conveniences such as
140
- `Path.unlink(missing_ok=True)`.
141
- - Runtime modules now use native Python 3.13 type syntax (e.g., `list[str]`,
142
- `Sequence[str] | None`) and drop legacy compatibility helpers.
143
- - Runtime dependencies include `rich-click` for the CLI surface and
144
- `lib_cli_exit_tools` for consistent exit handling. Development extras pin the
145
- tooling stack (pytest, ruff, pyright, bandit, build, twine, codecov-cli,
146
- pip-audit, textual, import-linter) to their latest major releases.
147
- - Development dependencies were refreshed to the latest stable releases
148
- (`ruff>=0.14.1`, `textual>=6.4.0`).
149
- - Continuous integration runs across GitHub's hosted runners (`ubuntu-latest`,
150
- `macos-latest`, `windows-latest`) on CPython 3.13 in addition to the most
151
- recent 3.x release Actions makes available.
152
-
153
- ### Why we recommend uv: supply-chain protection
154
-
155
- This repository commits a `uv.lock`. It pins every package the project needs, transitive
156
- dependencies included, to an exact version and to the hashes of that version's files. The
157
- `exclude-newer` setting under `[tool.uv]` in `pyproject.toml` adds a cooldown: uv leaves any
158
- release younger than that out of the lock. CI installs from the lock, so a hijacked release that
159
- gets pulled again within the cooldown never reaches our builds, and a file whose hash does not
160
- match is refused.
161
-
162
- That protection stays in this repository. The installable package declares only lower bounds
163
- (`>=`) for its dependencies, so a plain `pip install` takes the newest release of every transitive
164
- dependency at the moment you run it. If one of them was hijacked an hour earlier, you get the
165
- hijacked version. `pipx install` and `uv tool install` without options do the same.
166
-
167
- To install the command line tool with a cooldown of your own (uv then skips any release younger
168
- than 7 days, transitive ones included), or to run the exact tree our CI tests:
169
-
170
- ```bash
171
- uv tool install --exclude-newer "7 days" keep_github_workflows_active
172
- 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
173
- ```
174
-
175
- If you depend on keep_github_workflows_active in your own project, give that project the same cooldown (7 days here, as
176
- an example) and commit the `uv.lock` that `uv add keep_github_workflows_active` writes:
177
-
178
- ```toml
179
- [tool.uv]
180
- exclude-newer = "7 days"
181
- ```
182
-
183
- ## Usage
184
-
185
- Once installed and authenticated via repository secrets, schedule the automation
186
- from a GitHub Actions workflow (see `docs/systemdesign/module_reference.md` for
187
- the architectural wiring). The CLI remains available for local smoke-tests and
188
- packaging checks while the richer workflow management helpers iterate:
189
-
190
- ```bash
191
- keep_github_workflows_active info
192
- keep_github_workflows_active hello
193
- keep_github_workflows_active fail
194
- keep_github_workflows_active --traceback fail
195
- keep_github_workflows_active enable-all-workflows [--owner <user>] [--token <pat>]
196
- keep_github_workflows_active delete-old-workflow-runs [--owner <user>] [--token <pat>] [--keep <n>]
197
- keep-github-workflows-active info
198
- python -m keep_github_workflows_active info
199
- ```
200
-
201
- The workflow maintenance commands accept optional flags. When ``--owner`` or
202
- ``--token`` is omitted the CLI falls back to the values discovered via
203
- environment variables or the project's ``.env`` file. ``--keep`` defaults to
204
- ``50`` workflow runs per repository.
205
-
206
- Programmatic access is also exposed via the public helpers:
207
-
208
- ```python
209
- import keep_github_workflows_active as kgwa
210
-
211
- kgwa.emit_greeting()
212
- try:
213
- kgwa.raise_intentional_failure()
214
- except RuntimeError as exc:
215
- print(f"caught expected failure: {exc}")
216
-
217
- kgwa.print_info()
218
- ```
219
-
220
-
221
- ## Security
222
-
223
- All logging operations sanitize sensitive data before output to prevent credential
224
- leakage. The automation redacts:
225
-
226
- - GitHub personal access tokens (ghp_*, gho_*, etc.)
227
- - Authorization headers and API keys
228
- - Token-like patterns in error messages
229
-
230
- For complete security documentation including incident response procedures, see
231
- [SECURITY.md](docs/systemdesign/SECURITY.md).
232
-
233
- ## Further documentation
234
-
235
- - [Install Guide](INSTALL.md)
236
- - [Development Handbook](DEVELOPMENT.md)
237
- - [Contributor Guide](CONTRIBUTING.md)
238
- - [Changelog](CHANGELOG.md)
239
- - [Module Reference](docs/systemdesign/module_reference.md)
240
- - [Security Documentation](docs/systemdesign/SECURITY.md)
241
- - [License](LICENSE)