1
0
Fork 0
mirror of https://code.forgejo.org/actions/go-versions synced 2025-07-05 00:05:58 +02:00

Implement builders to build Go from source code

This commit is contained in:
MaksimZhukov 2020-06-09 22:52:06 +03:00
parent 8c06ab5f1e
commit 6cf25b0561
21 changed files with 836 additions and 0 deletions

71
builders/build-go.ps1 Normal file
View file

@ -0,0 +1,71 @@
using module "./builders/win-go-builder.psm1"
using module "./builders/nix-go-builder.psm1"
<#
.SYNOPSIS
Generate Go artifact.
.DESCRIPTION
Main script that creates instance of GoBuilder and builds of Go using specified parameters.
.PARAMETER Version
Required parameter. The version with which Go will be built.
.PARAMETER Architecture
Optional parameter. The architecture with which Go will be built. Using x64 by default.
.PARAMETER Platform
Required parameter. The platform for which Go will be built.
#>
param(
[Parameter (Mandatory=$true)][version] $Version,
[Parameter (Mandatory=$true)][string] $Platform,
[string] $Architecture = "x64"
)
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "nix-helpers.psm1") -DisableNameChecking
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "win-helpers.psm1") -DisableNameChecking
function Get-GoBuilder {
<#
.SYNOPSIS
Wrapper for class constructor to simplify importing GoBuilder.
.DESCRIPTION
Create instance of GoBuilder with specified parameters.
.PARAMETER Version
The version with which Go will be built.
.PARAMETER Platform
The platform for which Go will be built.
.PARAMETER Architecture
The architecture with which Go will be built.
#>
param (
[version] $Version,
[string] $Architecture,
[string] $Platform
)
$Platform = $Platform.ToLower()
if ($Platform -match 'win32') {
$builder = [WinGoBuilder]::New($Version, $Platform, $Architecture)
} elseif (($Platform -match 'linux') -or ($Platform -match 'darwin')) {
$builder = [NixGoBuilder]::New($Version, $Platform, $Architecture)
} else {
Write-Host "##vso[task.logissue type=error;] Invalid platform: $Platform"
exit 1
}
return $builder
}
### Create Go builder instance, and build artifact
$Builder = Get-GoBuilder -Version $Version -Platform $Platform -Architecture $Architecture
$Builder.Build()