Skip to content

Commit

Permalink
Merge pull request #34 from max-ieremenko/feature/ci-build
Browse files Browse the repository at this point in the history
github actions ci build
  • Loading branch information
max-ieremenko authored Nov 12, 2023
2 parents dbae200 + 47dae5a commit d39ed62
Show file tree
Hide file tree
Showing 19 changed files with 243 additions and 20 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches:
- master
- 'release/**'
paths-ignore:
- '**.md'
pull_request:
branches:
- master
- 'release/**'
paths-ignore:
- '**.md'

jobs:
build:
name: win-build
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Install dependencies
shell: pwsh
run: ./Build/install-dependencies.ps1

- name: Dotnet info
shell: pwsh
run: dotnet --info

- name: Build
shell: pwsh
run: ./Build/build.ps1 -Mode "github" -GithubToken "${{ secrets.GITHUB_TOKEN }}"

- name: Artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: |
.\bin\artifacts\*.nupkg
.\bin\artifacts\*.zip
if-no-files-found: error
19 changes: 17 additions & 2 deletions Build/build.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#Requires -Version "7.0"
#Requires -Modules @{ ModuleName="InvokeBuild"; ModuleVersion="5.10.4" }
#Requires -Modules @{ ModuleName="ThirdPartyLibraries"; ModuleVersion="3.4.1" }

[CmdletBinding()]
param (
[Parameter()]
[ValidateSet("local", "github")]
[string]
$Mode,

[Parameter()]
[string]
$GithubToken
)

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

$file = Join-Path $PSScriptRoot "build-tasks.ps1"
Invoke-Build -File $file
$file = Join-Path $PSScriptRoot "tasks/build-tasks.ps1"
$task = ($Mode -eq "github") ? "GithubBuild" : "LocalBuild"

Invoke-Build -File $file -Task $task -GithubToken $GithubToken
2 changes: 1 addition & 1 deletion Build/create-images.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

Set-StrictMode -Version Latest

$file = Join-Path $PSScriptRoot "create-images-tasks.ps1"
$file = Join-Path $PSScriptRoot "tasks/create-images-tasks.ps1"
Invoke-Build -File $file
33 changes: 33 additions & 0 deletions Build/install-dependencies.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#Requires -Version "7.0"

[CmdletBinding()]
param (
[Parameter()]
[ValidateSet(".net", "InvokeBuild", "ThirdPartyLibraries")]
[string[]]
$List = (".net", "InvokeBuild", "ThirdPartyLibraries")
)

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

. (Join-Path $PSScriptRoot "scripts/Get-ModuleVersion.ps1")
. (Join-Path $PSScriptRoot "scripts/Invoke-InstallDotNet.ps1")
. (Join-Path $PSScriptRoot "scripts/Invoke-InstallModule.ps1")

if (".net" -in $List) {
Invoke-InstallDotNet -Version "6.0.319"

$version = (Get-Content -Raw (Join-Path $PSScriptRoot "../Sources/global.json") | ConvertFrom-Json).sdk.version
Invoke-InstallDotNet -Version $version
}

if ("InvokeBuild" -in $List) {
$version = Get-ModuleVersion "InvokeBuild"
Invoke-InstallModule -Name "InvokeBuild" -Version $version
}

