Skip to content
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
166 changes: 144 additions & 22 deletions .github/workflows/filter-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ on:
jobs:
filter_build:
runs-on: ubuntu-latest
strategy:
matrix:
sofa_version: [master, v24.12]
### if: ${{ github.repository_owner == 'sofa-framework' }}
outputs:
SOFA_BRANCH_NAME: ${{ steps.export-vars.outputs.SOFA_BRANCH_NAME }}
SOFA_COMMIT_SHA: ${{ steps.export-vars.outputs.SOFA_COMMIT_SHA }}
Expand Down Expand Up @@ -111,8 +107,9 @@ jobs:
BUILDER_OS=${{ github.event.inputs.builder_os }}

# Validate branch format (e.g., v25.06)
if [[ ! "$BRANCH" =~ ^v[0-9]{2}\.[0-9]{2}$ ]]; then
echo "Error: Invalid branch name format: $BRANCH"
if [ [ ! "$BRANCH" =~ ^v[0-9]{2}\.[0-9]{2}$ ] && [ "$BRANCH" != "master" ] ]; then
echo "Error: Invalid branch name format: $BRANCH."
echo "Branch name should be either master or any release branch (e.g., v25.06)"
exit 1
fi
echo "Branch name $BRANCH is valid."
Expand Down Expand Up @@ -181,17 +178,7 @@ jobs:
- name: Check out code
uses: actions/checkout@v2

- name: Run when nightly
if: github.event.schedule == '0 2 * * *'
run: |
echo "This step runs only for nightly builds."
echo "SOFA_BRANCH_NAME=${{ matrix.sofa_version }}" >> $GITHUB_ENV
echo "PRESET=standard" >> $GITHUB_ENV
echo "WITH_ALL_TESTS=true" >> $GITHUB_ENV
echo "GENERATE_BINARIES=true" >> $GITHUB_ENV
echo 'BUILDER_OS=["sh-ubuntu_gcc_release","sh-windows_vs2022_release","sh-macos_clang_release"]' >> $GITHUB_ENV

- name: Check push on master case
- name: Check push on master case (e.g. merge)
if: ${{ github.event_name == 'push'}}
run: |
echo "This step runs only for push on the master branch."
Expand All @@ -200,8 +187,46 @@ jobs:
echo "FORCE_FULL_BUILD=true" >> $GITHUB_ENV
echo 'BUILDER_OS=["sh-ubuntu_gcc_release","sh-ubuntu_clang_release","sh-ubuntu_clang_debug","sh-fedora_clang_release","sh-windows_vs2022_release","sh-macos_clang_release"]' >> $GITHUB_ENV

- name: Run when PR is opened
if: ${{ github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'synchronize') }}
- name: Check in a PR when a commit is pushed or when a comment is created or edited
if: ${{ (github.event_name == 'pull_request' && github.event.action == 'synchronize') || (github.event_name == 'issue_comment' && github.event.issue.pull_request ) }}
uses: actions/github-script@v7
with:
script: |
const currentRunId = context.runId;
const workflowName = context.workflow;
const prNumber = ${{ github.event.pull_request.number }};

const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
status: 'in_progress'
});

const matchingRuns = runs.data.workflow_runs.filter(run => {
return run.name === workflowName &&
run.id !== currentRunId &&
run.head_branch === "${{ github.event.pull_request.head.ref }}";
});

for (const run of matchingRuns) {
console.log(`Cancelling previous run: ${run.id}`);
await github.rest.actions.cancelWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: run.id
});
}

if (matchingRuns.length > 0) {
console.log("Sleeping for 5 seconds to allow previous runs to cancel...");
await new Promise(resolve => setTimeout(resolve, 5000));
} else {
console.log("No previous runs to cancel. Continuing...");
}

- name: Run when PR is opened or a commit is pushed in a PR
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
Expand All @@ -212,9 +237,9 @@ jobs:

# Trigger the Build action
python scripts/github_CI/checkPRInfoBeforeBuild.py
- name: Run when PR comment is edited
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request && ( github.event.action == 'created'|| github.event.action == 'edited' ) }}

