Skip to content

Commit 23ff0d7

Browse files
Add GitHub ci workflows (actions#8464)
1 parent c6820d1 commit 23ff0d7

6 files changed

+175
-0
lines changed

.github/workflows/ci-cleanup.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
run-name: Cleanup ${{ github.head_ref }}
2+
on:
3+
pull_request_target:
4+
types: labeled
5+
paths:
6+
- 'images/**'
7+
8+
jobs:
9+
clean_ci:
10+
name: Clean CI runs
11+
runs-on: ubuntu-latest
12+
permissions:
13+
actions: write
14+
steps:
15+
- env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
shell: pwsh
18+
run: |
19+
$startDate = Get-Date -UFormat %s
20+
$workflows = @("macos11", "macos12", "ubuntu2004", "ubuntu2204", "windows2019", "windows2022")
21+
while ($true) {
22+
$continue = $false
23+
foreach ($wf in $workflows) {
24+
$skippedCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status skipped --json databaseId"
25+
$skippedIds = Invoke-Expression -Command $skippedCommand | ConvertFrom-Json | ForEach-Object { $_.databaseId }
26+
$skippedIds | ForEach-Object {
27+
$deleteCommand = "gh run delete --repo ${{ github.repository }} $_"
28+
Invoke-Expression -Command $deleteCommand
29+
}
30+
$pendingCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status requested --json databaseId --template '{{ . | len }}'"
31+
$pending = Invoke-Expression -Command $pendingCommand
32+
if ($pending -gt 0) {
33+
Write-Host "Pending for ${wf}.yml: $pending run(s)"
34+
$continue = $true
35+
}
36+
}
37+
if ($continue -eq $false) {
38+
Write-Host "All done, exiting"
39+
break
40+
}
41+
$curDate = Get-Date -UFormat %s
42+
if (($curDate - $startDate) -gt 60) {
43+
Write-Host "Reached timeout, exiting"
44+
break
45+
}
46+
Write-Host "Waiting 5 seconds..."
47+
Start-Sleep -Seconds 5
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Trigger Build workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_type:
7+
required: true
8+
type: string
9+
10+
defaults:
11+
run:
12+
shell: pwsh
13+
14+
jobs:
15+
trigger-workflow:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Trigger Build workflow
19+
env:
20+
CI_PR_TOKEN: ${{ secrets.CI_PR_TOKEN }}
21+
PR_TITLE: ${{ github.event.pull_request.title }}
22+
CI_PR: ${{ secrets.CI_REPO }}
23+
run: |
24+
$headers = @{
25+
Authorization="Bearer $env:CI_PR_TOKEN"
26+
}
27+
28+
# Private repository for builds
29+
$apiRepoUrl = "https://api.github.com/repos/$env:CI_PR"
30+
31+
$eventType = "trigger-${{ inputs.image_type }}-build"
32+
$body = @{
33+
event_type = $eventType;
34+
client_payload = @{
35+
pr_title = "$env:PR_TITLE"
36+
custom_repo = "${{ github.event.pull_request.head.repo.full_name }}"
37+
custom_repo_commit_hash = "${{ github.event.pull_request.head.sha }}"
38+
}
39+
}
40+
41+
$bodyString = $body | ConvertTo-Json
42+
43+
try {
44+
Invoke-WebRequest -Uri "$apiRepoUrl/dispatches" -Method Post -Headers $headers -Body $bodyString | Out-Null
45+
} catch {
46+
throw "$($_.exception[0].message)"
47+
}

.github/workflows/ubuntu2004.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Trigger Ubuntu20.04 CI
2+
run-name: Ubuntu20.04 - ${{ github.event.pull_request.title }}
3+
4+
on:
5+
pull_request_target:
6+
types: labeled
7+
paths:
8+
- 'images/linux/**'
9+
10+
defaults:
11+
run:
12+
shell: pwsh
13+
14+
jobs:
15+
Ubuntu_2004:
16+
if: contains(github.event.pull_request.labels.*.name, 'CI ubuntu-all') || contains(github.event.pull_request.labels.*.name, 'CI ubuntu-2004')
17+
uses: ./.github/workflows/trigger-ubuntu-win-build.yml
18+
with:
19+
image_type: 'ubuntu2004'
20+
secrets: inherit

.github/workflows/ubuntu2204.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Trigger Ubuntu22.04 CI
2+
run-name: Ubuntu22.04 - ${{ github.event.pull_request.title }}
3+
4+
on:
5+
pull_request_target:
6+
types: labeled
7+
paths:
8+
- 'images/linux/**'
9+
10+
defaults:
11+
run:
12+
shell: pwsh
13+
14+
jobs:
15+
Ubuntu_2204:
16+
if: contains(github.event.pull_request.labels.*.name, 'CI ubuntu-all') || contains(github.event.pull_request.labels.*.name, 'CI ubuntu-2204')
17+
uses: ./.github/workflows/trigger-ubuntu-win-build.yml
18+
with:
19+
image_type: 'ubuntu2204'
20+
secrets: inherit

.github/workflows/windows2019.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Trigger Windows19 CI
2+
run-name: Windows2019 - ${{ github.event.pull_request.title }}
3+
4+
on:
5+
pull_request_target:
6+
types: labeled
7+
paths:
8+
- 'images/win/**'
9+
10+
defaults:
11+
run:
12+
shell: pwsh
13+
14+
jobs:
15+
Windows_2019:
16+
if: contains(github.event.pull_request.labels.*.name, 'CI windows-all') || contains(github.event.pull_request.labels.*.name, 'CI windows-2019')
17+
uses: ./.github/workflows/trigger-ubuntu-win-build.yml
18+
with:
19+
image_type: 'windows2019'
20+
secrets: inherit

.github/workflows/windows2022.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Trigger Windows22 CI
2+
run-name: Windows2022 - ${{ github.event.pull_request.title }}
3+
4+
on:
5+
pull_request_target:
6+
types: labeled
7+
paths:
8+
- 'images/win/**'
9+
10+
defaults:
11+
run:
12+
shell: pwsh
13+
14+
jobs:
15+
Windows_2022:
16+
if: contains(github.event.pull_request.labels.*.name, 'CI windows-all') || contains(github.event.pull_request.labels.*.name, 'CI windows-2022')
17+
uses: ./.github/workflows/trigger-ubuntu-win-build.yml
18+
with:
19+
image_type: 'windows2022'
20+
secrets: inherit

0 commit comments

Comments
 (0)