Skip to content

Commit 630aac6

Browse files
committed
Improve AppVeyor CI configuration
- Always build all commits in main branches and pull requests. - For other branches, only build the latest commit; skip intermediate ones if multiple are pushed in quick succession. - Enable skip_branch_with_pr, to avoid redundant branch builds when a PR is open. - Increase clone_depth from 1 to 10 to reduce failures during checkout/init phase when multiple commits are pushed rapidly.
1 parent acd071f commit 630aac6

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

appveyor.yml

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
version: build-{build}~branch-{branch}
22

3-
clone_depth: 1
3+
skip_branch_with_pr: true
4+
5+
before_build:
6+
- ps: |
7+
$pullRequestNr = $env:APPVEYOR_PULL_REQUEST_NUMBER
8+
$branch = $env:APPVEYOR_REPO_BRANCH
9+
$commit = $env:APPVEYOR_REPO_COMMIT
10+
$repo = $env:APPVEYOR_REPO_NAME
11+
$prRepo = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME
12+
13+
$isPrFromFork = $pullRequestNr -and ($repo -ne $prRepo)
14+
Write-Host "pullRequestNr=$pullRequestNr, isPRFromFork=$isPrFromFork, branch=$branch, commit=$commit, repo=$repo"
15+
16+
if ($pullRequestNr -and (-not $isPrFromFork)) {
17+
$branch = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH
18+
$commit = $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT
19+
Write-Host "real branch name of this pull request is $branch, real commit $commit"
20+
}
21+
22+
if ($isPrFromFork) {
23+
Write-Host "pull request from a fork detected, always build."
24+
} elseif ($branch -eq "main" -or $branch -match '^\d+\.\d+$') {
25+
Write-Host "main branch detected, always build."
26+
} else {
27+
Write-Host "Checking if this is the latest commit on branch '$branch'..."
28+
$remoteHead = git ls-remote https://github.com/$repo.git refs/heads/$branch |
29+
ForEach-Object { ($_ -split "`t")[0] }
30+
Write-Host "latest commit=$remoteHead"
31+
if ($remoteHead -ne $commit) {
32+
Write-Host "Not the latest commit on branch '$branch' — skipping build."
33+
Exit-AppveyorBuild
34+
}
35+
}
36+
37+
clone_depth: 10
438

539
build_script:
640
# dump some system info

0 commit comments

Comments
 (0)