Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
version
to github action (and rewrite the whole thing while at …
…it) (#1940) Commit history before merge: * Add black_version to github action * Merge upstream/main into this branch * Add version support for the Black action pt.2 Since we're moving to a composite based action, quite a few changes were made. 1) Support was added for all OSes (Windows was painful). 2) Isolation from the rest of the workflow had to be done manually with a virtual environment. Other noteworthy changes: - Rewrote basically all of the logic and put it in a Python script for easy testing (not doing it here tho cause I'm lazy and I can't think of a reasonable way of testing it). - Renamed `black_version` to `version` to better fit the existing input naming scheme. - Added support for log groups, this makes our action's output a bit more fancy (I may or may have not added some debug output too). * Add more to and sorta rewrite the Action's docs Reflect compatability and gotchas. * Add CHANGELOG entry * Merge main into this branch * Remove debug; address typos; clean up action.yml Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
- Loading branch information
1 parent
a4e35b3
commit 4005246
Showing
6 changed files
with
103 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import shlex | ||
import sys | ||
from pathlib import Path | ||
from subprocess import run, PIPE, STDOUT | ||
|
||
ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"]) | ||
ENV_PATH = ACTION_PATH / ".black-env" | ||
ENV_BIN = ENV_PATH / ("Scripts" if sys.platform == "win32" else "bin") | ||
OPTIONS = os.getenv("INPUT_OPTIONS", default="") | ||
SRC = os.getenv("INPUT_SRC", default="") | ||
BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="") | ||
VERSION = os.getenv("INPUT_VERSION", default="") | ||
|
||
run([sys.executable, "-m", "venv", str(ENV_PATH)], check=True) | ||
|
||
req = "black[colorama,python2]" | ||
if VERSION: | ||
req += f"=={VERSION}" | ||
pip_proc = run( | ||
[str(ENV_BIN / "python"), "-m", "pip", "install", req], | ||
stdout=PIPE, | ||
stderr=STDOUT, | ||
encoding="utf-8", | ||
) | ||
if pip_proc.returncode: | ||
print(pip_proc.stdout) | ||
print("::error::Failed to install Black.", flush=True) | ||
sys.exit(pip_proc.returncode) | ||
|
||
|
||
base_cmd = [str(ENV_BIN / "black")] | ||
if BLACK_ARGS: | ||
# TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS. | ||
proc = run([*base_cmd, *shlex.split(BLACK_ARGS)]) | ||
else: | ||
proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)]) | ||
|
||
sys.exit(proc.returncode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters