Skip to content

Update driver submodules #156

Update driver submodules

Update driver submodules #156

name: Update driver submodules
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
update-submodules:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
submodules: true
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
persist-credentials: true
- name: Install rpm
run: |
sudo apt-get install -y rpm
- name: Configure git credentials for xcp-ng/driver-sources
env:
XCP_NG_RPMS_PAT: ${{ secrets.XCP_NG_RPMS_PAT }}
run: |
git config --global "http.https://github.com/xcp-ng/driver-sources.git/.extraheader" \
"AUTHORIZATION: basic $(printf '%s' "x-access-token:${XCP_NG_RPMS_PAT}" | base64 -w 0)"
- name: Update driver submodules to origin/8.3
id: update
run: |
updated=()
missing_sources=()
updated_sources=()
for submodule in drivers/8.3/srpm/*/; do
submodule="${submodule%/}"
src_submodule="${submodule/srpm/source}"
git -C "$submodule" fetch origin 8.3
local_sha=$(git -C "$submodule" rev-parse HEAD)
remote_sha=$(git -C "$submodule" rev-parse origin/8.3)
if [ "$local_sha" != "$remote_sha" ]; then
git -C "$submodule" checkout --detach origin/8.3
echo " $submodule: $local_sha -> $remote_sha"
updated+=("$submodule")
fi
if [ ! -d "$src_submodule" ]; then
# Missing sources, we need to add the sub-module as well as import its sources
{
# Add the source sub-module
git submodule add -b source/8.3 git@github.com:xcp-ng/driver-sources.git "drivers/8.3/source/$(basename "$submodule")"
# Import the sources
cd "$submodule"
branch=$(OOT_DRIVER_IMPORT=y ../../../../scripts/git-import-srpm HEAD | sed -n 's/.*Constructing \([^ ]\+\) from rev HEAD/\1/p')
cd -
# Push the source branch and update source sub-module
cd "$src_submodule"
git checkout $branch^0
git push origin $branch ${branch%patched}source
missing_sources+=("$src_submodule")
cd -
}
else
# Sources are present, let's check if they are stale
{
# Import the sources from HEAD
cd "$submodule"
branch=$(OOT_DRIVER_IMPORT=y ../../../../scripts/git-import-srpm HEAD | sed -n 's/.*Constructing \([^ ]\+\) from rev HEAD/\1/p')
cd -
# Check if they match
cd "$src_submodule"
if [ "$(git rev-parse HEAD)" != "$(git rev-parse $branch)" ]; then
# Sources are stale, refresh them from the above import
git checkout $branch^0
# And push them
git push -f origin ${branch} ${branch%patched}source
updated_sources+=("$src_submodule")
fi
cd -
}
fi
done
if [ ${#updated[@]} -gt 0 -o ${#missing_sources[@]} -gt 0 -o ${#updated_sources[@]} -gt 0 ]; then
echo "updated=true" >> "$GITHUB_OUTPUT"
printf '%s\n' "${updated[@]}" > /tmp/updated-submodules.txt
printf '%s\n' "${missing_sources[@]}" > /tmp/missing-sources.txt
printf '%s\n' "${updated_sources[@]}" > /tmp/updated-sources.txt
else
echo "No submodules needed updating."
echo "updated=false" >> "$GITHUB_OUTPUT"
fi
- name: Regenerate drivers/README.md
if: steps.update.outputs.updated == 'true'
run: |
./scripts/update-drivers-list.sh
- name: Commit and open PR
if: steps.update.outputs.updated == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
branch="auto/update-driver-submodules"
git config user.name "Vates Driver Importer"
git config user.email "gitimporter@vates.tech"
git checkout -b "$branch"
git add drivers/
git commit -s -m "drivers: update submodules and corresponding sources to latest 8.3 branch"
# Force-push so a re-run on the same day updates the existing branch.
git push --force origin "$branch"
# Open a PR only if none is already open for this branch.
if ! gh pr list --head "$branch" --state open --json number --jq '.[0].number' | grep -q .; then
{
echo "Automated daily update of driver submodules to the latest \`8.3\` branch."
echo ""
test -f /tmp/updated-submodules.txt && {
echo "Updated submodules:"
sed 's/^/- /' /tmp/updated-submodules.txt
echo ""
}
test -f /tmp/missing-sources.txt && {
echo "Added source submodules:"
sed 's/^/- /' /tmp/missing-sources.txt
echo ""
}
test -f /tmp/updated-sources.txt && {
echo "Updated source submodules:"
sed 's/^/- /' /tmp/updated-sources.txt
echo ""
}
} > /tmp/pr-body.txt
gh pr create \
--base main \
--head "$branch" \
--title "drivers: update submodules to latest 8.3 branch" \
--body-file /tmp/pr-body.txt
fi