Skip to content
Draft
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
108 changes: 108 additions & 0 deletions .github/actions/should-skip-ci-by-labels/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Copyright 2025- FlagOS Contributors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

name: 'Should Skip CI By Labels'
description: 'Determine whether CI should run based on the labels applied to the PR'

inputs:
backend:
description: 'Backend name matching the PR label (e.g. mthreads, nvidia)'
required: true
github-token:
description: 'GitHub token for API access'
required: true
default: ${{ github.token }}

outputs:
should_skip:
description: 'true if the PR only contains doc changes or lacks relevant labels, false if CI should run'
value: ${{ steps.check.outputs.should_skip }}

runs:
using: 'composite'
steps:
- name: Check PR labels
id: check
uses: actions/github-script@v6
with:
github-token: ${{ inputs.github-token }}
script: |
const backend = '${{ inputs.backend }}';
const eventName = context.eventName;

console.log(`🔍 Checking PR labels for backend: ${backend}`);

// 1. Handle non-PR events (e.g., direct push to the main branch)
// Direct pushes do not have PR labels. For safety, default to NOT skipping (i.e., run CI).
if (eventName !== 'pull_request' && eventName !== 'pull_request_target') {
console.log(`⚠️ Event is '${eventName}' (not a PR). Defaulting to run CI.`);
core.setOutput('should_skip', 'false');
return;
}

const prNumber = context.payload.pull_request.number;
let labels = [];
let shouldSkip = false;
const maxRetries = 10; // Maximum number of retries
const delayMs = 1000; // Delay between retries in milliseconds

// 2. Fetch labels with retry mechanism to handle delayed labeling
for (let i = 0; i < maxRetries; i++) {
// Use GitHub API to fetch the latest PR data
const { data: prData } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});

labels = prData.labels.map(label => label.name);
console.log(`[Attempt ${i + 1}/${maxRetries}] Current PR labels:`, labels.join(', ') || '(no labels)');

// If the PR has ANY labels, it means the labeler action has finished.
// We can break the loop and proceed to evaluation.
if (labels.length > 0) {
console.log('✅ Labeling completed. Proceeding to evaluation.');
break;
}

// If it's the last attempt, don't wait
if (i < maxRetries - 1) {
console.log(`⏳ No labels found yet. Waiting ${delayMs / 1000}s before retrying...`);
await new Promise(resolve => setTimeout(resolve, delayMs));
}
}

// 3. Evaluation logic with short-circuit evaluation
if (labels.includes('DOC')) {
console.log("🛑 Found 'DOC' label. All changes are documentation. Will safely skip CI.");
shouldSkip = true;
} else if (labels.includes(backend)) {
console.log(`✅ Found backend label '${backend}'. Will run CI.`);
shouldSkip = false;
} else if (labels.includes('CORE')) {
console.log("✅ Found 'CORE' label. Core files changed, will run CI.");
shouldSkip = false;
} else {
console.log(`🛑 No relevant labels (DOC, ${backend}, or CORE) found after retries. Will safely skip CI.`);
shouldSkip = true;
}

// Output the final result
core.setOutput('should_skip', shouldSkip ? 'true' : 'false');
65 changes: 34 additions & 31 deletions .github/new-prs-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# SOFTWARE.

# ==========================================
# 1. Core File Labels (CORE)
# Core File Labels (CORE)
# Includes core framework code and specific
# third-party core libraries.
# ==========================================
Expand Down Expand Up @@ -47,7 +47,7 @@ CORE:
- '.github/workflows/code-format-check.yml'

# ==========================================
# 2. CI/CD Labels
# CI/CD Labels
# Applied if any file under .github/workflows
# or .github/actions is modified.
# ==========================================
Expand All @@ -63,25 +63,43 @@ CI/CD:
- 'packaging/**'

# ==========================================
# 3. Documentation Labels (DOC)
# Applied if the PR contains modifications to
# any of the following file types.
# Doc Only Label
# Rule: Applied only if ALL changed files
# are documentation files, EXCLUDING CMakeLists.txt.
# ==========================================
DOC:
- all:
- changed-files:
- any-glob-to-all-files:
- '**/*.md'
- '**/*.txt'
- '**/*.rst'
- '**/*.png'
- '**/*.jpg'
- '**/*.jpeg'
- '**/*.gif'
- '**/*.ico'
- 'LICENSE'
- all-globs-to-all-files:
- '!**/CMakeLists.txt'

# ====================================================================================
# TLE Labels
# Rule: Applied if any file path contains 'tle', 'TLE', or 'Tle'
# NOTE: Only matches these exact case patterns, not 'tLe', 'tlE', 'TlE', 'tLE', etc.
# ====================================================================================
TLE:
- changed-files:
- any-glob-to-any-file:
- '**/*.md'
- '**/*.txt'
- '**/*.rst'
- '**/*.png'
- '**/*.jpg'
- '**/*.jpeg'
- '**/*.gif'
- '**/*.ico'
- 'LICENSE'
- '**/tle/**'
- '**/TLE/**'
- '**/Tle/**'
- '**/*tle*'
- '**/*TLE*'
- '**/*Tle*'

# ==========================================
# 4. Git Configuration Labels (GIT)
# Git Configuration Labels (GIT)
# Applied if Git-related configuration files are modified.
# ==========================================
GIT:
Expand All @@ -96,7 +114,7 @@ GIT:
- '.pre-commit-config.yaml'

# ==========================================
# 5. Backend Labels
# Backend Labels
# Rule: Applied if files under third_party/{backend}
# or .github/workflows/{backend}* are modified.
# ==========================================
Expand Down Expand Up @@ -208,18 +226,3 @@ xpu:
- any-glob-to-any-file:
- 'third_party/xpu/**'
- '.github/workflows/xpu*'

# ====================================================================================
# 6. TLE Labels
# Rule: Applied if any file path contains 'tle', 'TLE', or 'Tle'
# NOTE: Only matches these exact case patterns, not 'tLe', 'tlE', 'TlE', 'tLE', etc.
# ====================================================================================
TLE:
- changed-files:
- any-glob-to-any-file:
- '**/tle/**'
- '**/TLE/**'
- '**/Tle/**'
- '**/*tle*'
- '**/*TLE*'
- '**/*Tle*'
16 changes: 11 additions & 5 deletions .github/workflows/mthreads3.6-build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
mthreads36x-unit-test:
runs-on: mthreads3.6
if: ${{ github.repository == 'FlagTree/flagtree' || github.repository == 'flagos-ai/flagtree' }}

# Add permissions to read PR information (required for fetching labels)
permissions:
contents: read
pull-requests: read

steps:
- name: Setup environment
shell: bash
Expand All @@ -46,22 +52,22 @@ jobs:
with:
checkout_version: 'v6'

- name: Check if backend-relevant files changed
id: check_backend
uses: flagos-ai/FlagTree/.github/actions/check-backend-changed@main
- name: Check if CI should run based on PR labels
id: check_labels
uses: ./.github/actions/should-skip-ci-by-labels
with:
backend: mthreads

- name: Build FlagTree
if: steps.check_backend.outputs.should_skip != 'true'
if: steps.check_labels.outputs.should_skip != 'true'
shell: bash
run: |
set -x
export FLAGTREE_BACKEND=mthreads
MAX_JOBS=32 python3 -m pip install . --no-build-isolation

- name: Unit Test
if: steps.check_backend.outputs.should_skip != 'true'
if: steps.check_labels.outputs.should_skip != 'true'
shell: bash
run: |
set -x
Expand Down
Loading