diff --git a/.circleci/config.yml b/.circleci/config.yml index e052ffa91..14d0709ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,8 +1,12 @@ --- -version: 2 +version: 2.1 + +orbs: + win: circleci/windows@2.2.0 + azure-cli: circleci/azure-cli@1.0.0 jobs: - build: + test: working_directory: ~/helm.sh/helm docker: - image: circleci/golang:1.17 @@ -26,15 +30,89 @@ jobs: - run: name: test command: make test-coverage + build: + working_directory: ~/helm.sh/helm + docker: + - image: circleci/golang:1.16 + + auth: + username: $DOCKER_USER + password: $DOCKER_PASS + + environment: + GOCACHE: "/tmp/go/cache" + GOLANGCI_LINT_VERSION: "1.36.0" + + steps: + - checkout - deploy: name: deploy command: .circleci/deploy.sh + - persist_to_workspace: + root: . + paths: + - _dist/windows-amd64/* + + generate-windows-installer: + executor: win/default + steps: + - checkout + - attach_workspace: + at: 'C:\tmp\workspace' + - run: + name: Copy from Workspace + command: Copy-Item -Path "C:\tmp\workspace\_dist\*" -Destination "package\" -Recurse + - run: + name: install innosetup and build + command: Set-Location package; dir; .\build.ps1 + - persist_to_workspace: + root: . + paths: + - ./package/Output/* + - store_artifacts: + path: ./package/Output/ + + upload-binary: + executor: azure-cli/default + steps: + - azure-cli/install + - attach_workspace: + at: '/tmp/workspace' + - run: + name: Upload binary + command: cd /tmp/workspace/package/Output; az storage blob upload-batch -s . -d "$AZURE_STORAGE_CONTAINER_NAME" --pattern 'helm-*' --connection-string "$AZURE_STORAGE_CONNECTION_STRING" + workflows: version: 2 build: jobs: + - test - build: + requires: + - test filters: + branches: + only: + - main tags: only: /.*/ + - generate-windows-installer: + requires: + - build + filters: + branches: + only: + - main + tags: + only: /.*/ + - upload-binary: + requires: + - build + - generate-windows-installer + filters: + branches: + only: + - main + tags: + only: /.*/ \ No newline at end of file diff --git a/package/build.ps1 b/package/build.ps1 new file mode 100644 index 000000000..2b7c42a9a --- /dev/null +++ b/package/build.ps1 @@ -0,0 +1,46 @@ +if (![string]::IsNullOrEmpty(${Env:CIRCLE_PR_NUMBER})) { + Write-Host "Skipping deploy step; as this is a PR" + exit; +} + +if (![string]::IsNullOrEmpty(${Env:CIRCLE_TAG})) { + $ci_version = ${Env:CIRCLE_TAG} +} +elseif ( ${Env:CIRCLE_BRANCH} -eq "main" ) { + $ci_version = "canary" +} +else { + Write-Host "Skipping deploy step; this is neither a releasable branch or a tag" + exit; +} + +Invoke-WebRequest -Uri https://jrsoftware.org/download.php/is.exe -OutFile inno.exe + +$process = Start-Process -FilePath .\inno.exe -ArgumentList "/VERYSILENT", "/NORESTART" -NoNewWindow -PassThru -Wait + +$process.WaitForExit() + +Write-Host "Inno installer exit code : " $process.ExitCode + +$binary_name = "helm-" + $ci_version + "-windows-amd64" + +Write-Host "App Version :" $ci_version "Binary Name :" $binary_name + +$process = Start-Process -FilePath ${Env:ProgramFiles(x86)}"\Inno Setup 6\ISCC.exe" -ArgumentList "helm_installer.iss", "/Dversion=$ci_version", "/Dopname=$binary_name" -NoNewWindow -PassThru -Wait + +$process.WaitForExit() + +Write-Host "Inno Compiler exit code : " $process.ExitCode + + +$output = "Output\" +$binary_path = $output + $binary_name + ".exe" + +$hash = Get-FileHash -Path $binary_path -Algorithm SHA256 + +$opsha = $output + [System.IO.Path]::GetFileName($hash.Path) + $hash.Algorithm.ToLower() +$hash.Hash > $opsha + +$opshasum = $opsha + "sum" + +$hash.Hash + " " + $binary_name + ".exe" > $opshasum \ No newline at end of file diff --git a/package/helm_installer.iss b/package/helm_installer.iss new file mode 100644 index 000000000..3cf4b7542 --- /dev/null +++ b/package/helm_installer.iss @@ -0,0 +1,34 @@ +[Setup] +AppName=Helm +AppVersion={#version} +DefaultDirName={autopf}\Helm +DefaultGroupName=Helm +PrivilegesRequired=lowest +AppPublisher=Helm +AppPublisherURL=https://helm.sh +AppSupportURL=https://github.com/helm/helm +LicenseFile="windows-amd64\LICENSE" +OutputBaseFilename={#opname} + +[Files] +Source: "windows-amd64\*" ; DestDir: "{app}\bin"; + +[Registry] +Root: "HKCU"; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}\bin"; Check: NeedsAddPathHKCU(ExpandConstant('{app}\bin')) + +[Code] +function NeedsAddPathHKCU(Param: string): boolean; +var +OrigPath: string; +begin +if not RegQueryStringValue(HKEY_CURRENT_USER, +'Environment', +'Path', OrigPath) +then begin +Result := True; +exit; +end; +// look for the path with leading and trailing semicolon +// Pos() returns 0 if not found +Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0; +end; \ No newline at end of file