Skip to content

Nightly Update Submodule #171

Nightly Update Submodule

Nightly Update Submodule #171

Workflow file for this run

name: Nightly Update Submodule
on:
schedule:
- cron: '0 17 * * 0-5' # At 00:00 on every day-of-week from Monday through Saturday UTC +7
workflow_dispatch:
jobs:
update-submodule:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: write
outputs:
pr_number: ${{ steps.check-update.outputs.pr_number }}
pr_created: ${{ steps.check-update.outputs.pr_created }}
release_name: ${{ steps.check-update.outputs.release_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
ref: main
fetch-depth: 0
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Update submodule to latest release
id: check-update
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
run: |
cd llama.cpp
latest_release=$(curl -s https://api.github.com/repos/ggerganov/llama.cpp/releases/latest | jq -r '.tag_name')
release_name=$(curl -s https://api.github.com/repos/ggerganov/llama.cpp/releases/latest | jq -r '.name')
echo "::set-output name=release_name::$release_name"
git fetch
current_commit=$(git rev-parse HEAD)
git checkout $latest_release
new_commit=$(git rev-parse HEAD)
if [ "$current_commit" = "$new_commit" ]; then
echo "llamacpp remote repo doesn't have update today, skip nightly build"
echo "::set-output name=pr_created::false"
exit 0
fi
echo "::set-output name=pr_created::true"
cd -
git add llama.cpp
git commit -m "Update submodule to latest release $release_name"
branch_name="update-submodule-$(date +'%Y-%m-%d-%H-%M')"
git checkout -b $branch_name
git push origin $branch_name
pr_title="Update llama.cpp submodule to latest release $release_name"
pr_body="This PR updates the llama.cpp submodule to the latest release: $release_name."
gh pr create --title "$pr_title" --body "$pr_body" --head $branch_name --base main --reviewer vansangpfiev
pr_number=$(gh pr list --head $branch_name --json number --jq '.[0].number')
echo "::set-output name=pr_number::$pr_number"
check-and-merge-pr:
needs: update-submodule
if: needs.update-submodule.outputs.pr_created == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- name: Apply patch file
run: |
cd llama.cpp
git apply ../patches/0001-Add-API-query-buffer-size.patch
- name: Wait for CI to pass
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
run: |
pr_number=${{ needs.update-submodule.outputs.pr_number }}
while true; do
ci_completed=$(gh pr checks $pr_number --json completedAt --jq '.[].completedAt')
if echo "$ci_completed" | grep -q "0001-01-01T00:00:00Z"; then
echo "CI is still running, waiting..."
sleep 60
else
echo "CI has completed, checking states..."
ci_states=$(gh pr checks $pr_number --json state --jq '.[].state')
if echo "$ci_states" | grep -vqE "SUCCESS|SKIPPED"; then
echo "CI failed, exiting..."
exit 1
else
echo "CI passed, merging PR..."
break
fi
fi
done
- name: Merge the PR
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}
run: |
pr_number=${{ needs.update-submodule.outputs.pr_number }}
gh pr merge $pr_number --merge --admin
create-tag:
needs: [update-submodule, check-and-merge-pr]
if: needs.update-submodule.outputs.pr_created == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive
ref: main
fetch-depth: 0
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- name: Apply patch file
run: |
cd llama.cpp
git apply ../patches/0001-Add-API-query-buffer-size.patch
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Create and push a new tag
run: |
# Function to get the latest release tag
get_latest_tag() {
local retries=0
local max_retries=3
local tag
while [ $retries -lt $max_retries ]; do
tag=$(curl -s https://api.github.com/repos/janhq/cortex.llamacpp/releases/latest | jq -r .tag_name)
if [ -n "$tag" ] && [ "$tag" != "null" ]; then
echo $tag
return
else
let retries++
echo "Retrying... ($retries/$max_retries)"
sleep 2
fi
done
echo "Failed to fetch latest tag after $max_retries attempts."
exit 1
}
LATEST_TAG=$(get_latest_tag)
new_tag="${LATEST_TAG}-${{ needs.update-submodule.outputs.release_name }}"
git tag $new_tag
git push origin $new_tag