mirror of
https://github.com/actions/versions-package-tools.git
synced 2025-12-10 03:13:23 +00:00
Migrate tools CI to GA
This commit is contained in:
@@ -1,29 +1,15 @@
|
|||||||
steps:
|
steps:
|
||||||
- checkout: self
|
- checkout: self
|
||||||
|
|
||||||
- task: PowerShell@2
|
|
||||||
displayName: 'Get source version'
|
|
||||||
inputs:
|
|
||||||
TargetType: inline
|
|
||||||
script: |
|
|
||||||
$url = "https://api.github.com/repos/$(REPOSITORY)/commits/$(BRANCH)"
|
|
||||||
$commit = Invoke-RestMethod -Uri $url -Method "GET"
|
|
||||||
Write-Output "##vso[task.setvariable variable=COMMIT_SHA]$($commit.sha)"
|
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
displayName: 'Run builds'
|
displayName: 'Run builds'
|
||||||
inputs:
|
inputs:
|
||||||
targetType: filePath
|
targetType: filePath
|
||||||
filePath: './azure-devops/run-ci-builds.ps1'
|
filePath: './github/run-ci-builds.ps1'
|
||||||
arguments: |
|
arguments: |
|
||||||
-TeamFoundationCollectionUri $(System.TeamFoundationCollectionUri) `
|
-RepositoryFullName $(REPOSITORY_FULL_NAME) `
|
||||||
-AzureDevOpsProjectName $(System.TeamProject) `
|
-AccessToken $(GITHUB_TOKEN) `
|
||||||
-AzureDevOpsAccessToken $(System.AccessToken) `
|
-WorkflowFileName $(WORKFLOW_FILE_NAME) `
|
||||||
-SourceBranch $(BRANCH) `
|
-WorkflowDispatchRef $(DISPATCH_REF) `
|
||||||
-DefinitionId $(DEFINITION_ID) `
|
|
||||||
-SourceVersion $(COMMIT_SHA) `
|
|
||||||
-ManifestLink $(MANIFEST_URL) `
|
|
||||||
-WaitForBuilds $(WAIT_FOR_BUILDS) `
|
|
||||||
-ToolVersions "$(ToolVersions)" `
|
-ToolVersions "$(ToolVersions)" `
|
||||||
-RetryIntervalSec $(INTERVAL_SEC) `
|
-PublishReleases $(PUPLISH_RELEASES)
|
||||||
-RetryCount $(RETRY_COUNT)
|
|
||||||
@@ -3,6 +3,11 @@ param (
|
|||||||
)
|
)
|
||||||
|
|
||||||
$targetPath = $env:AGENT_TOOLSDIRECTORY
|
$targetPath = $env:AGENT_TOOLSDIRECTORY
|
||||||
|
if ([string]::IsNullOrEmpty($targetPath)) {
|
||||||
|
# GitHub Windows images don't have `AGENT_TOOLSDIRECTORY` variable
|
||||||
|
$targetPath = $env:RUNNER_TOOL_CACHE
|
||||||
|
}
|
||||||
|
|
||||||
if ($ToolName) {
|
if ($ToolName) {
|
||||||
$targetPath = Join-Path $targetPath $ToolName
|
$targetPath = Join-Path $targetPath $ToolName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,8 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Create commit with all unstaged changes in repository and create pull-request
|
Create commit with all unstaged changes in repository and create pull-request
|
||||||
|
|
||||||
.PARAMETER RepositoryOwner
|
.PARAMETER RepositoryFullName
|
||||||
Required parameter. The organization which tool repository belongs
|
Required parameter. The owner and repository name. For example, 'actions/versions-package-tools'
|
||||||
.PARAMETER RepositoryName
|
|
||||||
Optional parameter. The name of tool repository
|
|
||||||
.PARAMETER AccessToken
|
.PARAMETER AccessToken
|
||||||
Required parameter. PAT Token to authorize
|
Required parameter. PAT Token to authorize
|
||||||
.PARAMETER BranchName
|
.PARAMETER BranchName
|
||||||
@@ -18,8 +16,7 @@ Required parameter. The title of pull-request
|
|||||||
Required parameter. The description of pull-request
|
Required parameter. The description of pull-request
|
||||||
#>
|
#>
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)] [string] $RepositoryOwner,
|
[Parameter(Mandatory)] [string] $RepositoryFullName,
|
||||||
[Parameter(Mandatory)] [string] $RepositoryName,
|
|
||||||
[Parameter(Mandatory)] [string] $AccessToken,
|
[Parameter(Mandatory)] [string] $AccessToken,
|
||||||
[Parameter(Mandatory)] [string] $BranchName,
|
[Parameter(Mandatory)] [string] $BranchName,
|
||||||
[Parameter(Mandatory)] [string] $CommitMessage,
|
[Parameter(Mandatory)] [string] $CommitMessage,
|
||||||
@@ -46,11 +43,11 @@ function Update-PullRequest {
|
|||||||
|
|
||||||
$updatedPullRequest = $GitHubApi.UpdatePullRequest($Title, $Body, $BranchName, $PullRequest.number)
|
$updatedPullRequest = $GitHubApi.UpdatePullRequest($Title, $Body, $BranchName, $PullRequest.number)
|
||||||
|
|
||||||
if (($updatedPullRequest -eq $null) -or ($updatedPullRequest.html_url -eq $null)) {
|
if (($null -eq $updatedPullRequest) -or ($null -eq $updatedPullRequest.html_url)) {
|
||||||
Write-Host "##vso[task.logissue type=error;] Unexpected error occurs while updating pull request."
|
Write-Host "Unexpected error occurs while updating pull request."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
Write-host "##[section] Pull request updated: $($updatedPullRequest.html_url)"
|
Write-host "Pull request updated: $($updatedPullRequest.html_url)"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Create-PullRequest {
|
function Create-PullRequest {
|
||||||
@@ -67,12 +64,12 @@ function Create-PullRequest {
|
|||||||
|
|
||||||
$createdPullRequest = $GitHubApi.CreateNewPullRequest($Title, $Body, $BranchName)
|
$createdPullRequest = $GitHubApi.CreateNewPullRequest($Title, $Body, $BranchName)
|
||||||
|
|
||||||
if (($createdPullRequest -eq $null) -or ($createdPullRequest.html_url -eq $null)) {
|
if (($null -eq $createdPullRequest) -or ($null -eq $createdPullRequest.html_url)) {
|
||||||
Write-Host "##vso[task.logissue type=error;] Unexpected error occurs while creating pull request."
|
Write-Host "Unexpected error occurs while creating pull request."
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-host "##[section] Pull request created: $($createdPullRequest.html_url)"
|
Write-host "Pull request created: $($createdPullRequest.html_url)"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Configure local git preferences"
|
Write-Host "Configure local git preferences"
|
||||||
@@ -87,8 +84,9 @@ Git-CommitAllChanges -Message $CommitMessage
|
|||||||
Write-Host "Push branch: $BranchName"
|
Write-Host "Push branch: $BranchName"
|
||||||
Git-PushBranch -Name $BranchName -Force $true
|
Git-PushBranch -Name $BranchName -Force $true
|
||||||
|
|
||||||
$gitHubApi = Get-GitHubApi -AccountName $RepositoryOwner -ProjectName $RepositoryName -AccessToken $AccessToken
|
$gitHubApi = Get-GitHubApi -RepositoryFullName $RepositoryFullName -AccessToken $AccessToken
|
||||||
$pullRequest = $gitHubApi.GetPullRequest($BranchName, $RepositoryOwner)
|
$repositoryOwner = $RepositoryFullName.Split('/')[0]
|
||||||
|
$pullRequest = $gitHubApi.GetPullRequest($BranchName, $repositoryOwner)
|
||||||
|
|
||||||
if ($pullRequest.Count -gt 0) {
|
if ($pullRequest.Count -gt 0) {
|
||||||
Write-Host "Update pull request"
|
Write-Host "Update pull request"
|
||||||
|
|||||||
@@ -5,15 +5,13 @@ The module that contains a bunch of methods to interact with GitHub API V3
|
|||||||
class GitHubApi
|
class GitHubApi
|
||||||
{
|
{
|
||||||
[string] $BaseUrl
|
[string] $BaseUrl
|
||||||
[string] $RepoOwner
|
|
||||||
[object] $AuthHeader
|
[object] $AuthHeader
|
||||||
|
|
||||||
GitHubApi(
|
GitHubApi(
|
||||||
[string] $AccountName,
|
[string] $RepositoryFullName,
|
||||||
[string] $ProjectName,
|
|
||||||
[string] $AccessToken
|
[string] $AccessToken
|
||||||
) {
|
) {
|
||||||
$this.BaseUrl = $this.BuildBaseUrl($AccountName, $ProjectName)
|
$this.BaseUrl = $this.BuildBaseUrl($RepositoryFullName)
|
||||||
$this.AuthHeader = $this.BuildAuth($AccessToken)
|
$this.AuthHeader = $this.BuildAuth($AccessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,8 +25,8 @@ class GitHubApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[string] hidden BuildBaseUrl([string]$RepositoryOwner, [string]$RepositoryName) {
|
[string] hidden BuildBaseUrl([string]$RepositoryFullName) {
|
||||||
return "https://api.github.com/repos/$RepositoryOwner/$RepositoryName"
|
return "https://api.github.com/repos/$RepositoryFullName"
|
||||||
}
|
}
|
||||||
|
|
||||||
[object] CreateNewPullRequest([string]$Title, [string]$Body, [string]$BranchName){
|
[object] CreateNewPullRequest([string]$Title, [string]$Body, [string]$BranchName){
|
||||||
@@ -82,6 +80,35 @@ class GitHubApi
|
|||||||
return $releases
|
return $releases
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[void] DispatchWorkflow([string]$EventType) {
|
||||||
|
$url = "dispatches"
|
||||||
|
$body = @{
|
||||||
|
event_type = $EventType
|
||||||
|
} | ConvertTo-Json
|
||||||
|
|
||||||
|
$this.InvokeRestMethod($url, 'POST', $null, $body)
|
||||||
|
}
|
||||||
|
|
||||||
|
[object] GetWorkflowRuns([string]$WorkflowFileName) {
|
||||||
|
$url = "actions/workflows/$WorkflowFileName/runs"
|
||||||
|
return $this.InvokeRestMethod($url, 'GET', $null, $null)
|
||||||
|
}
|
||||||
|
|
||||||
|
[object] GetWorkflowRunJobs([string]$WorkflowRunId) {
|
||||||
|
$url = "actions/runs/$WorkflowRunId/jobs"
|
||||||
|
return $this.InvokeRestMethod($url, 'GET', $null, $null)
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] CreateWorkflowDispatch([string]$WorkflowFileName, [string]$Ref, [object]$Inputs) {
|
||||||
|
$url = "actions/workflows/${WorkflowFileName}/dispatches"
|
||||||
|
$body = @{
|
||||||
|
ref = $Ref
|
||||||
|
inputs = $Inputs
|
||||||
|
} | ConvertTo-Json
|
||||||
|
|
||||||
|
$this.InvokeRestMethod($url, 'POST', $null, $body)
|
||||||
|
}
|
||||||
|
|
||||||
[string] hidden BuildUrl([string]$Url, [string]$RequestParams) {
|
[string] hidden BuildUrl([string]$Url, [string]$RequestParams) {
|
||||||
if ([string]::IsNullOrEmpty($RequestParams)) {
|
if ([string]::IsNullOrEmpty($RequestParams)) {
|
||||||
return "$($this.BaseUrl)/$($Url)"
|
return "$($this.BaseUrl)/$($Url)"
|
||||||
@@ -117,10 +144,9 @@ class GitHubApi
|
|||||||
|
|
||||||
function Get-GitHubApi {
|
function Get-GitHubApi {
|
||||||
param (
|
param (
|
||||||
[string] $AccountName,
|
[string] $RepositoryFullName,
|
||||||
[string] $ProjectName,
|
|
||||||
[string] $AccessToken
|
[string] $AccessToken
|
||||||
)
|
)
|
||||||
|
|
||||||
return [GitHubApi]::New($AccountName, $ProjectName, $AccessToken)
|
return [GitHubApi]::New($RepositoryFullName, $AccessToken)
|
||||||
}
|
}
|
||||||
91
github/run-ci-builds.ps1
Normal file
91
github/run-ci-builds.ps1
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Trigger runs on the workflow_dispatch event to build and upload tool packages
|
||||||
|
|
||||||
|
.PARAMETER RepositoryFullName
|
||||||
|
Required parameter. The owner and repository name. For example, 'actions/versions-package-tools'
|
||||||
|
.PARAMETER AccessToken
|
||||||
|
Required parameter. PAT Token to authorize
|
||||||
|
.PARAMETER WorkflowFileName
|
||||||
|
Required parameter. The name of workflow file that will be triggered
|
||||||
|
.PARAMETER WorkflowDispatchRef
|
||||||
|
Required parameter. The reference of the workflow run. The reference can be a branch, tag, or a commit SHA.
|
||||||
|
.PARAMETER ToolVersions
|
||||||
|
Required parameter. List of tool versions to build and upload
|
||||||
|
.PARAMETER PublishReleases
|
||||||
|
Required parameter. Whether to publish releases, true or false
|
||||||
|
#>
|
||||||
|
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)] [string] $RepositoryFullName,
|
||||||
|
[Parameter(Mandatory)] [string] $AccessToken,
|
||||||
|
[Parameter(Mandatory)] [string] $WorkflowFileName,
|
||||||
|
[Parameter(Mandatory)] [string] $WorkflowDispatchRef,
|
||||||
|
[Parameter(Mandatory)] [string] $ToolVersions,
|
||||||
|
[Parameter(Mandatory)] [string] $PublishReleases
|
||||||
|
)
|
||||||
|
|
||||||
|
Import-Module (Join-Path $PSScriptRoot "github-api.psm1")
|
||||||
|
|
||||||
|
function Get-WorkflowRunLink {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory)] [object] $GitHubApi,
|
||||||
|
[Parameter(Mandatory)] [string] $WorkflowFileName,
|
||||||
|
[Parameter(Mandatory)] [string] $ToolVersion
|
||||||
|
)
|
||||||
|
|
||||||
|
$listWorkflowRuns = $GitHubApi.GetWorkflowRuns($WorkflowFileName).workflow_runs | Sort-Object -Property 'run_number' -Descending
|
||||||
|
|
||||||
|
foreach ($workflowRun in $listWorkflowRuns) {
|
||||||
|
$workflowRunJob = $gitHubApi.GetWorkflowRunJobs($workflowRun.id).jobs | Select-Object -First 1
|
||||||
|
|
||||||
|
if ($workflowRunJob.name -match $ToolVersion) {
|
||||||
|
return $workflowRun.html_url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
function Queue-Builds {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)] [object] $GitHubApi,
|
||||||
|
[Parameter(Mandatory)] [string] $ToolVersions,
|
||||||
|
[Parameter(Mandatory)] [string] $WorkflowFileName,
|
||||||
|
[Parameter(Mandatory)] [string] $WorkflowDispatchRef,
|
||||||
|
[Parameter(Mandatory)] [string] $PublishReleases
|
||||||
|
)
|
||||||
|
|
||||||
|
$inputs = @{
|
||||||
|
PUBLISH_RELEASES = $PublishReleases
|
||||||
|
}
|
||||||
|
|
||||||
|
$ToolVersions.Split(',') | ForEach-Object {
|
||||||
|
$version = $_.Trim()
|
||||||
|
$inputs.VERSION = $version
|
||||||
|
|
||||||
|
Write-Host "Queue build for $version..."
|
||||||
|
$GitHubApi.CreateWorkflowDispatch($WorkflowFileName, $WorkflowDispatchRef, $inputs)
|
||||||
|
|
||||||
|
Start-Sleep -s 10
|
||||||
|
$workflowRunLink = Get-WorkflowRunLink -GitHubApi $GitHubApi `
|
||||||
|
-WorkflowFileName $WorkflowFileName `
|
||||||
|
-ToolVersion $version
|
||||||
|
|
||||||
|
if (-not $workflowRunLink) {
|
||||||
|
Write-Host "Could not find build for $version..."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Link to the build: $workflowRunLink"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$gitHubApi = Get-GitHubApi -RepositoryFullName $RepositoryFullName -AccessToken $AccessToken
|
||||||
|
|
||||||
|
Write-Host "Versions to build: $ToolVersions"
|
||||||
|
Queue-Builds -GitHubApi $gitHubApi `
|
||||||
|
-ToolVersions $ToolVersions `
|
||||||
|
-WorkflowFileName $WorkflowFileName `
|
||||||
|
-WorkflowDispatchRef $WorkflowDispatchRef `
|
||||||
|
-PublishReleases $PublishReleases
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Generate versions manifest based on repository releases
|
Generate versions manifest based on repository releases
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
Versions manifest is needed to find the latest assets for particular version of tool
|
Versions manifest is needed to find the latest assets for particular version of tool
|
||||||
.PARAMETER GitHubRepositoryOwner
|
.PARAMETER RepositoryFullName
|
||||||
Required parameter. The organization which tool repository belongs
|
Required parameter. The owner and repository name. For example, 'actions/versions-package-tools'
|
||||||
.PARAMETER GitHubRepositoryName
|
|
||||||
Required parameter. The name of tool repository
|
|
||||||
.PARAMETER GitHubAccessToken
|
.PARAMETER GitHubAccessToken
|
||||||
Required parameter. PAT Token to overcome GitHub API Rate limit
|
Required parameter. PAT Token to overcome GitHub API Rate limit
|
||||||
.PARAMETER OutputFile
|
.PARAMETER OutputFile
|
||||||
@@ -17,8 +14,7 @@ Path to the json file with parsing configuration
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
param (
|
param (
|
||||||
[Parameter(Mandatory)] [string] $GitHubRepositoryOwner,
|
[Parameter(Mandatory)] [string] $RepositoryFullName,
|
||||||
[Parameter(Mandatory)] [string] $GitHubRepositoryName,
|
|
||||||
[Parameter(Mandatory)] [string] $GitHubAccessToken,
|
[Parameter(Mandatory)] [string] $GitHubAccessToken,
|
||||||
[Parameter(Mandatory)] [string] $OutputFile,
|
[Parameter(Mandatory)] [string] $OutputFile,
|
||||||
[Parameter(Mandatory)] [string] $ConfigurationFile
|
[Parameter(Mandatory)] [string] $ConfigurationFile
|
||||||
@@ -29,7 +25,7 @@ Import-Module (Join-Path $PSScriptRoot "manifest-utils.psm1") -Force
|
|||||||
|
|
||||||
$configuration = Read-ConfigurationFile -Filepath $ConfigurationFile
|
$configuration = Read-ConfigurationFile -Filepath $ConfigurationFile
|
||||||
|
|
||||||
$gitHubApi = Get-GitHubApi -AccountName $GitHubRepositoryOwner -ProjectName $GitHubRepositoryName -AccessToken $GitHubAccessToken
|
$gitHubApi = Get-GitHubApi -RepositoryFullName $RepositoryFullName -AccessToken $GitHubAccessToken
|
||||||
$releases = $gitHubApi.GetReleases()
|
$releases = $gitHubApi.GetReleases()
|
||||||
$versionIndex = Build-VersionsManifest -Releases $releases -Configuration $configuration
|
$versionIndex = Build-VersionsManifest -Releases $releases -Configuration $configuration
|
||||||
$versionIndex | ConvertTo-Json -Depth 5 | Out-File $OutputFile -Encoding UTF8NoBOM -Force
|
$versionIndex | ConvertTo-Json -Depth 5 | Out-File $OutputFile -Encoding UTF8NoBOM -Force
|
||||||
|
|||||||
Reference in New Issue
Block a user