Skip to content

Commit b542f58

Browse files
authored
Use GH action version when version argument not specified (#3543)
1 parent f3b1a3b commit b542f58

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

.git_archival.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node: $Format:%H$
2+
node-date: $Format:%cI$
3+
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
4+
ref-names: $Format:%D$

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git_archival.txt export-subst

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161

6262
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
6363

64+
- Update GitHub Action to use the version of Black equivalent to action's version if
65+
version input is not specified (#3543)
66+
6467
### Documentation
6568

6669
<!-- Major changes to documentation and policies. Small docs changes

action/main.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,34 @@
2222
extra_deps = "[colorama,jupyter]"
2323
else:
2424
extra_deps = "[colorama]"
25-
req = f"black{extra_deps}{version_specifier}"
25+
if version_specifier:
26+
req = f"black{extra_deps}{version_specifier}"
27+
else:
28+
describe_name = ""
29+
with open(ACTION_PATH / ".git_archival.txt", encoding="utf-8") as fp:
30+
for line in fp:
31+
if line.startswith("describe-name: "):
32+
describe_name = line[len("describe-name: ") :].rstrip()
33+
break
34+
if not describe_name:
35+
print("::error::Failed to detect action version.", flush=True)
36+
sys.exit(1)
37+
# expected format is one of:
38+
# - 23.1.0
39+
# - 23.1.0-51-g448bba7
40+
if describe_name.count("-") < 2:
41+
# the action's commit matches a tag exactly, install exact version from PyPI
42+
req = f"black{extra_deps}=={describe_name}"
43+
else:
44+
# the action's commit does not match any tag, install from the local git repo
45+
req = f".{extra_deps}"
46+
print(f"Installing {req}...", flush=True)
2647
pip_proc = run(
2748
[str(ENV_BIN / "python"), "-m", "pip", "install", req],
2849
stdout=PIPE,
2950
stderr=STDOUT,
3051
encoding="utf-8",
52+
cwd=ACTION_PATH,
3153
)
3254
if pip_proc.returncode:
3355
print(pip_proc.stdout)

0 commit comments

Comments
 (0)