Skip to content

Nightly Upstream Sync #41

Nightly Upstream Sync

Nightly Upstream Sync #41

name: Nightly Upstream Sync
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
force_update:
description: 'Force update even if no changes detected'
type: boolean
default: false
permissions:
contents: write
pull-requests: write
actions: write
env:
DEBFULLNAME: "GitHub Actions Bot"
DEBEMAIL: "41898282+github-actions[bot]@users.noreply.github.com"
jobs:
sync-upstream:
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# Use a PAT if available to allow PR to trigger CI workflows
# Without this, PRs created by GITHUB_TOKEN won't trigger other workflows
token: ${{ secrets.WORKFLOW_PAT || github.token }}
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y git devscripts debhelper dh-dkms dkms
- name: Configure git user
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Clone upstream repositories
run: |
set -e
echo "=== Cloning upstream repositories ==="
KERNEL_REPO="https://gitlab.freedesktop.org/drm/misc/kernel.git"
KERNEL_BRANCH="drm-misc-fixes"
FIRMWARE_REPO="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git"
FIRMWARE_BRANCH="main"
echo "Cloning drm-kernel (shallow)..."
git clone --depth 1 --branch $KERNEL_BRANCH $KERNEL_REPO drm-kernel
echo "Cloning linux-firmware (shallow)..."
git clone --depth 1 --branch $FIRMWARE_BRANCH $FIRMWARE_REPO linux-firmware
echo "✓ Upstream repositories cloned"
- name: Store upstream commit metadata
id: upstream
run: |
set -e
echo "=== Storing upstream metadata ==="
CURRENT_VERSION=$(dpkg-parsechangelog -S Version)
echo "Current package version: $CURRENT_VERSION"
# Extract commit from version: 7.0.0-rc1+git20260226.36d9579fe-1 -> 36d9579fe
CURRENT_KERNEL_COMMIT=$(echo "$CURRENT_VERSION" | sed -n 's/.*+git[0-9]*\.\([a-f0-9]*\)-.*/\1/p')
if [ -z "$CURRENT_KERNEL_COMMIT" ]; then
CURRENT_KERNEL_COMMIT="unknown"
fi
echo "Current kernel commit (from changelog): $CURRENT_KERNEL_COMMIT"
cd drm-kernel
UPSTREAM_KERNEL_COMMIT_FULL=$(git rev-parse HEAD)
UPSTREAM_KERNEL_COMMIT=$(git rev-parse --short HEAD)
echo "Upstream kernel commit: $UPSTREAM_KERNEL_COMMIT"
cd ..
echo "old_kernel_commit=$CURRENT_KERNEL_COMMIT" >> $GITHUB_OUTPUT
echo "new_kernel_commit=$UPSTREAM_KERNEL_COMMIT_FULL" >> $GITHUB_OUTPUT
CURRENT_FIRMWARE_COMMIT=$(dpkg-parsechangelog -S Changes | grep -oP 'Firmware commit: \K[a-f0-9]+' | head -1 || echo "unknown")
echo "Current firmware commit (from changelog): $CURRENT_FIRMWARE_COMMIT"
cd linux-firmware
UPSTREAM_FIRMWARE_COMMIT=$(git rev-parse HEAD)
UPSTREAM_FIRMWARE_COMMIT_SHORT=$(git rev-parse --short HEAD)
echo "Upstream firmware commit: $UPSTREAM_FIRMWARE_COMMIT_SHORT"
echo "old_firmware_commit=$CURRENT_FIRMWARE_COMMIT" >> $GITHUB_OUTPUT
echo "new_firmware_commit=$UPSTREAM_FIRMWARE_COMMIT" >> $GITHUB_OUTPUT
cd ..
- name: Run update script
id: update
run: |
set -e
echo "=== Running update-from-upstream.sh ==="
./scripts/update-from-upstream.sh 2>&1 | tee update.log
echo "✓ Update script completed successfully"
- name: Add firmware tracking to changelog
run: |
set -e
echo "=== Adding firmware tracking to changelog ==="
cd linux-firmware
FIRMWARE_COMMIT=$(git rev-parse --short HEAD)
cd ..
dch --append "Firmware commit: $FIRMWARE_COMMIT"
echo "✓ Firmware commit added to changelog"
- name: Update version-dependent files
run: |
set -e
echo "=== Updating version-dependent files ==="
PKG_VERSION=$(dpkg-parsechangelog -S Version)
# Remove debian revision (e.g., -1) to get the upstream version
UPSTREAM_VERSION=$(echo "$PKG_VERSION" | sed 's/-[0-9]*$//')
echo "Package version: $PKG_VERSION"
echo "Upstream version: $UPSTREAM_VERSION"
# Update dkms.conf
if [ -f src/amdxdna/dkms.conf ]; then
echo "Updating src/amdxdna/dkms.conf..."
sed -i "s/^PACKAGE_VERSION=.*/PACKAGE_VERSION=\"$UPSTREAM_VERSION\"/" src/amdxdna/dkms.conf
echo "✓ Updated dkms.conf"
else
echo "✗ src/amdxdna/dkms.conf not found"
exit 1
fi
# Update debian/amdxdna-dkms.install
if [ -f debian/amdxdna-dkms.install ]; then
echo "Updating debian/amdxdna-dkms.install..."
sed -i "s|usr/src/amdxdna-[^ ]*|usr/src/amdxdna-$UPSTREAM_VERSION|g" debian/amdxdna-dkms.install
echo "✓ Updated amdxdna-dkms.install"
else
echo "✗ debian/amdxdna-dkms.install not found"
exit 1
fi
echo ""
echo "=== Verifying updates ==="
echo "dkms.conf:"
grep "^PACKAGE_VERSION=" src/amdxdna/dkms.conf
echo ""
echo "amdxdna-dkms.install:"
cat debian/amdxdna-dkms.install
echo ""
echo "✓ All version-dependent files updated"
- name: Detect if there are actual changes
id: detect
run: |
set -e
echo "=== Checking for driver/firmware changes ==="
# Check if src/ or firmware/ directories have changes
# Exclude metadata files (dkms.conf, changelog, install files)
# Only count actual source/firmware file changes
if git diff --quiet -- src/ firmware/ ':!src/amdxdna/dkms.conf' 2>/dev/null; then
echo "✗ No driver or firmware changes detected"
echo "Changes were only in changelog/metadata"
HAS_UPDATES="false"
else
echo "✓ Driver or firmware changes detected:"
git diff --name-only -- src/ firmware/ ':!src/amdxdna/dkms.conf' 2>/dev/null || true
HAS_UPDATES="true"
fi
if [ "${{ github.event.inputs.force_update }}" = "true" ]; then
echo "⚠ Force update requested"
HAS_UPDATES="true"
fi
echo "has_updates=$HAS_UPDATES" >> $GITHUB_OUTPUT
echo "Has updates: $HAS_UPDATES"
- name: Early exit if no updates
if: steps.detect.outputs.has_updates != 'true'
run: |
echo "✓ No file changes after sync. Exiting gracefully."
echo "Run workflow manually with force_update=true to force a PR."
- name: Verify changes
if: steps.detect.outputs.has_updates == 'true'
run: |
set -e
echo "=== Verifying changes ==="
if git diff --name-only | grep -q "debian/changelog"; then
echo "✓ debian/changelog was updated"
else
echo "✗ debian/changelog was not updated - script may have failed"
exit 1
fi
if git diff --name-only | grep -q "^src/"; then
echo "✓ src/ directory was updated"
else
echo "⚠ src/ directory was not updated - checking if this is expected..."
fi
echo ""
echo "=== Changed files ==="
git status --short
- name: Extract version metadata
if: steps.detect.outputs.has_updates == 'true'
id: metadata
run: |
set -e
PKG_VERSION=$(dpkg-parsechangelog -S Version)
echo "package_version=$PKG_VERSION" >> $GITHUB_OUTPUT
cd drm-kernel
KERNEL_VERSION=$(make -s kernelversion 2>/dev/null || echo "unknown")
KERNEL_COMMIT=$(git rev-parse --short HEAD)
echo "kernel_version=$KERNEL_VERSION" >> $GITHUB_OUTPUT
echo "kernel_commit=$KERNEL_COMMIT" >> $GITHUB_OUTPUT
cd ..
echo "Package version: $PKG_VERSION"
echo "Kernel version: $KERNEL_VERSION"
echo "Kernel commit: $KERNEL_COMMIT"
- name: Create feature branch and commit
if: steps.detect.outputs.has_updates == 'true'
id: commit
run: |
set -e
BRANCH_NAME="automated-upstream-sync-$(date +%Y%m%d)"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
echo "⚠ Branch $BRANCH_NAME already exists remotely"
BRANCH_NAME="automated-upstream-sync-$(date +%Y%m%d-%H%M%S)"
echo "Using unique branch name: $BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
fi
git checkout -b "$BRANCH_NAME"
rm -f update.log
git add -A
KERNEL_VERSION="${{ steps.metadata.outputs.kernel_version }}"
KERNEL_COMMIT="${{ steps.metadata.outputs.kernel_commit }}"
PKG_VERSION="${{ steps.metadata.outputs.package_version }}"
OLD_KERNEL="${{ steps.upstream.outputs.old_kernel_commit }}"
NEW_KERNEL="${{ steps.upstream.outputs.new_kernel_commit }}"
OLD_FIRMWARE="${{ steps.upstream.outputs.old_firmware_commit }}"
NEW_FIRMWARE="${{ steps.upstream.outputs.new_firmware_commit }}"
COMMIT_MSG=$(cat <<EOF
Automated upstream sync: Update to kernel $KERNEL_VERSION ($KERNEL_COMMIT)
Updates:
- drm-misc-fixes: ${OLD_KERNEL:0:7} -> ${NEW_KERNEL:0:7}
- linux-firmware: ${OLD_FIRMWARE:0:7} -> ${NEW_FIRMWARE:0:7}
Package version: $PKG_VERSION
Co-Authored-By: GitHub Actions Bot <actions@github.com>
EOF
)
git commit -m "$COMMIT_MSG"
git push -u origin "$BRANCH_NAME"
echo "✓ Changes committed and pushed to $BRANCH_NAME"
- name: Create Pull Request
if: steps.detect.outputs.has_updates == 'true'
env:
# Use WORKFLOW_PAT if available to trigger CI on the PR
# Otherwise use github.token (but CI won't auto-run)
GH_TOKEN: ${{ secrets.WORKFLOW_PAT || github.token }}
run: |
set -e
KERNEL_VERSION="${{ steps.metadata.outputs.kernel_version }}"
KERNEL_COMMIT="${{ steps.metadata.outputs.kernel_commit }}"
PKG_VERSION="${{ steps.metadata.outputs.package_version }}"
BRANCH_NAME="${{ steps.commit.outputs.branch_name }}"
OLD_KERNEL="${{ steps.upstream.outputs.old_kernel_commit }}"
NEW_KERNEL="${{ steps.upstream.outputs.new_kernel_commit }}"
OLD_FIRMWARE="${{ steps.upstream.outputs.old_firmware_commit }}"
NEW_FIRMWARE="${{ steps.upstream.outputs.new_firmware_commit }}"
# Truncate commit hashes for display
OLD_KERNEL_SHORT="${OLD_KERNEL:0:7}"
NEW_KERNEL_SHORT="${NEW_KERNEL:0:7}"
OLD_FIRMWARE_SHORT="${OLD_FIRMWARE:0:7}"
NEW_FIRMWARE_SHORT="${NEW_FIRMWARE:0:7}"
# Check if we're using a PAT or the default token
if [ -n "${{ secrets.WORKFLOW_PAT }}" ]; then
CI_NOTE=""
else
CI_NOTE="
NOTE: CI workflows will not automatically run on this PR because it was created using GITHUB_TOKEN.
To enable automatic CI runs, configure a Personal Access Token (PAT) as the \\\`WORKFLOW_PAT\\\` secret.
Alternatively, you can manually trigger CI by closing and reopening this PR, or by pushing a new commit.
"
fi
cat > pr_body.md <<EOF
## Summary
This PR contains automated upstream synchronization from:
- **drm-misc-fixes**: Kernel driver sources
- **linux-firmware**: NPU firmware files
### Changes
- **Kernel version**: $KERNEL_VERSION (commit [$KERNEL_COMMIT](https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/$NEW_KERNEL))
- **Package version**: $PKG_VERSION
- **drm-misc-fixes**: [\`$OLD_KERNEL_SHORT\`](https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/$OLD_KERNEL) → [\`$NEW_KERNEL_SHORT\`](https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/$NEW_KERNEL)
- **linux-firmware**: [\`$OLD_FIRMWARE_SHORT\`](https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/commit/?id=$OLD_FIRMWARE) → [\`$NEW_FIRMWARE_SHORT\`](https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/commit/?id=$NEW_FIRMWARE)
### Updated Files
This sync automatically updated:
- Source files in \`src/\` and \`firmware/\`
- \`debian/changelog\` with new version
- \`src/amdxdna/dkms.conf\` PACKAGE_VERSION
- \`debian/amdxdna-dkms.install\` paths to match new version
$CI_NOTE
## Test plan
- [ ] Verify CI passes (DKMS builds on OEM 6.17 and HWE 6.17)
- [ ] Review driver source changes
- [ ] Review firmware changes
- [ ] Check for any compatibility issues
- [ ] Test on hardware (if available)
---
🤖 This PR was automatically created by the [nightly upstream sync workflow](https://github.com/${{ github.repository }}/actions/workflows/nightly-upstream-sync.yml).
Generated with [Claude Code](https://claude.com/claude-code)
EOF
gh pr create \
--title "Automated upstream sync: Update to kernel $KERNEL_VERSION ($KERNEL_COMMIT)" \
--body-file pr_body.md \
--base main \
--head "$BRANCH_NAME" \
--assignee superm1
echo "✓ Pull Request created successfully"