2 files changed
+62
-1
No files matched your search
@@ -1,4 +1,5 @@
|
|||||||
name: Deploy
|
name: Deploy
|
||||||
|
# retry-deploy.yaml reruns all jobs after failure, up to 3 times.
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -13,4 +14,4 @@ jobs:
|
|||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
|
passphrase: ${{ secrets.SSH_PRIVATE_KEY_PASSPHRASE }}
|
||||||
command_timeout: 3h
|
command_timeout: 3h
|
||||||
script: bash /root/maria/script/action/blog.sh
|
script: bash /root/maria/script/action/blog.sh
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
name: Retry Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_run:
|
||||||
|
workflows: [Deploy]
|
||||||
|
types: [completed]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
actions: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
retry:
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
(gitea.event.workflow_run.conclusion == 'failure' ||
|
||||||
|
gitea.event.workflow_run.conclusion == 'timed_out')
|
||||||
|
&& gitea.event.workflow_run.run_attempt >= 1
|
||||||
|
&& gitea.event.workflow_run.run_attempt <= 3
|
||||||
|
}}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Retry the entire Deploy workflow
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||||
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
|
RUN_ID: ${{ gitea.event.workflow_run.id }}
|
||||||
|
RUN_ATTEMPT: ${{ gitea.event.workflow_run.run_attempt }}
|
||||||
|
run: |
|
||||||
|
python3 - <<'PY'
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
max_retries = 3
|
||||||
|
event_attempt = int(os.environ['RUN_ATTEMPT'])
|
||||||
|
server = os.environ['GITEA_SERVER_URL'].rstrip('/')
|
||||||
|
repository = os.environ['GITEA_REPOSITORY']
|
||||||
|
run_id = os.environ['RUN_ID']
|
||||||
|
run_url = f'{server}/api/v1/repos/{repository}/actions/runs/{run_id}'
|
||||||
|
headers = {
|
||||||
|
'Authorization': f'token {os.environ["GITEA_TOKEN"]}',
|
||||||
|
'Accept': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
|
with urlopen(Request(run_url, headers=headers), timeout=30) as response:
|
||||||
|
current_run = json.load(response)
|
||||||
|
|
||||||
|
# Ignore stale completion events if a newer attempt has already started.
|
||||||
|
if (current_run['run_attempt'] != event_attempt
|
||||||
|
or current_run['status'] not in ('completed', 'failure', 'timed_out')
|
||||||
|
or current_run['conclusion'] not in ('failure', 'timed_out')
|
||||||
|
or not 1 <= event_attempt <= max_retries):
|
||||||
|
print('No retry needed for this completion event.')
|
||||||
|
else:
|
||||||
|
request = Request(f'{run_url}/rerun', headers=headers, method='POST')
|
||||||
|
with urlopen(request, timeout=30) as response:
|
||||||
|
response.read()
|
||||||
|
print(f'Retrying all jobs: retry {event_attempt}/{max_retries}.')
|
||||||
|
PY
|
||||||
Reference in new issue
Block a user