Skip the workflow if there is already one running
This commit is contained in:
parent
8b1d0ec0ba
commit
fe669e0bf1
21
.github/workflows/build.yml
vendored
21
.github/workflows/build.yml
vendored
@ -35,37 +35,43 @@ jobs:
|
||||
python -m pip install --upgrade pip setuptools wheel
|
||||
python -m pip install --user -r requirements.txt
|
||||
|
||||
- name: Show build queue
|
||||
id: queue
|
||||
- name: Check if we should run
|
||||
id: check
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
python autobuild.py show --fail-on-idle
|
||||
python autobuild.py should-run
|
||||
$skipBuild = ($LASTEXITCODE -ne 0)
|
||||
If ($skipBuild) {echo '::set-output name=skip-build::true'}
|
||||
exit 0
|
||||
|
||||
- name: Show build queue
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
python autobuild.py show
|
||||
|
||||
- uses: msys2/setup-msys2@v2
|
||||
if: steps.queue.outputs.skip-build != 'true'
|
||||
if: steps.check.outputs.skip-build != 'true'
|
||||
with:
|
||||
msystem: MSYS
|
||||
update: true
|
||||
install: msys2-devel base-devel mingw-w64-x86_64-toolchain mingw-w64-i686-toolchain git
|
||||
|
||||
- name: Check install
|
||||
if: steps.queue.outputs.skip-build != 'true'
|
||||
if: steps.check.outputs.skip-build != 'true'
|
||||
run: |
|
||||
msys2 -c 'pacman -Qkq'
|
||||
|
||||
- name: Init git
|
||||
if: steps.queue.outputs.skip-build != 'true'
|
||||
if: steps.check.outputs.skip-build != 'true'
|
||||
shell: msys2 {0}
|
||||
run: |
|
||||
git config --global user.email 'ci@msys2.org'
|
||||
git config --global user.name 'MSYS2 Continuous Integration'
|
||||
|
||||
- name: Process build queue
|
||||
if: steps.queue.outputs.skip-build != 'true'
|
||||
if: steps.check.outputs.skip-build != 'true'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
@ -76,6 +82,7 @@ jobs:
|
||||
python autobuild.py build "$MSYS2_ROOT" "$BUILD_ROOT"
|
||||
|
||||
- name: Clean up assets
|
||||
if: steps.check.outputs.skip-build != 'true'
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
|
||||
37
autobuild.py
37
autobuild.py
@ -44,6 +44,7 @@ SKIP: List[str] = [
|
||||
|
||||
|
||||
REPO = "msys2/msys2-autobuild"
|
||||
WORKFLOW = "build"
|
||||
|
||||
|
||||
def timeoutgen(timeout: float) -> Callable[[], float]:
|
||||
@ -549,6 +550,35 @@ def get_packages_to_build() -> Tuple[
|
||||
return done, skipped, todo
|
||||
|
||||
|
||||
def get_workflow():
|
||||
repo = get_repo()
|
||||
for workflow in repo.get_workflows():
|
||||
if workflow.name == WORKFLOW:
|
||||
return workflow
|
||||
else:
|
||||
raise Exception("workflow not found:", WORKFLOW)
|
||||
|
||||
|
||||
def should_run(args: Any) -> None:
|
||||
current_id = None
|
||||
if "GITHUB_RUN_ID" in os.environ:
|
||||
current_id = int(os.environ["GITHUB_RUN_ID"])
|
||||
|
||||
workflow = get_workflow()
|
||||
runs = list(workflow.get_runs(status="in_progress"))
|
||||
runs += list(workflow.get_runs(status="queued"))
|
||||
for run in runs:
|
||||
if current_id is not None and current_id == run.id:
|
||||
# Ignore this run itself
|
||||
continue
|
||||
raise SystemExit(
|
||||
f"Another workflow is currently running or has something queued: {run.html_url}")
|
||||
|
||||
done, skipped, todo = get_packages_to_build()
|
||||
if not todo:
|
||||
raise SystemExit("Nothing to build")
|
||||
|
||||
|
||||
def show_build(args: Any) -> None:
|
||||
done, skipped, todo = get_packages_to_build()
|
||||
|
||||
@ -564,9 +594,6 @@ def show_build(args: Any) -> None:
|
||||
print(tabulate([(p["name"], bt, p["version"]) for (p, bt) in done],
|
||||
headers=["Package", "Build", "Version"]))
|
||||
|
||||
if args.fail_on_idle and not todo:
|
||||
raise SystemExit("Nothing to build")
|
||||
|
||||
|
||||
def show_assets(args: Any) -> None:
|
||||
repo = get_repo()
|
||||
@ -757,6 +784,10 @@ def main(argv: List[str]):
|
||||
"--fail-on-idle", action="store_true", help="Fails if there is nothing to do")
|
||||
sub.set_defaults(func=show_build)
|
||||
|
||||
sub = subparser.add_parser(
|
||||
"should-run", help="Fails if the workflow shouldn't run", allow_abbrev=False)
|
||||
sub.set_defaults(func=should_run)
|
||||
|
||||
sub = subparser.add_parser(
|
||||
"show-assets", help="Show all staging packages", allow_abbrev=False)
|
||||
sub.set_defaults(func=show_assets)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user