Skip to content

Commit

Permalink
Add unified status check (#93)
Browse files Browse the repository at this point in the history
* Add unified status check

* Test failure

* f

* f

* Prep for merge
  • Loading branch information
samuelburnham authored Nov 1, 2024
1 parent aab977c commit 80bb1fb
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,60 @@ on:
jobs:
test-ref:
runs-on: ubuntu-latest
if: github.event_name == 'merge_group'
steps:
- uses: actions/checkout@v4
- name: Print branch names
if: github.event_name == 'merge_group'
run: |
echo "Head ref: ${{ github.event.merge_group.head_ref }}"
echo "Base ref: ${{ github.event.merge_group.base_ref }}"
echo "Base ref 2: ${{ github.base_ref }}"
exit 1
- uses: actions/checkout@v4
if: github.event_name == 'merge_group'
with:
ref: ${{ github.event.merge_group.base_ref }}

test-ref-b:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Print branch name
run: |
echo "Base ref: ${{ github.base_ref }}"
check-job-results:
if: always()
needs: [test-ref, test-ref-b]
runs-on: ubuntu-latest
steps:
- name: Check job results
id: check-results
run: |
# Create an associative array of job statuses
declare -A job_results=(
["test-ref"]="${{ needs.test-ref.result }}"
["test-ref-b"]="${{ needs.test-ref-b.result }}"
)
# Iterate through jobs and get their results
failed_count=0
for job in "${!job_results[@]}"; do
RESULT=${job_results[$job]}
if [[ "$RESULT" == "failure" ]]; then
failed_count=$((failed_count + 1))
fi
echo "$job result: $RESULT"
done
if [ "$failed_count" -gt 0 ]; then
echo "Some jobs failed"
echo "result=failure" | tee -a $GITHUB_OUTPUT
else
echo "All jobs succeeded or were skipped"
echo "result=success" | tee -a $GITHUB_OUTPUT
fi
- name: Error on job failure
run: |
if [[ "${{ steps.check-results.outputs.result }}" == "failure" ]]; then
exit 1
fi

0 comments on commit 80bb1fb

Please sign in to comment.