Skip to content

Commit

Permalink
Merge pull request #10 from deadsnakes/yaml_action
Browse files Browse the repository at this point in the history
port action to python instead of js
  • Loading branch information
asottile authored Sep 13, 2020
2 parents b042c41 + c6bba30 commit fc656d8
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 3,767 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/deploy.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

33 changes: 27 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v3.2.0
hooks:
- id: check-json
- id: check-yaml
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v7.0.0
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: eslint
args: [--fix]
- id: flake8
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.4
hooks:
- id: autopep8
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.3.5
hooks:
- id: reorder-python-imports
args: [--py3-plus]
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.0.1
hooks:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782
hooks:
- id: mypy
24 changes: 0 additions & 24 deletions Makefile

This file was deleted.

7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ inputs:
description: python version to use, such as '3.9'
required: true
runs:
using: node12
main: dist/index.js
using: composite
steps:
- name: add deadsnakes ppa and install ${{ inputs.python-version }}
run: ${{ github.action_path }}/bin/install-python ${{ inputs.python-version }}
shell: bash
89 changes: 89 additions & 0 deletions bin/install-python
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
import argparse
import contextlib
import os.path
import shlex
import subprocess
from typing import Generator
from typing import NamedTuple
from typing import Tuple


class Group(NamedTuple):
section: str
cmds: Tuple[Tuple[str, ...], ...]

@classmethod
def make(cls, section: str, *cmds: Tuple[str, ...]) -> 'Group':
return cls(section, cmds)


@contextlib.contextmanager
def _group(s: str) -> Generator[None, None, None]:
print(f'::group::{s}')
try:
yield
finally:
print('::endgroup::')


def _print_call(*args: str) -> int:
cmd = ' '.join(shlex.quote(arg) for arg in args)
print(f'[command] {cmd}', flush=True)
return subprocess.call(args)


def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument('version')
args = parser.parse_args()

if args.version.endswith('-dev'):
version = args.version[:-1 * len('-dev')]
ppa = 'ppa:deadsnakes/nightly'
else:
version = args.version
ppa = 'ppa:deadsnakes/ppa'

py = f'python{version}'
packages = [f'{py}-dev', f'{py}-venv']
if float(version) >= 3.9:
packages.append(f'{py}-distutils')
else:
packages.append('python3-distutils')

envdir = os.path.expanduser(f'~/venv-{version}')
bindir = os.path.join(envdir, 'bin')
pip = os.path.join(bindir, 'pip')

groups = (
Group.make(
f'add ppa {ppa}',
('sudo', 'add-apt-repository', '--yes', ppa),
),
Group.make(
f'install {py}',
(
'sudo', 'apt-get', 'install', '-y', '--no-install-recommends',
*packages,
),
),
Group.make(
f'set up {py} environment',
(py, '-mvenv', envdir),
(pip, 'install', '--upgrade', 'pip', 'setuptools', 'wheel'),
),
)

for group in groups:
with _group(group.section):
for cmd in group.cmds:
if _print_call(*cmd):
return 1

print(f'::add-path::{bindir}')
return 0


if __name__ == '__main__':
exit(main())
48 changes: 0 additions & 48 deletions index.js

This file was deleted.

Loading

0 comments on commit fc656d8

Please sign in to comment.