mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 10:42:13 +02:00
ci: Rewrite lint task Bash snippet to Python
The Bash snippet was shorter, but relying on implicit word splitting (see the shellcheck SC2086 warning). For example, the DOCKER_BUILD_CACHE_ARG shlex.split is now done identical to how ci/test/02_run_container.py does it. Moreover, the Python will hopefully be easier to modify in the future, as the dev notes recommend Python over Bash.
This commit is contained in:
40
.github/workflows/ci.yml
vendored
40
.github/workflows/ci.yml
vendored
@@ -599,11 +599,37 @@ jobs:
|
|||||||
cache-provider: ${{ needs.runners.outputs.provider }}
|
cache-provider: ${{ needs.runners.outputs.provider }}
|
||||||
|
|
||||||
- name: CI script
|
- name: CI script
|
||||||
|
shell: python
|
||||||
run: |
|
run: |
|
||||||
set -o xtrace
|
import os, shlex, subprocess, sys
|
||||||
docker buildx build -t "$CONTAINER_NAME" $DOCKER_BUILD_CACHE_ARG --file "./ci/lint_imagefile" .
|
|
||||||
CIRRUS_PR_FLAG=""
|
def run(cmd, **kwargs):
|
||||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
print("+ " + shlex.join(cmd), flush=True)
|
||||||
CIRRUS_PR_FLAG="-e CIRRUS_PR=1"
|
kwargs.setdefault("check", True)
|
||||||
fi
|
try:
|
||||||
docker run --rm $CIRRUS_PR_FLAG -v "$(pwd)":/bitcoin "$CONTAINER_NAME"
|
return subprocess.run(cmd, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
sys.exit(e)
|
||||||
|
|
||||||
|
CONTAINER_NAME = os.environ["CONTAINER_NAME"]
|
||||||
|
|
||||||
|
build_cmd = [
|
||||||
|
"docker", "buildx", "build",
|
||||||
|
f"--tag={CONTAINER_NAME}",
|
||||||
|
*shlex.split(os.getenv("DOCKER_BUILD_CACHE_ARG", "")),
|
||||||
|
"--file=./ci/lint_imagefile",
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
|
||||||
|
run(build_cmd)
|
||||||
|
|
||||||
|
CIRRUS_PR_FLAG = []
|
||||||
|
if '${{ github.event_name }}' == "pull_request":
|
||||||
|
CIRRUS_PR_FLAG = ["-e", "CIRRUS_PR=1"]
|
||||||
|
|
||||||
|
run([
|
||||||
|
"docker", "run", "--rm",
|
||||||
|
*CIRRUS_PR_FLAG,
|
||||||
|
f"--volume={os.getcwd()}:/bitcoin",
|
||||||
|
CONTAINER_NAME,
|
||||||
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user