Skip to content

Commit fc656d8

Browse files
authored
Merge pull request #10 from deadsnakes/yaml_action
port action to python instead of js
2 parents b042c41 + c6bba30 commit fc656d8

File tree

11 files changed

+127
-3767
lines changed

11 files changed

+127
-3767
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v3.1.0
3+
rev: v3.2.0
44
hooks:
5-
- id: check-json
65
- id: check-yaml
76
- id: trailing-whitespace
87
- id: end-of-file-fixer
9-
- repo: https://github.com/pre-commit/mirrors-eslint
10-
rev: v7.0.0
8+
- repo: https://gitlab.com/pycqa/flake8
9+
rev: 3.8.3
1110
hooks:
12-
- id: eslint
13-
args: [--fix]
11+
- id: flake8
12+
- repo: https://github.com/pre-commit/mirrors-autopep8
13+
rev: v1.5.4
14+
hooks:
15+
- id: autopep8
16+
- repo: https://github.com/asottile/reorder_python_imports
17+
rev: v2.3.5
18+
hooks:
19+
- id: reorder-python-imports
20+
args: [--py3-plus]
21+
- repo: https://github.com/asottile/add-trailing-comma
22+
rev: v2.0.1
23+
hooks:
24+
- id: add-trailing-comma
25+
args: [--py36-plus]
26+
- repo: https://github.com/asottile/pyupgrade
27+
rev: v2.7.2
28+
hooks:
29+
- id: pyupgrade
30+
args: [--py36-plus]
31+
- repo: https://github.com/pre-commit/mirrors-mypy
32+
rev: v0.782
33+
hooks:
34+
- id: mypy

Makefile

Lines changed: 0 additions & 24 deletions
This file was deleted.

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ inputs:
55
description: python version to use, such as '3.9'
66
required: true
77
runs:
8-
using: node12
9-
main: dist/index.js
8+
using: composite
9+
steps:
10+
- name: add deadsnakes ppa and install ${{ inputs.python-version }}
11+
run: ${{ github.action_path }}/bin/install-python ${{ inputs.python-version }}
12+
shell: bash

bin/install-python

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import contextlib
4+
import os.path
5+
import shlex
6+
import subprocess
7+
from typing import Generator
8+
from typing import NamedTuple
9+
from typing import Tuple
10+
11+
12+
class Group(NamedTuple):
13+
section: str
14+
cmds: Tuple[Tuple[str, ...], ...]
15+
16+
@classmethod
17+
def make(cls, section: str, *cmds: Tuple[str, ...]) -> 'Group':
18+
return cls(section, cmds)
19+
20+
21+
@contextlib.contextmanager
22+
def _group(s: str) -> Generator[None, None, None]:
23+
print(f'::group::{s}')
24+
try:
25+
yield
26+
finally:
27+
print('::endgroup::')
28+
29+
30+
def _print_call(*args: str) -> int:
31+
cmd = ' '.join(shlex.quote(arg) for arg in args)
32+
print(f'[command] {cmd}', flush=True)
33+
return subprocess.call(args)
34+
35+
36+
def main() -> int:
37+
parser = argparse.ArgumentParser()
38+
parser.add_argument('version')
39+
args = parser.parse_args()
40+
41+
if args.version.endswith('-dev'):
42+
version = args.version[:-1 * len('-dev')]
43+
ppa = 'ppa:deadsnakes/nightly'
44+
else:
45+
version = args.version
46+
ppa = 'ppa:deadsnakes/ppa'
47+
48+
py = f'python{version}'
49+
packages = [f'{py}-dev', f'{py}-venv']
50+
if float(version) >= 3.9:
51+
packages.append(f'{py}-distutils')
52+
else:
53+
packages.append('python3-distutils')
54+
55+
envdir = os.path.expanduser(f'~/venv-{version}')
56+
bindir = os.path.join(envdir, 'bin')
57+
pip = os.path.join(bindir, 'pip')
58+
59+
groups = (
60+
Group.make(
61+
f'add ppa {ppa}',
62+
('sudo', 'add-apt-repository', '--yes', ppa),
63+
),
64+
Group.make(
65+
f'install {py}',
66+
(
67+
'sudo', 'apt-get', 'install', '-y', '--no-install-recommends',
68+
*packages,
69+
),
70+
),
71+
Group.make(
72+
f'set up {py} environment',
73+
(py, '-mvenv', envdir),
74+
(pip, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'),
75+
),
76+
)
77+
78+
for group in groups:
79+
with _group(group.section):
80+
for cmd in group.cmds:
81+
if _print_call(*cmd):
82+
return 1
83+
84+
print(f'::add-path::{bindir}')
85+
return 0
86+
87+
88+
if __name__ == '__main__':
89+
exit(main())

index.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)