CI Pipeline #1
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: CI Pipeline | |
on: | |
workflow_dispatch: | |
jobs: | |
verify_commit: | |
runs-on: ubuntu-latest | |
name: Verify latest commit | |
outputs: | |
RUN_BUILD: ${{ steps.verify_commit.outputs.RUN_BUILD }} | |
steps: | |
- uses: actions/checkout@v3 | |
- id: verify_commit | |
name: Verify latest commit is less than 24 hours | |
run: echo '::set-output name=RUN_BUILD::'$(test -n "$(git log --format=%H --since='24 hours ago')" && echo 'true' || echo 'false') | |
build: | |
runs-on: ubuntu-latest | |
needs: verify_commit | |
if: ${{ needs.verify_commit.outputs.RUN_BUILD == 'true' }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Print successful build message | |
run: echo "Build job was successful!" | |
check_status: | |
runs-on: ubuntu-latest | |
needs: verify_commit | |
if: ${{ needs.verify_commit.outputs.RUN_BUILD == 'false' }} | |
steps: | |
- name: Check last workflow status | |
id: check_status | |
run: | | |
workflow_filename="random-success-failure.yml" | |
last_workflow=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/$workflow_filename/runs?per_page=1" | jq -r '.workflow_runs[0]') | |
conclusion=$(echo $last_workflow | jq -r '.conclusion') | |
echo "conclusion=$conclusion" >> $GITHUB_ENV | |
- name: Print and handle the status | |
run: | | |
echo "The status of the last workflow run is: ${{ env.conclusion }}" | |
if [ "${{ env.conclusion }}" != "success" ]; then | |
echo "The last workflow did not succeed. Failing this workflow." | |
exit 1 | |
else | |
echo "The last workflow succeeded. This workflow will succeed." | |
fi |