CheckWFRunStatus #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CheckWFRunStatus | |
on: | |
workflow_dispatch: | |
jobs: | |
test_previous_run: | |
runs-on: ubuntu-latest | |
steps: | |
# Step per ottenere le informazioni dell'ultima esecuzione | |
- name: Get last workflow run | |
id: get_last_run | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const response = await github.rest.actions.listWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'test_wf_run_status.yml', | |
per_page: 1, | |
}); | |
const lastRun = response.data.workflow_runs[0]; | |
console.log('\n\n-------------------------\n') | |
console.log('WORKFLOW RUNS: \n') | |
console.log(response.data.workflow_runs) | |
console.log('\n\n-------------------------\n') | |
console.log('Response: \n') | |
console.log(lastRun) | |
console.log(lastRun.conclusion) | |
core.setOutput('conclusion', lastRun.conclusion); | |
core.setOutput('run_id', lastRun.id) | |
- name: print the status | |
run: | | |
echo "${{steps.get_last_run.outputs.conclusion}}" | |
echo "${{steps.get_last_run.outputs.run_id}}" | |
# Step per controllare lo stato | |
# - name: Check workflow result | |
# if: ${{ steps.get_last_run.outputs.conclusion == 'success' }} | |
# run: | | |
# echo "Previous run was successful. No need to run the workflow today." | |
# exit 0 # Stop workflow run | |
- name: Re run last workflow | |
id: re_run_wf | |
# # if: ${{ steps.get_last_run.outputs.conclusion != 'success' }} | |
uses: actions/github-script@v6 | |
env: | |
LAST_RUN_ID: ${{ steps.get_last_run.outputs.run_id }} | |
with: | |
script: | | |
console.log('In the re run last workflow step') | |
const { LAST_RUN_ID } = process.env | |
console.log(`Input run id: ${LAST_RUN_ID}`) | |
const response = await github.rest.actions.createWorkflowDispatch({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: 'import_truth.yml', | |
ref = 'main', | |
}); | |
console.log('\n\n-------------------------\n') | |
console.log('RERUNNING WORKFLOW: \n') | |
console.log(response) | |
console.log('\n\n-------------------------\n') | |
# Step uscita | |
- name: Terminate workflow | |
run: echo "Terminating with success" | |