Skip to content

Commit 0774389

Browse files
committed
Allow COPR builds to catch up so we can merge multiple PRs without stacking builds
1 parent 5076406 commit 0774389

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

.github/workflows/build-copr-packages.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,29 @@ jobs:
3939
- name: Checkout repository
4040
uses: actions/checkout@v6
4141
with:
42-
fetch-depth: 2
42+
fetch-depth: 0 # Full history to find last successful build
43+
44+
- name: Get last successful build commit
45+
id: last-success
46+
env:
47+
GH_TOKEN: ${{ github.token }}
48+
run: |
49+
# Find the last successful workflow run on this branch
50+
LAST_SHA=$(gh run list \
51+
--workflow="Build COPR Packages" \
52+
--branch=main \
53+
--status=success \
54+
--limit=1 \
55+
--json headSha \
56+
--jq '.[0].headSha // empty' 2>/dev/null) || LAST_SHA=""
57+
58+
if [[ -n "$LAST_SHA" ]]; then
59+
echo "Last successful build: $LAST_SHA"
60+
echo "sha=$LAST_SHA" >> $GITHUB_OUTPUT
61+
else
62+
echo "No previous successful build found, will use HEAD~1"
63+
echo "sha=" >> $GITHUB_OUTPUT
64+
fi
4365
4466
- name: Detect changed packages
4567
id: detect
@@ -102,11 +124,22 @@ jobs:
102124
CHANGED_PKGS=$(echo "${{ inputs.packages }}" | tr ',' ' ')
103125
else
104126
echo "Detecting changed packages..."
127+
128+
# Compare against last successful build, or HEAD~1 if none
129+
LAST_SHA="${{ steps.last-success.outputs.sha }}"
130+
if [[ -n "$LAST_SHA" ]]; then
131+
echo "Comparing HEAD against last successful build: $LAST_SHA"
132+
COMPARE_REF="$LAST_SHA"
133+
else
134+
echo "Comparing HEAD against HEAD~1"
135+
COMPARE_REF="HEAD~1"
136+
fi
137+
105138
CHANGED_PKGS=""
106139
for dir in packages/*/; do
107140
pkg=$(basename "$dir")
108141
if [[ "$pkg" != "README.md" ]]; then
109-
if git diff --name-only HEAD~1 HEAD | grep -q "^packages/$pkg/"; then
142+
if git diff --name-only "$COMPARE_REF" HEAD | grep -q "^packages/$pkg/"; then
110143
CHANGED_PKGS="$CHANGED_PKGS $pkg"
111144
fi
112145
fi

0 commit comments

Comments
 (0)