- name: Run when PR comment is created or edited
if: ${{ github.event_name == 'issue_comment' && github.event.issue.pull_request }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.issue.pull_request.number }}
Expand All @@ -230,6 +255,102 @@ jobs:
python scripts/github_CI/checkPRInfoBeforeBuild.py
fi

echo "PR_NUMBER=${PR_NUMBER}"
echo "OWNER_NAME=${OWNER_NAME}"
echo "PR_COMMIT_SHA=${PR_COMMIT_SHA}"
echo "github.event.issue.number=${github.event.issue.number}"
echo "github.event.issue.pull_request=${github.event.issue.pull_request}"
echo "github.event.issue=${github.event.issue}"


- name: Export environment variables as outputs
id: export-vars
run: |
# Validate branch format (e.g., v25.06)
if [ [ ! "$SOFA_BRANCH_NAME" =~ ^v[0-9]{2}\.[0-9]{2}$ ] && [ "$SOFA_BRANCH_NAME" != "master" ] ]; then
echo "Error: Invalid branch name format: $SOFA_BRANCH_NAME."
echo "Branch name should be either master or any release branch (e.g., v25.06)"
exit 1
fi

echo "SOFA_BRANCH_NAME=${SOFA_BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "SOFA_COMMIT_SHA=${SOFA_COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "PRESET=${PRESET}" >> $GITHUB_OUTPUT
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_OUTPUT
echo "CI_DEPENDS_ON=${CI_DEPENDS_ON}" >> $GITHUB_OUTPUT
echo "WITH_ALL_TESTS=${WITH_ALL_TESTS}" >> $GITHUB_OUTPUT
echo "FORCE_FULL_BUILD=${FORCE_FULL_BUILD}" >> $GITHUB_OUTPUT
echo "OUT_OF_TREE_BUILD=${OUT_OF_TREE_BUILD}" >> $GITHUB_OUTPUT
echo "GENERATE_BINARIES=${GENERATE_BINARIES}" >> $GITHUB_OUTPUT
echo "PR_OWNER_URL=${PR_OWNER_URL}" >> $GITHUB_OUTPUT
echo "PR_BRANCH_NAME=${PR_BRANCH_NAME}" >> $GITHUB_OUTPUT
echo "PR_COMMIT_SHA=${PR_COMMIT_SHA}" >> $GITHUB_OUTPUT
echo "BUILDER_OS=${BUILDER_OS}" >> $GITHUB_OUTPUT




nightly_build:
runs-on: ubuntu-latest
if: github.event.schedule == '0 2 * * *'
strategy:
matrix:
sofa_version: [master, v24.12]
### if: ${{ github.repository_owner == 'sofa-framework' }}
outputs:
SOFA_BRANCH_NAME: ${{ steps.export-vars.outputs.SOFA_BRANCH_NAME }}
SOFA_COMMIT_SHA: ${{ steps.export-vars.outputs.SOFA_COMMIT_SHA }}
PRESET: ${{ steps.export-vars.outputs.PRESET }}
PYTHON_VERSION: ${{ steps.export-vars.outputs.PYTHON_VERSION }}
CI_DEPENDS_ON: ${{ steps.export-vars.outputs.CI_DEPENDS_ON }}
WITH_ALL_TESTS: ${{ steps.export-vars.outputs.WITH_ALL_TESTS }}
FORCE_FULL_BUILD: ${{ steps.export-vars.outputs.FORCE_FULL_BUILD }}
OUT_OF_TREE_BUILD: ${{ steps.export-vars.outputs.OUT_OF_TREE_BUILD }}
GENERATE_BINARIES: ${{ steps.export-vars.outputs.GENERATE_BINARIES }}
PR_OWNER_URL: ${{ steps.export-vars.outputs.PR_OWNER_URL }}
PR_BRANCH_NAME: ${{ steps.export-vars.outputs.PR_BRANCH_NAME }}
PR_COMMIT_SHA: ${{ steps.export-vars.outputs.PR_COMMIT_SHA }}
BUILDER_OS: ${{ steps.export-vars.outputs.BUILDER_OS }}

steps:
- name: Default values of environment variables
run: |
echo "SOFA_BRANCH_NAME=master" >> $GITHUB_ENV # SOFA_BRANCH_NAME: "master"
echo "SOFA_COMMIT_SHA=HEAD" >> $GITHUB_ENV # SOFA_COMMIT_SHA: "HEAD"
echo "PRESET=full" >> $GITHUB_ENV # PRESET: "full"
echo "PYTHON_VERSION=3.12" >> $GITHUB_ENV # PYTHON_VERSION: "3.12"
echo "CI_DEPENDS_ON=" >> $GITHUB_ENV # CI_DEPENDS_ON: ""
echo "WITH_ALL_TESTS=false" >> $GITHUB_ENV # WITH_ALL_TESTS: false
echo "FORCE_FULL_BUILD=false" >> $GITHUB_ENV # FORCE_FULL_BUILD: false
echo "OUT_OF_TREE_BUILD=" >> $GITHUB_ENV # OUT_OF_TREE_BUILD: ""
echo "GENERATE_BINARIES=false" >> $GITHUB_ENV # GENERATE_BINARIES: false
echo "PR_OWNER_URL=" >> $GITHUB_ENV # PR_OWNER_URL: ""
echo "PR_BRANCH_NAME=" >> $GITHUB_ENV # PR_BRANCH_NAME: ""
echo "PR_COMMIT_SHA=HEAD" >> $GITHUB_ENV # PR_COMMIT_SHA: "HEAD"
echo 'BUILDER_OS=["sh-ubuntu_gcc_release"]' >> $GITHUB_ENV # BUILDER_OS: ["sh-ubuntu_gcc_release"]

- name: Set up python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install pip packages
run: |
pip install python-graphql-client
pip install requests

- name: Check out code
uses: actions/checkout@v2

- name: Run when nightly
run: |
echo "This step runs only for nightly builds."
echo "SOFA_BRANCH_NAME=${{ matrix.sofa_version }}" >> $GITHUB_ENV
echo "PRESET=standard" >> $GITHUB_ENV
echo "WITH_ALL_TESTS=true" >> $GITHUB_ENV
echo "GENERATE_BINARIES=true" >> $GITHUB_ENV
echo 'BUILDER_OS=["sh-ubuntu_gcc_release","sh-windows_vs2022_release","sh-macos_clang_release"]' >> $GITHUB_ENV

- name: Export environment variables as outputs
id: export-vars
run: |
Expand All @@ -249,6 +370,7 @@ jobs:




# ===============================================================
# ===============================================================

Expand Down
6 changes: 3 additions & 3 deletions scripts/github_CI/checkPRInfoBeforeBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ def extract_ci_depends_on():

# Ensure the URL is in the expected dependency format, e.g. https://github.com/sofa-framework/Sofa.Qt/pull/6
parts = dependency.split('/')
if len(parts) != 6 or parts[0] != 'https:' or parts[1] != '' or parts[2] != 'github.com':
if len(parts) != 7 or parts[0] != 'https:' or parts[1] != '' or parts[2] != 'github.com':
raise ValueError("")
print(f"Invalid URL ci-depends-on format: {dependency}")
exit(1)

owner = parts[3]
repo = parts[4]
pull_number = parts[5]
pull_number = parts[6]
dependency_request_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}"

response = requests.get(dependency_request_url, headers=HEADERS)
Expand All @@ -179,7 +179,7 @@ def extract_ci_depends_on():

dependency_pr_data = response.json()

key = dependency_pr_data['repo']['name'] #Sofa.Qt
key = dependency_pr_data['head']['repo']['name'] #Sofa.Qt
repo_url = dependency_pr_data['html_url'] #https://github.com/sofa-framework/Sofa.Qt
branch_name = dependency_pr_data['head']['ref'] #my_feature_branch

Expand Down
Loading