TestWFRunStatus #37
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: TestWFRunStatus | |
on: | |
workflow_dispatch: | |
# scheduled run every Friday at 19.00 (18.00 UTC) | |
schedule: | |
- cron: '40 16 * * 3' | |
- cron: '45 16 * * 3' | |
- cron: '50 16 * * 3' | |
jobs: | |
test_previous_run: | |
runs-on: ubuntu-latest | |
steps: | |
- name: trace init | |
# if: github.event.schedule == '40 16 * * 3' | |
run: | | |
echo "testing wf run - failure" | |
exit 0 | |
# Step per ottenere le informazioni dell'ultima esecuzione | |
- name: Get last workflow run | |
id: get_last_run | |
# if: github.event.schedule != '40 16 * * 3' | |
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); | |
- name: print the status | |
run: echo "${{steps.get_last_run.outputs.conclusion}}" | |
# Step per controllare lo stato | |
- name: Check workflow result | |
# if: ${{ github.event.schedule != '40 16 * * 3' && steps.get_last_run.outputs.conclusion == 'success' }} | |
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 | |
# Step uscita | |
- name: Terminate workflow | |
run: echo "Terminating with success" | |