mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 21:59:10 +02:00
ci: Move lint exec snippet to stand-alone py file
Moving the python code out of the yaml string makes it easier to lint, format, and edit. This can be reviewed with the git options: --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space
This commit is contained in:
51
.github/ci-lint-exec.py
vendored
Executable file
51
.github/ci-lint-exec.py
vendored
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Copyright (c) The Bitcoin Core developers
|
||||||
|
# Distributed under the MIT software license, see the accompanying
|
||||||
|
# file COPYING or https://opensource.org/license/mit.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def run(cmd, **kwargs):
|
||||||
|
print("+ " + shlex.join(cmd), flush=True)
|
||||||
|
kwargs.setdefault("check", True)
|
||||||
|
try:
|
||||||
|
return subprocess.run(cmd, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
sys.exit(e)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
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",
|
||||||
|
"."
|
||||||
|
]
|
||||||
|
|
||||||
|
if run(build_cmd, check=False).returncode != 0:
|
||||||
|
print("Retry building image tag after failure")
|
||||||
|
time.sleep(3)
|
||||||
|
run(build_cmd)
|
||||||
|
|
||||||
|
CIRRUS_PR_FLAG = []
|
||||||
|
if os.environ.get("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,
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
38
.github/workflows/ci.yml
vendored
38
.github/workflows/ci.yml
vendored
@@ -620,40 +620,4 @@ jobs:
|
|||||||
cache-provider: ${{ needs.runners.outputs.provider }}
|
cache-provider: ${{ needs.runners.outputs.provider }}
|
||||||
|
|
||||||
- name: CI script
|
- name: CI script
|
||||||
shell: python
|
run: python .github/ci-lint-exec.py
|
||||||
run: |
|
|
||||||
import os, shlex, subprocess, sys, time
|
|
||||||
|
|
||||||
def run(cmd, **kwargs):
|
|
||||||
print("+ " + shlex.join(cmd), flush=True)
|
|
||||||
kwargs.setdefault("check", True)
|
|
||||||
try:
|
|
||||||
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",
|
|
||||||
"."
|
|
||||||
]
|
|
||||||
|
|
||||||
if run(build_cmd, check=False).returncode != 0:
|
|
||||||
print("Retry building image tag after failure")
|
|
||||||
time.sleep(3)
|
|
||||||
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