Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental windows setup #421

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
experimental windows setup
  • Loading branch information
majastrz committed Sep 1, 2020
commit 59b9136e483125d39fef9013d041d027c463dcfe
36 changes: 35 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ jobs:
- os: 'windows-latest'
rid: 'win-x64'
configuration: 'release'
publishLanguageServer: 'false'
- os: 'ubuntu-latest'
rid: 'linux-x64'
configuration: 'release'
publishLanguageServer: 'true'
- os: 'macos-latest'
rid: 'osx-x64'
configuration: 'release'
publishLanguageServer: 'false'

steps:
- uses: actions/checkout@v2
Expand All @@ -56,14 +59,15 @@ jobs:
run: dotnet test --configuration ${{ matrix.configuration }} --collect:"XPlat Code Coverage" --settings ./.github/workflows/codecov.runsettings

- name: Publish Language Server
if: ${{ matrix.publishLanguageServer == 'true' }}
run: dotnet publish --configuration ${{ matrix.configuration }} ./src/Bicep.LangServer/Bicep.LangServer.csproj

- name: Publish Bicep
run: dotnet publish --configuration ${{ matrix.configuration }} --self-contained true -p:PublishTrimmed=true -p:PublishSingleFile=true -r ${{ matrix.rid }} ./src/Bicep.Cli/Bicep.Cli.csproj

- name: Upload Language Server
uses: actions/upload-artifact@v2
if: ${{ matrix.rid == 'linux-x64' }}
if: ${{ matrix.publishLanguageServer == 'true' }}
with:
name: Bicep.LangServer
path: ./src/Bicep.LangServer/bin/${{ matrix.configuration }}/netcoreapp3.1/publish/*
Expand All @@ -80,6 +84,36 @@ jobs:
with:
flags: dotnet

build-windows-setup:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be added to the release as well (lower down in this file)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah intentionally left it out until we validate the installer more.

name: 'Build Windows Setup'
runs-on: 'windows-latest'
needs: build-bicep

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301

- name: Download Bicep CLI
uses: actions/download-artifact@v2
with:
name: bicep-release-win-x64
path: ./src/installer-win/bicep

- name: Build Windows Installer
run: dotnet build --configuration release ./src/installer-win/installer.proj

- name: Upload Windows Installer
uses: actions/upload-artifact@v2
with:
name: bicep-setup-win-x64
path: ./src/installer-win/bin/release/net46/bicep-setup-win-x64.exe

build-vsix:
name: 'Build VSIX'
runs-on: 'ubuntu-latest'
Expand Down
12 changes: 12 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// Defines version of MSBuild project SDKs to use
// https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019#how-project-sdks-are-resolved
"msbuild-sdks": {
"Microsoft.Build.NoTargets": "2.0.1"
},
"sdk": {
"comment": "Need to use a particular version to ensure consistency across machines no matter what SDK versions they have installed.",
"version": "3.1.301",
"RollForward": "latestFeature"
}
}
1 change: 1 addition & 0 deletions src/installer-win/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bicep/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think better to be more precise and prefix with a / (or whatever path prefix you're trying to exclude)

Copy link
Member Author

@majastrz majastrz Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .gitignore is specific to this directory only, though. I think we did something like that in the VSIX project too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you need to create bicep folders at different levels it feels unnecessary. It's often done for more general build artifacts like out or node_modules which can appear at different levels, but in this case I think you should know exactly where the folder is created.

49 changes: 49 additions & 0 deletions src/installer-win/SetPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
param (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind making a note to update the install instructions for Windows when we next have a release? Maybe we can just start another 'running items for 0.2 release' note.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #424

[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $AppPath,

[Parameter()]
[bool]
$Remove = $false
)

$ErrorActionPreference = 'Stop';

$registryPath = 'HKCU:\Environment';
$environmentVariable = 'Path';

$environmentKey = Get-Item -path $registryPath;
[string]$currentPath = $environmentKey.GetValue($environmentVariable, '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames);

$paths = $currentPath.Split(@(';'), [System.StringSplitOptions]::RemoveEmptyEntries);

if($Remove)
{
# remove path
if($paths -contains $AppPath)
{
$paths = $paths | Where-Object { $_ -ne $AppPath };
$modified = $true;
}
}
else
{
# upsert path
if(-not ($paths -contains $AppPath))
{
$paths += $AppPath;
$modified = $true;
}
}

if(-not $paths)
{
$paths = @();
}

if($modified)
{
$newPath = [string]::Join(';', $paths);
New-ItemProperty -Path $registryPath -Name $environmentVariable -PropertyType ExpandString -Value $newPath -Force | Out-Null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work without a reboot? I found that updating the reg value didn't work when I wrote the install instructions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked on my home machine immediately. The installer does something to make explorer.exe reload environment variables (there's a ChangesEnvironment=yes) setting. What you were probably seeing was explorer.exe launched processes getting stale environment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not help with any open command shells (cmd.exe, powershell, etc.) until they are reopened. However, that's a standard behavior for environments. I can make the installer force a reboot, but I don't think it's necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, no need to force a reboot. The behavior I was seeing was also with newly opened cmd/powershell windows. Sounds like the installer is doing something special to handle it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, explorer or windows must have some sort of API for these situations.

}
45 changes: 45 additions & 0 deletions src/installer-win/bicep.iss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#define MyAppName "Bicep CLI"

#ifndef MyAppVersion
#define MyAppVersion "0.0"
#endif

#define MyAppPublisher "Microsoft Corporation"
#define MyAppURL "https://github.com/Azure/bicep"
#define MyAppExeName "bicep.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{7EF9DE63-59B1-4325-955A-937F3E0A4EA8}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
DefaultGroupName={#MyAppName}
LicenseFile=..\..\LICENSE
PrivilegesRequired=lowest
OutputBaseFilename=bicep-setup-win-x64
Compression=lzma
SolidCompression=yes
WizardStyle=modern
ChangesEnvironment=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "bicep\bicep.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "bicep\bicep.pdb"; DestDir: "{app}"; Flags: ignoreversion
Source: "SetPath.ps1"; DestDir: "{app}\setup"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -Command ""& '{app}\setup\SetPath.ps1' -AppPath '{app}' -Remove $false"" "; WorkingDir: {app}; Flags: runhidden

[UninstallRun]
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -Command ""& '{app}\setup\SetPath.ps1' -AppPath '{app}' -Remove $true"" "; WorkingDir: {app}; Flags: runhidden
22 changes: 22 additions & 0 deletions src/installer-win/installer.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
This project pulls down the setup compiler from a nuget and invokes it to build the setup exe.
It depends on the published self-contained bicep.exe and bicep.pdb to be placed in a bicep subfolder.
During the CI build, this happens via artifact download action.
-->
<Project Sdk="Microsoft.Build.NoTargets">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the machine has to have .NET 4.6 installed to run the installer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's just a dummy target framework needed for a NoTargets project. The installer is not .net-based btw. I believe it's native code (Delphi I think.)

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Tools.InnoSetup" Version="6.0.5" />
</ItemGroup>

<ItemGroup>
<IssFile Include="bicep.iss" />
</ItemGroup>

<Target Name="RunTool" AfterTargets="Build" DependsOnTargets="GetBuildVersion">
<Exec Command="$(InnoSetupCompiler) %(IssFile.FullPath) /O$(OutDir) /DMyAppVersion=$(BuildVersion)" />
</Target>
</Project>