diff --git a/.github/workflows/ci-cleanup.yml b/.github/workflows/ci-cleanup.yml new file mode 100644 index 000000000..3b532e4cc --- /dev/null +++ b/.github/workflows/ci-cleanup.yml @@ -0,0 +1,48 @@ +run-name: Cleanup ${{ github.head_ref }} +on: + pull_request_target: + types: labeled + paths: + - 'images/**' + +jobs: + clean_ci: + name: Clean CI runs + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + shell: pwsh + run: | + $startDate = Get-Date -UFormat %s + $workflows = @("macos11", "macos12", "ubuntu2004", "ubuntu2204", "windows2019", "windows2022") + while ($true) { + $continue = $false + foreach ($wf in $workflows) { + $skippedCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status skipped --json databaseId" + $skippedIds = Invoke-Expression -Command $skippedCommand | ConvertFrom-Json | ForEach-Object { $_.databaseId } + $skippedIds | ForEach-Object { + $deleteCommand = "gh run delete --repo ${{ github.repository }} $_" + Invoke-Expression -Command $deleteCommand + } + $pendingCommand = "gh run list --workflow ${wf}.yml --branch ${{ github.event.pull_request.head.ref }} --repo ${{ github.repository }} --status requested --json databaseId --template '{{ . | len }}'" + $pending = Invoke-Expression -Command $pendingCommand + if ($pending -gt 0) { + Write-Host "Pending for ${wf}.yml: $pending run(s)" + $continue = $true + } + } + if ($continue -eq $false) { + Write-Host "All done, exiting" + break + } + $curDate = Get-Date -UFormat %s + if (($curDate - $startDate) -gt 60) { + Write-Host "Reached timeout, exiting" + break + } + Write-Host "Waiting 5 seconds..." + Start-Sleep -Seconds 5 + } diff --git a/.github/workflows/trigger-ubuntu-win-build.yml b/.github/workflows/trigger-ubuntu-win-build.yml new file mode 100644 index 000000000..973a325f0 --- /dev/null +++ b/.github/workflows/trigger-ubuntu-win-build.yml @@ -0,0 +1,47 @@ +name: Trigger Build workflow + +on: + workflow_call: + inputs: + image_type: + required: true + type: string + +defaults: + run: + shell: pwsh + +jobs: + trigger-workflow: + runs-on: ubuntu-latest + steps: + - name: Trigger Build workflow + env: + CI_PR_TOKEN: ${{ secrets.CI_PR_TOKEN }} + PR_TITLE: ${{ github.event.pull_request.title }} + CI_PR: ${{ secrets.CI_REPO }} + run: | + $headers = @{ + Authorization="Bearer $env:CI_PR_TOKEN" + } + + # Private repository for builds + $apiRepoUrl = "https://api.github.com/repos/$env:CI_PR" + + $eventType = "trigger-${{ inputs.image_type }}-build" + $body = @{ + event_type = $eventType; + client_payload = @{ + pr_title = "$env:PR_TITLE" + custom_repo = "${{ github.event.pull_request.head.repo.full_name }}" + custom_repo_commit_hash = "${{ github.event.pull_request.head.sha }}" + } + } + + $bodyString = $body | ConvertTo-Json + + try { + Invoke-WebRequest -Uri "$apiRepoUrl/dispatches" -Method Post -Headers $headers -Body $bodyString | Out-Null + } catch { + throw "$($_.exception[0].message)" + } diff --git a/.github/workflows/ubuntu2004.yml b/.github/workflows/ubuntu2004.yml new file mode 100644 index 000000000..cfe71fd34 --- /dev/null +++ b/.github/workflows/ubuntu2004.yml @@ -0,0 +1,20 @@ +name: Trigger Ubuntu20.04 CI +run-name: Ubuntu20.04 - ${{ github.event.pull_request.title }} + +on: + pull_request_target: + types: labeled + paths: + - 'images/linux/**' + +defaults: + run: + shell: pwsh + +jobs: + Ubuntu_2004: + if: contains(github.event.pull_request.labels.*.name, 'CI ubuntu-all') || contains(github.event.pull_request.labels.*.name, 'CI ubuntu-2004') + uses: ./.github/workflows/trigger-ubuntu-win-build.yml + with: + image_type: 'ubuntu2004' + secrets: inherit diff --git a/.github/workflows/ubuntu2204.yml b/.github/workflows/ubuntu2204.yml new file mode 100644 index 000000000..634bb5369 --- /dev/null +++ b/.github/workflows/ubuntu2204.yml @@ -0,0 +1,20 @@ +name: Trigger Ubuntu22.04 CI +run-name: Ubuntu22.04 - ${{ github.event.pull_request.title }} + +on: + pull_request_target: + types: labeled + paths: + - 'images/linux/**' + +defaults: + run: + shell: pwsh + +jobs: + Ubuntu_2204: + if: contains(github.event.pull_request.labels.*.name, 'CI ubuntu-all') || contains(github.event.pull_request.labels.*.name, 'CI ubuntu-2204') + uses: ./.github/workflows/trigger-ubuntu-win-build.yml + with: + image_type: 'ubuntu2204' + secrets: inherit diff --git a/.github/workflows/windows2019.yml b/.github/workflows/windows2019.yml new file mode 100644 index 000000000..72ba47339 --- /dev/null +++ b/.github/workflows/windows2019.yml @@ -0,0 +1,20 @@ +name: Trigger Windows19 CI +run-name: Windows2019 - ${{ github.event.pull_request.title }} + +on: + pull_request_target: + types: labeled + paths: + - 'images/win/**' + +defaults: + run: + shell: pwsh + +jobs: + Windows_2019: + if: contains(github.event.pull_request.labels.*.name, 'CI windows-all') || contains(github.event.pull_request.labels.*.name, 'CI windows-2019') + uses: ./.github/workflows/trigger-ubuntu-win-build.yml + with: + image_type: 'windows2019' + secrets: inherit diff --git a/.github/workflows/windows2022.yml b/.github/workflows/windows2022.yml new file mode 100644 index 000000000..0454811e2 --- /dev/null +++ b/.github/workflows/windows2022.yml @@ -0,0 +1,20 @@ +name: Trigger Windows22 CI +run-name: Windows2022 - ${{ github.event.pull_request.title }} + +on: + pull_request_target: + types: labeled + paths: + - 'images/win/**' + +defaults: + run: + shell: pwsh + +jobs: + Windows_2022: + if: contains(github.event.pull_request.labels.*.name, 'CI windows-all') || contains(github.event.pull_request.labels.*.name, 'CI windows-2022') + uses: ./.github/workflows/trigger-ubuntu-win-build.yml + with: + image_type: 'windows2022' + secrets: inherit