Skip to content
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

fix(ci): adjust sim conditional logic #3395

Merged
merged 6 commits into from
Jan 23, 2025
Merged
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
37 changes: 37 additions & 0 deletions .github/workflows/reusable-sim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Reusable Sim Workflow
on:
workflow_call:
inputs:
make-target:
description: 'Makefile target to execute'
required: true
type: string
run:
description: 'Whether to run the job or not'
required: true
type: boolean
runs-on:
description: 'The runner to use for the job'
type: string
default: 'ubuntu-22.04'
jobs:
sim:
if: ${{ inputs.run }}
runs-on: ${{ inputs.runs-on }}
strategy:
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
gartnera marked this conversation as resolved.
Show resolved Hide resolved

- name: Install dependencies
run: make runsim

- name: Run ${{ inputs.make-target }}
run: |
make ${{ inputs.make-target }}
73 changes: 37 additions & 36 deletions .github/workflows/sim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- develop
- release/*
pull_request:
types: [opened, synchronize, labeled]
schedule:
Expand All @@ -23,20 +24,19 @@ jobs:
changed-files:
runs-on: ubuntu-latest
outputs:
modified_files: ${{ steps.changes.outputs.modified_files }}
x_changed: ${{ steps.x-changes.outputs.any_changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get changed files in x directory
id: changes
run: |
echo "::set-output name=modified_files::$(git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^x/' | xargs)"
id: x-changes
uses: tj-actions/changed-files@v45
with:
files: x/**

matrix-conditionals:
needs: changed-files
if: |
contains(github.event.pull_request.labels.*.name, 'SIM_TESTS') || needs.changed-files.outputs.modified_files
runs-on: ubuntu-22.04
outputs:
SIM_TEST_NOND: ${{ steps.matrix-conditionals.outputs.SIM_TEST_NOND }}
Expand All @@ -48,11 +48,29 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const makeTargetsInput = context.payload.inputs ? context.payload.inputs['make-targets'] : null;
const defaultTargets = ['test-sim-nondeterminism', 'test-sim-fullappsimulation', 'test-sim-import-export', 'test-sim-after-import'];
let makeTargets = [];
if (context.eventName === 'pull_request') {
const changedFiles = ${{ needs.changed-files.outputs.x_changed }};
const pull_number = context.payload.pull_request.number;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pull_number,
});
const labels = pr.labels.map(label => label.name);
console.log(`labels for ${pull_number}:`, labels);
gartnera marked this conversation as resolved.
Show resolved Hide resolved
console.log(`changedFiles for ${pull_number}:`, changedFiles);

const makeTargets = makeTargetsInput ? makeTargetsInput.split(',') : defaultTargets;
if (changedFiles || labels.includes('SIM_TESTS')) {
makeTargets = defaultTargets;
}
} else {
const makeTargetsInput = context.payload.inputs ? context.payload.inputs['make-targets'] : null;
makeTargets = makeTargetsInput ? makeTargetsInput.split(',') : defaultTargets;
}

console.log('makeTargets: ', makeTargets);
core.setOutput('SIM_TEST_NOND', makeTargets.includes('test-sim-nondeterminism'));
core.setOutput('SIM_TEST_FULL', makeTargets.includes('test-sim-fullappsimulation'));
core.setOutput('SIM_TEST_IMPORT_EXPORT', makeTargets.includes('test-sim-import-export'));
Expand All @@ -61,45 +79,28 @@ jobs:
simulation-tests:
needs:
- matrix-conditionals
if: |
contains(github.event.pull_request.labels.*.name, 'SIM_TESTS') || needs.changed-files.outputs.modified_files
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
include:
- make-target: "test-sim-nondeterminism"
condition: ${{ needs.matrix-conditionals.outputs.SIM_TEST_NOND == 'true' }}
run: ${{ needs.matrix-conditionals.outputs.SIM_TEST_NOND == 'true' }}
- make-target: "test-sim-fullappsimulation"
condition: ${{ needs.matrix-conditionals.outputs.SIM_TEST_FULL == 'true' }}
run: ${{ needs.matrix-conditionals.outputs.SIM_TEST_FULL == 'true' }}
- make-target: "test-sim-import-export"
condition: ${{ needs.matrix-conditionals.outputs.SIM_TEST_IMPORT_EXPORT == 'true' }}
run: ${{ needs.matrix-conditionals.outputs.SIM_TEST_IMPORT_EXPORT == 'true' }}
- make-target: "test-sim-after-import"
condition: ${{ needs.matrix-conditionals.outputs.SIM_TEST_AFTER_IMPORT == 'true' }}
run: ${{ needs.matrix-conditionals.outputs.SIM_TEST_AFTER_IMPORT == 'true' }}
name: ${{ matrix.make-target }}
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Install dependencies
run: make runsim

- name: Run ${{ matrix.make-target }}
if: ${{ matrix.condition }}
run: |
make ${{ matrix.make-target }}

uses: ./.github/workflows/reusable-sim.yml
with:
make-target: ${{ matrix.make-target }}
run: ${{ matrix.run }}
sim-ok:
runs-on: ubuntu-22.04
needs:
- simulation-tests
if: |
contains(github.event.pull_request.labels.*.name, 'SIM_TESTS') || needs.changed-files.outputs.modified_files
runs-on: ubuntu-22.04
if: ${{ !cancelled() }}
steps:
- name: Aggregate Results
run: |
Expand Down
Loading