Skip to content
Closed
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
82 changes: 82 additions & 0 deletions .github/workflows/safe-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

name: Safe Upstream Sync

on:
schedule:
- cron: '0 3 * * *' # Runs daily at 03:00 UTC
workflow_dispatch: # Allows manual trigger

jobs:
safe-sync:
runs-on: ubuntu-latest

steps:
# -----------------------
# Checkout fork (full history)
# -----------------------
- name: Checkout fork
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0 # full clone to avoid origin/ ambiguity
ref: master

# -----------------------
# Setup Git & upstream
# -----------------------
- name: Setup Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git remote add upstream https://github.com/sonic-net/sonic-buildimage.git
git fetch upstream master --depth=0

# -----------------------
# Attempt safe merge
# -----------------------
- name: Attempt safe merge
id: merge
run: |
set -e
SYNC_STATUS="success"
git checkout master

if git merge --no-commit --no-ff upstream/master; then
git commit -m "Auto-sync from upstream/master"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/nexthop-ai/sonic-buildimage.git master
else
git merge --abort
SYNC_STATUS="conflict"
echo "Merge conflict detected. Sync aborted."
fi

echo "SYNC_STATUS=$SYNC_STATUS" >> $GITHUB_ENV

# -----------------------
# Notify Slack after sync
# -----------------------
- name: Notify Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
BRANCH_NAME: master
REPO_URL: https://github.com/nexthop-ai/sonic-buildimage
run: |
if [ "$SYNC_STATUS" == "success" ]; then
STATUS_MESSAGE="✅ Auto-sync completed successfully"
else
STATUS_MESSAGE="⚠️ Auto-sync aborted due to merge conflicts"
fi

curl -X POST -H 'Content-type: application/json' \
--data '{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "'"$STATUS_MESSAGE"'\nBranch: '"$BRANCH_NAME"'\nRepo: <'"$REPO_URL"'|View Repo>\nCommit SHA: '"$GITHUB_SHA"'"
}
}
]
}' $SLACK_WEBHOOK_URL

58 changes: 58 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package(default_visibility = ["//visibility:public"])

# SONiC Linux Headers
# This rule provides the Linux kernel headers used by SONiC
# Based on the sonic-linux-kernel package defined in rules/linux-kernel.mk
genrule(
name = "sonic_linux_headers",
srcs = [
"rules/linux-kernel.mk",
"rules/linux-kernel.dep",
] + glob([
"src/sonic-linux-kernel/**",
], exclude = [
"**/*.git/**",
"**/.*",
"**/*.md",
]),
outs = ["sonic_linux_headers.tar.gz"],
cmd = """
echo "=== Building SONiC Linux Headers ==="

# Extract kernel version information from linux-kernel.mk
KVERSION_SHORT=$$(grep "^KVERSION_SHORT = " $(location rules/linux-kernel.mk) | cut -d' ' -f3)
KERNEL_VERSION=$$(grep "^KERNEL_VERSION = " $(location rules/linux-kernel.mk) | cut -d' ' -f3)
KERNEL_SUBVERSION=$$(grep "^KERNEL_SUBVERSION = " $(location rules/linux-kernel.mk) | cut -d' ' -f3)

echo "Kernel version: $$KVERSION_SHORT, $$KERNEL_VERSION-$$KERNEL_SUBVERSION"

# Create a temporary directory for the headers
HEADERS_DIR=$$(mktemp -d)

# Copy all source files to the headers directory
for file in $(SRCS); do
# Skip if it's one of the config files (handle them separately)
if [[ "$$file" == *"rules/linux-kernel.mk" ]] || [[ "$$file" == *"rules/linux-kernel.dep" ]]; then
cp "$$file" "$$HEADERS_DIR/"
continue
fi

# For sonic-linux-kernel files, preserve directory structure
if [[ "$$file" == *"src/sonic-linux-kernel/"* ]]; then
# Extract the relative path after src/sonic-linux-kernel/
rel_path=$${file#*src/sonic-linux-kernel/}
target_dir=$$HEADERS_DIR/src/sonic-linux-kernel/$$(dirname "$$rel_path")
mkdir -p "$$target_dir"
cp "$$file" "$$target_dir/"
fi
done

# Create the output tar.gz file
tar -czf $@ -C $$HEADERS_DIR .

# Clean up
rm -rf $$HEADERS_DIR

echo "=== SONiC Linux Headers package created ==="
""",
)