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