Skip to content

Commit 0000c33

Browse files
committed
Detect workflow file changes to trigger LKL build
Previously, the nightly LKL build only checked the hash of the LKL commit, so the build process will only be triggered when the upstream LKL has new commit. However, if the build-lkl.yml is updated, the LKL should be rebuilt. This checks not only the LKL commit hash but the hash of build-lkl.yml to ensure the build process is triggered when build-lkl.yml is updated. Change-Id: I8db1dc2c1fea03bd8dc85d767e6298739d4a9f35
1 parent 00007b6 commit 0000c33

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

.github/workflows/build-lkl.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ jobs:
3636
contents: read
3737
outputs:
3838
lkl_commit: ${{ steps.head.outputs.commit }}
39+
yml_hash: ${{ steps.compare.outputs.yml_hash }}
3940
needs_build: ${{ steps.compare.outputs.needs_build }}
4041
steps:
42+
- name: Checkout repository
43+
uses: actions/checkout@v4
44+
4145
- name: Get upstream LKL HEAD
4246
id: head
4347
run: |
@@ -54,25 +58,37 @@ jobs:
5458
env:
5559
GH_TOKEN: ${{ github.token }}
5660
run: |
61+
CURRENT_YML=$(sha256sum .github/workflows/build-lkl.yml | awk '{print $1}')
62+
echo "yml_hash=${CURRENT_YML}" >> "$GITHUB_OUTPUT"
63+
5764
if [ "${{ inputs.force }}" = "true" ]; then
5865
echo "needs_build=true" >> "$GITHUB_OUTPUT"
5966
echo "Forced rebuild requested."
6067
exit 0
6168
fi
6269
6370
# Fetch BUILD_INFO from existing nightly release.
64-
LAST_COMMIT=$(gh release view "${{ env.NIGHTLY_TAG }}" \
71+
LAST_RELEASE=$(gh release view "${{ env.NIGHTLY_TAG }}" \
6572
--repo "${{ env.KBOX_REPO }}" \
66-
--json body --jq '.body' 2>/dev/null \
73+
--json body --jq '.body' 2>/dev/null) || LAST_RELEASE=""
74+
75+
LAST_COMMIT=$(echo "$LAST_RELEASE" \
6776
| grep -oP 'commit=\K[0-9a-f]+' | head -1) || LAST_COMMIT=""
6877
69-
CURRENT="${{ steps.head.outputs.commit }}"
70-
if [ "$LAST_COMMIT" = "$CURRENT" ]; then
71-
echo "needs_build=false" >> "$GITHUB_OUTPUT"
72-
echo "Upstream unchanged (${CURRENT}). Skipping build."
73-
else
78+
LAST_YML=$(echo "$LAST_RELEASE" \
79+
| grep -oP 'yml_hash=\K[0-9a-f]+' | head -1) || LAST_YML=""
80+
81+
CURRENT_COMMIT="${{ steps.head.outputs.commit }}"
82+
83+
if [ "$LAST_COMMIT" != "$CURRENT_COMMIT" ]; then
84+
echo "needs_build=true" >> "$GITHUB_OUTPUT"
85+
echo "New upstream commit: ${CURRENT_COMMIT} (was: ${LAST_COMMIT:-none})"
86+
elif [ "$LAST_YML" != "$CURRENT_YML" ]; then
7487
echo "needs_build=true" >> "$GITHUB_OUTPUT"
75-
echo "New upstream commit: ${CURRENT} (was: ${LAST_COMMIT:-none})"
88+
echo "build-lkl.yml was changed"
89+
else
90+
echo "needs_build=false" >> "$GITHUB_OUTPUT"
91+
echo "Upstream unchanged (${CURRENT_COMMIT}) and the build script unchanged. Skipping build."
7692
fi
7793
7894
# ---- Build x86_64, aarch64 and riscv64 in parallel ----
@@ -144,12 +160,14 @@ jobs:
144160
GH_TOKEN: ${{ github.token }}
145161
run: |
146162
LKL_COMMIT="${{ needs.check-upstream.outputs.lkl_commit }}"
163+
YML_HASH="${{ needs.check-upstream.outputs.yml_hash }}"
147164
BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)
148165
149166
cat > /tmp/release-notes.md <<EOF
150167
Nightly prebuilt liblkl.a for kbox.
151168
152169
commit=${LKL_COMMIT}
170+
yml_hash=${YML_HASH}
153171
date=${BUILD_DATE}
154172
upstream=https://github.com/${{ env.LKL_UPSTREAM }}/commit/${LKL_COMMIT}
155173

0 commit comments

Comments
 (0)