Use GH action version when version argument not specified
diff --git a/.git_archival.txt b/.git_archival.txt
new file mode 100644
index 00000000000..8fb235d7045
--- /dev/null
+++ b/.git_archival.txt
@@ -0,0 +1,4 @@
+node: $Format:%H$
+node-date: $Format:%cI$
+describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
+ref-names: $Format:%D$
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000000..00a7b00c94e
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+.git_archival.txt  export-subst
diff --git a/CHANGES.md b/CHANGES.md
index 2071eb3f800..b10cfc9888a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -42,6 +42,9 @@
 
 <!-- For example, Docker, GitHub Actions, pre-commit, editors -->
 
+- Update GitHub Action to use the version of Black equivalent to action's version if
+  version input is not specified (#3543)
+
 ### Documentation
 
 <!-- Major changes to documentation and policies. Small docs changes
diff --git a/action/main.py b/action/main.py
index ff9d4112aed..23c3a652194 100644
--- a/action/main.py
+++ b/action/main.py
@@ -22,12 +22,34 @@
     extra_deps = "[colorama,jupyter]"
 else:
     extra_deps = "[colorama]"
-req = f"black{extra_deps}{version_specifier}"
+if version_specifier:
+    req = f"black{extra_deps}{version_specifier}"
+else:
+    describe_name = ""
+    with open(ACTION_PATH / ".git_archival.txt", encoding="utf-8") as fp:
+        for line in fp:
+            if line.startswith("describe-name: "):
+                describe_name = line[len("describe-name: ") :].rstrip()
+                break
+    if not describe_name:
+        print("::error::Failed to detect action version.", flush=True)
+        sys.exit(1)
+    # expected format is one of:
+    # - 23.1.0
+    # - 23.1.0-51-g448bba7
+    if describe_name.count("-") < 2:
+        # the action's commit matches a tag exactly, install exact version from PyPI
+        req = f"black{extra_deps}=={describe_name}"
+    else:
+        # the action's commit does not match any tag, install from the local git repo
+        req = f".{extra_deps}"
+print(f"Installing {req}...", flush=True)
 pip_proc = run(
     [str(ENV_BIN / "python"), "-m", "pip", "install", req],
     stdout=PIPE,
     stderr=STDOUT,
     encoding="utf-8",
+    cwd=ACTION_PATH,
 )
 if pip_proc.returncode:
     print(pip_proc.stdout)

### Description

Resolves #3382 

There are 2 things going on here:
- addition of `.git_archival.txt` set with `export-subst` git attribute so that black can be installed from a git archive, see: https://github.com/pypa/setuptools_scm#git-archives
- update to GH action changing it to use GH action version when the version argument is not specified; this means:
    - when the action's commit is tagged, install Black from PyPI using that tag's name as the pinned version
    - when the action's commit is not tagged, install Black from the action's local directory

A couple of tests:
- `Jackenmen/black@22.12.0` - 22.12.0 on my repo is not the real commit of 22.12.0 as then it wouldn't have this feature; however it does allow you to see that the code gets 2022 formatting:
    - https://github.com/Jackenmen/black/actions/runs/4076830464/jobs/7025089166
- `Jackenmen/black@e29e12c973d0e294a0a905b1fb4d8f4962bfa408` - the exact same commit that you get with 22.12.0, just confirming that it still correctly detects it as a tagged release in such a case:
    - https://github.com/Jackenmen/black/actions/runs/4076898146/jobs/7025240425
- `Jackenmen/black@9a168472de3144674dd7db3c6b514b7e5f5d5c20` - an untagged commit *after* the fake 22.12.0 tag, this causes the action to install Black from the local source; you can see that this causes it to use 2023 formatting:
    - https://github.com/Jackenmen/black/actions/runs/4076901054/jobs/7025246892
- `Jackenmen/black@stable` - the exact same commit that you get with 22.12.0, just confirming that it correctly fetches 22.12.0:
    - https://github.com/Jackenmen/black/actions/runs/4077049374/jobs/7025578668


### Checklist - did you ...

- [x] Add an entry in `CHANGES.md` if necessary?
- [x] Add / update tests if necessary?
- [ ] Add new / update outdated documentation?