if ("ThirdPartyLibraries" -in $List) {
$version = Get-ModuleVersion "ThirdPartyLibraries"
Invoke-InstallModule -Name "ThirdPartyLibraries" -Version $version
}
19 changes: 19 additions & 0 deletions Build/scripts/Get-ModuleVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Get-ModuleVersion {
param (
[Parameter(Mandatory)]
[string]
$Name
)

$sources = Get-Content (Join-Path $PSScriptRoot "../build.ps1") -Raw
$tokens = $null
$errors = $null
$modules = [Management.Automation.Language.Parser]::ParseInput($sources, [ref]$tokens, [ref]$errors).ScriptRequirements.RequiredModules
foreach ($module in $modules) {
if ($module.Name -eq $Name) {
return $module.Version
}
}

throw "Module $Name not found."
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Get-Version {
function Get-ReleaseVersion {
param (
[Parameter(Mandatory)]
[ValidateScript({ Test-Path $_ })]
Expand Down
68 changes: 68 additions & 0 deletions Build/scripts/Invoke-InstallDotNet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
function Invoke-InstallDotNet {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Version
)

function Test-Version {
param (
[Parameter(Mandatory)]
[System.Management.Automation.SemanticVersion]
$Target,

[Parameter(Mandatory)]
[System.Management.Automation.SemanticVersion]
$Test
)

# 6.0 vs 7.0
if ($Target.Major -ne $Test.Major -or $Target.Minor -ne $Test.Minor) {
$false
}
else {
# 6.0.0 vs 6.0.1
# 7.0.100 vs 7.0.100-rc.2.22477.23
$Target.CompareTo($Test) -le 0
}
}

if (Get-Command -Name dotnet -ErrorAction SilentlyContinue) {
$versions = dotnet --list-sdks
foreach ($installedVersion in $versions) {
# 6.0.401 [C:\Program Files\dotnet\sdk]
$test = ($installedVersion -split " ")[0]

if (Test-Version -Target $Version -Test $test) {
Write-Output ".net sdk $test is alredy installed"
return
}
}
}

$installDir = "C:\Program Files\dotnet"
$installScript = "dotnet-install.ps1"

if ($IsLinux) {
$installDir = "/usr/share/dotnet"
$installScript = "dotnet-install.sh"
}

$downloadDir = Join-Path ([System.IO.Path]::GetTempPath()) "install-dotnet"
if (Test-Path $downloadDir) {
Remove-Item -Path $downloadDir -Recurse -Force
}

New-Item -Path $downloadDir -ItemType Directory | Out-Null

$dotnetInstall = Join-Path $downloadDir $installScript
Invoke-WebRequest -Uri "https://dot.net/v1/$installScript" -OutFile $dotnetInstall

if ($IsLinux) {
chmod +x $dotnetInstall
}

"$dotnetInstall -Version $Version -InstallDir $installDir"
& $dotnetInstall -Version $Version -InstallDir $installDir
}
21 changes: 21 additions & 0 deletions Build/scripts/Invoke-InstallModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function Invoke-InstallModule {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Name,

[Parameter(Mandatory)]
[string]
$Version
)

$test = Get-InstalledModule -Name $Name -MinimumVersion $Version -ErrorAction "SilentlyContinue"
if ($test) {
Write-Output "$Name $($test.Version) is alredy installed"
return
}

Write-Output "Install $Name $version"
Install-Module -Name $Name -RequiredVersion $Version -Force
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ param(

task Default StartDatabase, UnZip, RunTest

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

$containerId = ""
$connectionString = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ param(

task Default StartDatabase, RunTest

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

$containerId = ""
$connectionString = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ param(

task Default RunContainers, CopyModule, PublishModule, RunTest

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

$containerId = ""
$connectionString = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ param(

task Default StartDatabase, RunTest

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

$containerId = ""
$connectionString = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ param(

task Default StartDatabase, UnZip, RunTest

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

$containerId = ""
$connectionString = ""
Expand Down
24 changes: 17 additions & 7 deletions Build/build-tasks.ps1 → Build/tasks/build-tasks.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
task Default Initialize, Clean, Build, ThirdPartyNotices, Pack, UnitTest, IntegrationTest
param(
[Parameter()]
[string]
$GithubToken
)

task GithubBuild Initialize, Clean, Build, ThirdPartyNotices, Pack
task LocalBuild GithubBuild, UnitTest, IntegrationTest

task Pack PackGlobalTool, PackPoweShellModule, PackNuget472, PackManualDownload
task IntegrationTest InitializeIntegrationTest, PsDesktopTest, PsCoreTest, SdkToolTest, NetRuntimeLinuxTest, NetRuntimeWindowsTest

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

task Initialize {
$sources = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\Sources"))
$bin = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\bin"))
$root = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\..\"))
$sources = Join-Path $root "Sources"
$bin = Join-Path $root "bin"
$artifacts = Join-Path $bin "artifacts"

$script:settings = @{
nugetexe = Join-Path $PSScriptRoot "nuget.exe"
nugetexe = Join-Path $root "Build\nuget.exe"
sources = $sources
bin = $bin
artifacts = $artifacts
artifactsPowerShell = Join-Path $artifacts "PowerShell"
integrationTests = Join-Path $bin "IntegrationTests"
version = Get-Version -SourcePath $sources
version = Get-ReleaseVersion -SourcePath $sources
githubToken = $GithubToken
repositoryCommitId = git rev-parse HEAD
}

Expand All @@ -41,7 +51,7 @@ task Build {
}

task ThirdPartyNotices {
Invoke-Build -File build-tasks.third-party.ps1 -settings $settings
Invoke-Build -File "build-tasks.third-party.ps1" -settings $settings
}

task PackGlobalTool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ param(
task Default Update, Test, Publish

Enter-Build {
$repository = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "third-party-libraries"))
$repository = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "../third-party-libraries"))
$sources = $settings.sources
}

task Update {
Update-ThirdPartyLibrariesRepository -AppName "SqlDatabase" -Source $sources -Repository $repository
Update-ThirdPartyLibrariesRepository -AppName "SqlDatabase" -Source $sources -Repository $repository -GithubPersonalAccessToken $settings.githubToken
}

task Test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ param(

task Default RunContainers, UpdateConfig, RunTests

Get-ChildItem -Path (Join-Path $PSScriptRoot 'scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }
Get-ChildItem -Path (Join-Path $PSScriptRoot '../scripts') -Filter *.ps1 | ForEach-Object { . $_.FullName }

$containerIds = @()
$mssqlConnectionString = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ task Default `
, BuildMySqlDatabase

Enter-Build {
$context = Join-Path $PSScriptRoot "..\Sources\Docker"
$context = Join-Path $PSScriptRoot "..\..\Sources\Docker"
}

task BuildMsSqlDatabase {
Expand Down
7 changes: 7 additions & 0 deletions Sources/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "7.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
}
}
6 changes: 6 additions & 0 deletions Sources/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>

0 comments on commit d39ed62

Please sign in to comment.