Skip to content

Commit 39807af

Browse files
committed
make cli
1 parent 82c6111 commit 39807af

6 files changed

Lines changed: 35 additions & 17 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
venv
2+
.venv
3+
dist

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
GitHub Actions Utils
1+
GitHub Actions CLI
22
====================
33

44
The purpose of this tool is to work with your GitHub Actions workflows in your repositories.
5+
It is complementary to the GitHub CLI.
56

67
So far, three main flows are supported:
78

@@ -10,7 +11,7 @@ So far, three main flows are supported:
1011
Example:
1112

1213
```shell
13-
python ghautils.py cunla/fakeredis list-workflows
14+
github-actions-cli cunla/fakeredis list-workflows
1415
```
1516
will return:
1617

@@ -27,7 +28,7 @@ Given a repo and a workflow path, return all actions in the workflow.
2728

2829
Example:
2930
```shell
30-
python ghautils.py cunla/fakeredis list-actions .github/workflows/publish.yml
31+
github-actions-cli cunla/fakeredis list-actions .github/workflows/publish.yml
3132
```
3233

3334
Result
@@ -42,7 +43,7 @@ Show the latest versions of actions used in a repository workflow.
4243

4344
Example:
4445
```shell
45-
python ghautils.py cunla/fakeredis update
46+
github-actions-cli cunla/fakeredis update
4647
```
4748
Result:
4849
```text
@@ -56,10 +57,16 @@ Result:
5657
actions/checkout @ v3 ==> v3.5.3
5758
```
5859

60+
# Installation
61+
62+
```shell
63+
pip install github-actions-cli
64+
```
65+
5966
# Help messages
6067

6168
```text
62-
usage: ghautils.py [-h] [--github-token GITHUB_TOKEN] repo {list-workflows,list-actions,update} ...
69+
usage: github-actions-cli [-h] [--github-token GITHUB_TOKEN] repo {list-workflows,list-actions,update} ...
6370
6471
positional arguments:
6572
repo Repository to analyze
File renamed without changes.
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
#!/usr/bin/env python3
12
import argparse
3+
import logging
24
import os
35
from typing import Optional, List, Set, Tuple, Dict
46

57
import yaml
68
from github import Github, Workflow
79

10+
logging.basicConfig(level=logging.WARNING)
11+
logging.getLogger('github.Requester').setLevel(logging.WARNING)
12+
logger = logging.getLogger()
13+
814

915
def parse_args() -> argparse.Namespace:
1016
parser = argparse.ArgumentParser()
@@ -14,8 +20,8 @@ def parse_args() -> argparse.Namespace:
1420
help='GitHub token to use, by default will use GITHUB_TOKEN environment variable')
1521
subcommands = parser.add_subparsers(dest='command', required=True)
1622
list_wfs_cmd_parser = subcommands.add_parser('list-workflows', help='List github workflows')
17-
list_wfs_cmd_parser.add_argument('--local-only', action='store_true', dest='local_only',
18-
help='Show only workflows stored in the repository')
23+
list_wfs_cmd_parser.add_argument('--all', action='store_true', dest='external_workflows',
24+
help='Show external workflows as well')
1925
list_actions_cmd_parser = subcommands.add_parser('list-actions', help='List actions in a workflow')
2026
list_actions_cmd_parser.add_argument('workflow_path', help='Workflow path')
2127
update_gha_cmd_parser = subcommands.add_parser('update', help='Update actions in github workflows')
@@ -33,12 +39,12 @@ def __init__(self, github_token: Optional[str]):
3339
raise ValueError('GITHUB_TOKEN must be set')
3440
self.client = Github(login_or_token=github_token)
3541

36-
def get_github_workflows(self, repo_name: str, local_only: bool = False) -> List[Workflow]:
42+
def get_github_workflows(self, repo_name: str, external_workflows: bool = False) -> List[Workflow]:
3743
if repo_name in self.workflows:
3844
return list(self.workflows[repo_name].values())
3945
repo = self.client.get_repo(repo_name)
4046
workflows = list(repo.get_workflows())
41-
if local_only:
47+
if not external_workflows:
4248
workflows = list(filter(lambda item: item.path.startswith('.github/'), workflows))
4349
self.workflows[repo_name] = {wf.path: wf for wf in workflows}
4450
return workflows

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
requires = ["poetry-core"]
33
build-backend = "poetry.core.masonry.api"
44

5+
[tool.poetry.scripts]
6+
github-actions-cli = "gha_cli.cli:run"
7+
58
[tool.poetry]
69
name = "github-actions-cli"
7-
packages = [
8-
{ include = "gha-cli" },
9-
]
10-
version = "1.0.0b1"
10+
version = "1.0.0b2"
1111
description = "GitHub Actions CLI - allows updating workflows, etc."
1212
readme = "README.md"
1313
keywords = ["GitHub Actions", "CLI"]
14+
packages = [
15+
{ include = "gha_cli" },
16+
]
17+
1418
authors = [
1519
"Daniel Moran <daniel@moransoftware.ca>",
1620
]
@@ -39,7 +43,7 @@ documentation = "https://github.com/dsoftwareinc/github-actions-cli"
3943
[tool.poetry.dependencies]
4044
python = "^3.9"
4145
pygithub = "^1.59"
42-
pyyaml = { version = "^6.0", optional = true }
46+
pyyaml = "^6.0"
4347

4448
[tool.poetry.dev-dependencies]
4549
poetry = "^1.5"

0 commit comments

Comments
 (0)