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

msbuild task and cli nugets #1992

Merged
merged 5 commits into from
Mar 25, 2021
Merged

msbuild task and cli nugets #1992

merged 5 commits into from
Mar 25, 2021

Conversation

majastrz
Copy link
Member

@majastrz majastrz commented Mar 24, 2021

Added:

  • MSBuild task
  • NuGet packaging for the MSBuild task and CLI tool
  • E2E tests for NuGet packages.

This fixes #290.

@@ -77,6 +77,109 @@ stages:
official: ${{ parameters.official }}
rid: osx-x64

- job: packages_windows
Copy link
Member Author

Choose a reason for hiding this comment

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

packages_windows [](start = 9, length = 16)

Packages have to be signed on a Windows container (limitations of the current infra), but tests have to run on the right OS as separate jobs. This is different than the GH build.

rid: win-x64
artifactSuffix: windows

- job: packages_test_linux
Copy link
Member Author

@majastrz majastrz Mar 24, 2021

Choose a reason for hiding this comment

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

packages_test_linux [](start = 9, length = 19)

Sadly no osx image in the internal pipeline, which means no E2E tests :( We do have them on the GH side, though.

@@ -0,0 +1,42 @@
<#
Prerequisites:
Copy link
Member Author

Choose a reason for hiding this comment

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

Prerequisites [](start = 0, length = 13)

Same script as in the types-az repo.

@@ -19,4 +19,30 @@
<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)/BannedSymbols.txt" />
</ItemGroup>

<!-- Nuget Publishing related properties that are common to all packages -->
Copy link
Member Author

Choose a reason for hiding this comment

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

Nuget [](start = 7, length = 5)

Copied from the types-az repo.

Prerequisites:
- Copy bicep.exe and *.pdb from Bicep CLI publish directory to bicep\ directory under this project.
-->
<Project Sdk="Microsoft.Build.NoTargets">
Copy link
Member Author

Choose a reason for hiding this comment

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

NoTargets [](start = 30, length = 9)

This is a completely custom NuGet without a real assembly, so I had to do it myself in a NoTargets SDK project :( Thankfully NuGet.exe is available in a NuGet package and works on all the major OSs.

<!--
This project prevents the e2e tests from inheriting our repo build settings.
-->
<Project>
Copy link
Member Author

Choose a reason for hiding this comment

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

Project [](start = 1, length = 7)

The e2e tests for the msbuild task involve calling msbuild to build test projects. The files in this directory isolate the test builds from our normal settings.

Pickup latest available packages (including prerelease) from local feed configured in NuGet.config.
-->
<ItemGroup>
<PackageReference Include="Azure.Bicep.CommandLine.$(RuntimeSuffix)" Version="*-*" />
Copy link
Member Author

Choose a reason for hiding this comment

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

- [](start = 82, length = 3)

This is not ok to use in a normal project, but for test purposes it's a great way of picking up the latest package from the local feed.

<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="local-packages" />
Copy link
Member Author

Choose a reason for hiding this comment

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

local-packages [](start = 28, length = 14)

The GH and ADO build is setup to drop packages here when they are built, so the project will use newest package from the build.

@@ -0,0 +1,15 @@
{
"compilerOptions": {
Copy link
Member Author

Choose a reason for hiding this comment

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

compilerOptions [](start = 5, length = 15)

I mostly set up the e2e project by copy/pasting existing things. @shenglol and @anthony-c-martin, I haven't done a whole lot of TS, so feel free to point out any weirdness.

"@types/jest": "^26.0.21",
"cross-spawn": "^7.0.3",
"jest": "^26.6.3",
"prettier": "^2.2.1",
Copy link
Member

Choose a reason for hiding this comment

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

Are you using prettier in this project?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am now :)

Comment on lines 12 to 14
const projectDir = path.normalize(path.join(__dirname, `../examples/${projectName}/`))
this.projectDir = projectDir,
this.projectFile = path.join(projectDir, `${projectName}.proj`)
Copy link
Member

@anthony-c-martin anthony-c-martin Mar 24, 2021

Choose a reason for hiding this comment

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

[nit] missing semicolons and indenting. Prettier would probably catch this if you feel like enabling 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.

Fixed by auto formatting.

encoding: "utf-8",
});

if(expectSuccess && result.status != 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Convention is to use === and !== by default unless you've got very good reasons not to

Copy link
Member Author

Choose a reason for hiding this comment

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

Might be a bit late for this - but is packaging architecture-agnostic managed DLLs an option?

e.g. invoking it via:
dotnet ./src/Bicep.Cli/bin/Debug/net5.0/bicep.dll --help

We'd need a check for dotnet >= 5 somehow (or could perhaps pull it down via nuget); which may or may not be an option for internal MSFT builds.

That was the initial approach I wanted to go with, but users with locked down pipelines do not always control which runtimes are installed on the build agents. I think in the future we can add a platform-agnostic version of the CLI nuget and update the MSBuild nuget to call dotnet on it, but the current CLI nugets will need to remain.

Copy link
Member Author

Choose a reason for hiding this comment

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

The above reply went to the wrong comment, but fixed the wrong operator also.

Comment on lines 17 to 27
public clean() {
const result = spawn.sync("git", ["clean", "-dfx", "--", this.projectDir], {
cwd: this.projectDir,
stdio: "pipe",
encoding: "utf-8",
});

if(result.status != 0) {
this.handleFailure("git", result);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

We had an issue raised about having an implicit dependency on git in our build process; might be nice to avoid this if possible - for example by staging files to a temp directory.

https://www.npmjs.com/package/nodegit is a potential solution, but I personally hate it - on some platforms it has to compile git from source which takes AGES

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 I remember that, but it's rather difficult to get all the dependencies lined up to even run these tests correctly. We can fix once we get feedback.

@@ -0,0 +1,9 @@
root = true
Copy link
Member

Choose a reason for hiding this comment

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

Worth just adding this to the top-level .editorconfig for [*.{ts,tsx,js}] rather than creating new ones?

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 good pt.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@anthony-c-martin
Copy link
Member

anthony-c-martin commented Mar 24, 2021

Might be a bit late for this - but is packaging architecture-agnostic managed DLLs an option?

e.g. invoking it via:
dotnet ./src/Bicep.Cli/bin/Debug/net5.0/bicep.dll --help

We'd need a check for dotnet >= 5 somehow (or could perhaps pull it down via nuget); which may or may not be an option for internal MSFT builds.

import * as spawn from 'cross-spawn';
import * as path from "path";
import * as fs from "fs";
import { SpawnSyncReturns } from 'node:child_process';
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Inconsistent quotes. Formatting the document in VSCode will fix these automatically if you have the prettier extension installed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed by auto formatting.

@@ -0,0 +1,6 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing license header.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed by auto formatting.

@@ -0,0 +1,72 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Missing license header.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed by auto formatting.

@majastrz majastrz merged commit 6452a40 into main Mar 25, 2021
@majastrz majastrz deleted the majastrz/msbuild branch March 25, 2021 01:10
majastrz added a commit that referenced this pull request Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need MSBuild task to integrate with build systems
3 participants