Skip to content

Dynamically set job inputs #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 74 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,93 @@ on:
pull_request:

jobs:
test-ref:
changes:
runs-on: ubuntu-latest
if: github.event_name == 'merge_group'
outputs:
packages: ${{ steps.get-packages.outputs.packages }}
steps:
- uses: actions/checkout@v4
- name: Print branch names
run: |
echo "Head ref: ${{ github.event.merge_group.head_ref }}"
echo "Base ref: ${{ github.event.merge_group.base_ref }}"
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
ref: ${{ github.event.merge_group.base_ref }}
filters: |
aptos:
- 'aptos/**'
ethereum:
- 'ethereum/**'
- name: Get list of changed packages
id: get-packages
run: |
PACKAGES=$(echo '${{ steps.filter.outputs.changes }}' | jq -c '.')
echo "packages=$PACKAGES" | tee -a "$GITHUB_OUTPUT"

test-ref-b:
# Test job that runs for each changed package
test:
needs: changes
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
if: ${{ needs.changes.outputs.packages != '[]' && needs.changes.outputs.packages != '' }}
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.changes.outputs.packages) }}
steps:
- uses: actions/checkout@v4
- name: Print branch name
- name: Run tests for ${{ matrix.package }}
run: |
echo "Base ref: ${{ github.base_ref }}"
# Run your tests here
echo "Testing ${{ matrix.package }}"

check-job-results:
if: always()
needs: [test-ref, test-ref-b]
needs: [changes, test]
runs-on: ubuntu-latest
steps:
- name: Check job results
id: check-results
- name: Check
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
if [[ "${{ needs.changes.outputs.packages }}" == "[]" || "${{ needs.changes.outputs.packages }}" == "" ]]; then
echo "No test jobs were run because no paths were changed."
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
echo "Test jobs were run. Checking results..."
# Check the result of the test jobs
if [[ "${{ needs.test.result }}" == "failure" ]]; then
echo "One or more test jobs failed"
exit 1
else
echo "All test jobs succeeded"
exit 0
fi
fi

# - name: Check job results
# id: check-results
# run: |
# # Convert JSON array to Bash array
# mapfile -t job_names < <(echo '${{ fromJson(needs.changes.outputs.jobs) }}')
#
# # Create associative array of job results
# declare -A job_results
# for job in "${job_names[@]}"; do
# job_results["$job"]=$(eval echo "\${{ needs.changes.${job}.result }}")
# done
#
# # 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
1 change: 1 addition & 0 deletions aptos/tmp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Test change