Skip to content

[DOC][CI] Add spacemit to readme, and update workflow #2381

[DOC][CI] Add spacemit to readme, and update workflow

[DOC][CI] Add spacemit to readme, and update workflow #2381

Workflow file for this run

# 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: "Labelling new pull requests"
# pull_request_target is used so that the workflow runs with write permissions
# even on PRs from forks, allowing labels to be applied.
# This is safe here because no code from the PR is checked out or executed;
# the labeler only reads the list of changed file paths.
on:
pull_request_target:
types:
- opened
- reopened
- ready_for_review
- synchronize
- edited
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- id: labeler
uses: actions/labeler@v7
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
configuration-path: .github/new-prs-labeler.yml
- name: Sync target branch label
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}" # The base branch name of PR
PR_NUMBER="${{ github.event.pull_request.number }}" # The PR number for API calls
# Get all branch names in the repo (dynamically, no hardcoded list needed)
BRANCH_NAMES=$(gh api "repos/$GITHUB_REPOSITORY/branches" --paginate --jq '.[].name')
# Get all labels currently on this PR, with one label per line
CURRENT_LABELS=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json labels --jq '.labels[].name')
# Remove any label that matches a branch name but is not the target branch
while IFS= read -r LABEL; do
if [ "$LABEL" != "$TARGET_BRANCH" ] && echo "$BRANCH_NAMES" | grep -qx "$LABEL"; then
gh pr edit "$PR_NUMBER" --remove-label "$LABEL" --repo "$GITHUB_REPOSITORY" 2>/dev/null || true
fi
done <<< "$CURRENT_LABELS"
# Ensure the target branch label exists (create if needed) and add it
gh label create "$TARGET_BRANCH" --repo "$GITHUB_REPOSITORY" 2>/dev/null || true
gh pr edit "$PR_NUMBER" --add-label "$TARGET_BRANCH" --repo "$GITHUB_REPOSITORY"