mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Merge pull request #39630 from ClickHouse/workflow-rerun-lambda
Attempt to fix wrong workflow_run data for rerun
This commit is contained in:
commit
70d97e9393
3
tests/ci/.gitignore
vendored
Normal file
3
tests/ci/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*_lambda/lambda-venv
|
||||||
|
*_lambda/lambda-package
|
||||||
|
*_lambda/lambda-package.zip
|
2
tests/ci/team_keys_lambda/.gitignore
vendored
2
tests/ci/team_keys_lambda/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
lambda-venv
|
|
||||||
lambda-package.zip
|
|
@ -1,15 +1,24 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
|
|
||||||
|
WORKDIR=$(dirname "$0")
|
||||||
|
cd "$WORKDIR"
|
||||||
|
|
||||||
|
PY_EXEC=python3.9
|
||||||
|
LAMBDA_NAME=$(basename "$PWD")
|
||||||
|
LAMBDA_NAME=${LAMBDA_NAME//_/-}
|
||||||
VENV=lambda-venv
|
VENV=lambda-venv
|
||||||
py_exec=$(which python3)
|
|
||||||
py_version=$(basename "$(readlink -f "$py_exec")")
|
|
||||||
rm -rf "$VENV" lambda-package.zip
|
rm -rf "$VENV" lambda-package.zip
|
||||||
virtualenv "$VENV"
|
"$PY_EXEC" -m venv "$VENV"
|
||||||
|
#virtualenv "$VENV"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
source "$VENV/bin/activate"
|
source "$VENV/bin/activate"
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
PACKAGES="$VENV/lib/$py_version/site-packages"
|
PACKAGE=lambda-package
|
||||||
cp app.py "$PACKAGES/"
|
rm -rf "$PACKAGE" "$PACKAGE".zip
|
||||||
( cd "$PACKAGES" && zip -r ../../../../lambda-package.zip . )
|
cp -r "$VENV/lib/$PY_EXEC/site-packages" "$PACKAGE"
|
||||||
|
cp app.py "$PACKAGE"
|
||||||
|
rm -r "$PACKAGE"/{pip,pip-*,setuptools,setuptools-*}
|
||||||
|
( cd "$PACKAGE" && zip -r ../"$PACKAGE".zip . )
|
||||||
|
|
||||||
aws lambda update-function-code --function-name team-keys-lambda --zip-file fileb://lambda-package.zip
|
aws lambda update-function-code --function-name "$LAMBDA_NAME" --zip-file fileb://"$PACKAGE".zip
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
FROM public.ecr.aws/lambda/python:3.9
|
|
||||||
|
|
||||||
# Install the function's dependencies using file requirements.txt
|
|
||||||
# from your project folder.
|
|
||||||
|
|
||||||
COPY requirements.txt .
|
|
||||||
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
|
|
||||||
|
|
||||||
# Copy function code
|
|
||||||
COPY app.py ${LAMBDA_TASK_ROOT}
|
|
||||||
|
|
||||||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
|
|
||||||
CMD [ "app.handler" ]
|
|
@ -402,10 +402,27 @@ def main(event):
|
|||||||
workflow_description = get_workflow_description_from_event(event_data)
|
workflow_description = get_workflow_description_from_event(event_data)
|
||||||
|
|
||||||
print("Got workflow description", workflow_description)
|
print("Got workflow description", workflow_description)
|
||||||
if (
|
if workflow_description.action == "completed":
|
||||||
workflow_description.action == "completed"
|
attempt = 0
|
||||||
and workflow_description.conclusion == "failure"
|
# Nice and reliable GH API sends from time to time such events, e.g:
|
||||||
):
|
# action='completed', conclusion=None, status='in_progress',
|
||||||
|
# So let's try receiving a real workflow data
|
||||||
|
while workflow_description.conclusion is None and attempt < MAX_RETRY:
|
||||||
|
progressive_sleep = 3 * sum(i + 1 for i in range(attempt))
|
||||||
|
time.sleep(progressive_sleep)
|
||||||
|
event_data["workflow_run"] = _exec_get_with_retry(
|
||||||
|
workflow_description.api_url
|
||||||
|
)
|
||||||
|
workflow_description = get_workflow_description_from_event(event_data)
|
||||||
|
attempt += 1
|
||||||
|
|
||||||
|
if workflow_description.conclusion != "failure":
|
||||||
|
print(
|
||||||
|
"Workflow finished with status "
|
||||||
|
f"{workflow_description.conclusion}, exiting"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"Workflow",
|
"Workflow",
|
||||||
workflow_description.url,
|
workflow_description.url,
|
||||||
@ -438,11 +455,9 @@ def main(event):
|
|||||||
)
|
)
|
||||||
|
|
||||||
print("Got pull requests for workflow", len(pull_requests))
|
print("Got pull requests for workflow", len(pull_requests))
|
||||||
if len(pull_requests) > 1:
|
if len(pull_requests) != 1:
|
||||||
raise Exception("Received more than one PR for workflow run")
|
print(f"Can't continue with non-uniq PRs: {pull_requests}")
|
||||||
|
return
|
||||||
if len(pull_requests) < 1:
|
|
||||||
raise Exception("Cannot find any pull requests for workflow run")
|
|
||||||
|
|
||||||
pull_request = pull_requests[0]
|
pull_request = pull_requests[0]
|
||||||
print("Pull request for workflow number", pull_request["number"])
|
print("Pull request for workflow number", pull_request["number"])
|
||||||
@ -467,4 +482,8 @@ def main(event):
|
|||||||
|
|
||||||
|
|
||||||
def handler(event, _):
|
def handler(event, _):
|
||||||
|
try:
|
||||||
main(event)
|
main(event)
|
||||||
|
except Exception:
|
||||||
|
print("Received event: ", event)
|
||||||
|
raise
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
../team_keys_lambda/build_and_deploy_archive.sh
|
Loading…
Reference in New Issue
Block a user