Skip to content

karellen-llvm-update #314

karellen-llvm-update

karellen-llvm-update #314

Workflow file for this run

name: karellen-llvm-update
on:
schedule:
- cron: "0 */6 * * *"
workflow_dispatch:
jobs:
check-update:
runs-on: self-hosted
timeout-minutes: 600
continue-on-error: false
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 60
steps:
- name: Ensure only single auto-update branch
shell: bash
run: |
set -eEux
set -o pipefail
shopt -s extglob
CURRENT_BRANCH="$(git ls-remote $GITHUB_SERVER_URL/$GITHUB_REPOSITORY 'auto-update-*' 2>/dev/null | { grep -o 'refs/heads/auto-update-.*' || true; } | sed 's/refs\/heads\///')"
if [ -n "$CURRENT_BRANCH" ] ; then
echo "# Pending auto-update branch $CURRENT_BRANCH already exists!" >> $GITHUB_STEP_SUMMARY
gh run cancel -R $GITHUB_SERVER_URL/$GITHUB_REPOSITORY ${{ github.run_id }}
sleep 10
fi
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Updates
shell: bash
run: |
set -eEux
set -o pipefail
shopt -s extglob
MODULES_CHANGED=""
while read line; do
read -r SUBMODULE_SHA SUBMODULE_NAME SUBMODULE_DESCRIBE <<<"$line"
# The submodules here are not initialized so there'll be a '-' in front of the local SHA
SUBMODULE_SHA=${SUBMODULE_SHA:1}
GIT_CONFIG="$(git config -f .gitmodules -l | grep 'submodule.'$SUBMODULE_NAME.)"
SUBMODULE_URL="$(echo "$GIT_CONFIG" | grep 'submodule.'$SUBMODULE_NAME'.url=' | sed 's/submodule\.'$SUBMODULE_NAME'\.url=//')"
SUBMODULE_BRANCH="$(echo "$GIT_CONFIG" | grep 'submodule.'$SUBMODULE_NAME'.branch=' | sed 's/submodule\.'$SUBMODULE_NAME'\.branch=//')"
read -r REMOTE_SHA REMOTE_REF <<<"$(git ls-remote $SUBMODULE_URL | grep 'refs/heads/'$SUBMODULE_BRANCH)"
if [ "$SUBMODULE_SHA" != "$REMOTE_SHA" ]; then
echo "## Submodule $SUBMODULE_NAME @ $SUBMODULE_URL/tree/$SUBMODULE_BRANCH local $SUBMODULE_SHA vs remote $REMOTE_SHA" >> $GITHUB_STEP_SUMMARY
MODULES_CHANGED="1"
else
echo "## Submodule $SUBMODULE_NAME @ $SUBMODULE_URL/tree/$SUBMODULE_BRANCH local $SUBMODULE_SHA unchanged" >> $GITHUB_STEP_SUMMARY
fi
done <<< "$(git submodule status)"
if [ -z "$MODULES_CHANGED" ]; then
echo "# No submodules changed detected - exiting!" >> $GITHUB_STEP_SUMMARY
exit 0
fi
git submodule sync --recursive
git submodule update --init --force --recursive
CURRENT_VERSION="$(./version_extractor.py -m python -d llvm-project)"
git submodule update --init --remote --recursive
NEW_VERSION="$(./version_extractor.py -m python -d llvm-project)"
if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then
echo "# Current version: $CURRENT_VERSION" >> $GITHUB_STEP_SUMMARY
echo "# New version: $NEW_VERSION" >> $GITHUB_STEP_SUMMARY
BRANCH_NAME="auto-update-${CURRENT_VERSION}-${NEW_VERSION}"
TITLE="Automatic update from $CURRENT_VERSION to $NEW_VERSION"
git config --global user.email "supervisor@karellen.co"
git config --global user.name "Karellen Supervisor"
git checkout -b "$BRANCH_NAME"
git commit -a -m "$TITLE"
git push --set-upstream origin "$BRANCH_NAME"
PR_URL="$(gh pr create --head "$BRANCH_NAME" --base master --fill --no-maintainer-edit)"
gh pr merge --merge --auto -d "$PR_URL"
fi