Skip to content

Commit

Permalink
Azure Pipelines Extension (Prototype) (#233)
Browse files Browse the repository at this point in the history
* add vscode-ext

* add build script
  • Loading branch information
ChristopherHX authored Oct 7, 2023
1 parent 6c63a81 commit 9f00e60
Show file tree
Hide file tree
Showing 15 changed files with 7,622 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@ jobs:
dotnet-version: 7.0.x
- name: Build ExpandAzurePipelines
run: dotnet publish src/ExpandAzurePipelines -c Release --output out
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Build azure-pipelines-vscode-ext
run: |
npm install
dotnet workload install wasm-tools
npm run build
working-directory: src/azure-pipelines-vscode-ext
- name: Make layout
run: |
mkdir webapp
mv out/wwwroot webapp/ExpandAzurePipelines
mkdir -p webapp/azure-pipelines-vscode-ext
mv src/azure-pipelines-vscode-ext/build webapp/azure-pipelines-vscode-ext/
mv src/azure-pipelines-vscode-ext/dist webapp/azure-pipelines-vscode-ext/
mv src/azure-pipelines-vscode-ext/package.json webapp/azure-pipelines-vscode-ext/
- name: Setup Pages
if: github.event_name == 'push'
uses: actions/configure-pages@v3
Expand Down
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
"processId": "${command:pickProcess}",
"requireExactSource": false
},
{
"name": "Run azure-pipelines-vscode-ext Extension",
"type": "extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}/src/azure-pipelines-vscode-ext"]
}
],
}

3 changes: 3 additions & 0 deletions src/azure-pipelines-vscode-ext/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
dist
.vscode-test-web
13 changes: 13 additions & 0 deletions src/azure-pipelines-vscode-ext/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Azure Pipelines VSCode Extension

This is a minimal Azure Pipelines Extensions

## Running the Extension

```sh
npm install
dotnet workload install wasm-tools
npm run build
```

- Run vscode target "Run azure-pipelines-vscode-ext Extension" to test it
6 changes: 6 additions & 0 deletions src/azure-pipelines-vscode-ext/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export var basePaths = {};
export var customImports = {};
export async function myimport(url) {
console.log("fake-import: " + url);
return customImports[url];
}
9 changes: 9 additions & 0 deletions src/azure-pipelines-vscode-ext/ext-core/Interop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;
using System.Runtime.InteropServices.JavaScript;
public static partial class Interop {
[JSImport("globalThis.href")]
internal static partial Task<string> GetHRef();

[JSImport("readFile", "extension.js")]
internal static partial Task<string> ReadFile(string name);
}
79 changes: 79 additions & 0 deletions src/azure-pipelines-vscode-ext/ext-core/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;

Console.WriteLine ("Hello, Console!");

public class MyClass {
[MethodImpl(MethodImplOptions.NoInlining)]
public static string CallMeFromJS()
{
return "Hello, World!";
}


private class MyEventEmitter : YamlDotNet.Serialization.EventEmitters.ChainedEventEmitter {
public MyEventEmitter(YamlDotNet.Serialization.IEventEmitter emitter) : base(emitter) {

}

private class ReplaceDescriptor : YamlDotNet.Serialization.IObjectDescriptor {
public object? Value { get; set; }

Check warning on line 21 in src/azure-pipelines-vscode-ext/ext-core/Program.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 21 in src/azure-pipelines-vscode-ext/ext-core/Program.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public Type Type { get; set; }
public Type StaticType { get; set; }
public YamlDotNet.Core.ScalarStyle ScalarStyle { get; set; }
}

public override void Emit(YamlDotNet.Serialization.ScalarEventInfo eventInfo, YamlDotNet.Core.IEmitter emitter)
{
if(eventInfo.Source.Value is string svalue) {
// Apply expression escaping to allow parsing the result without errors
if(svalue.Contains("${{")) {
eventInfo = new YamlDotNet.Serialization.ScalarEventInfo(new ReplaceDescriptor { Value = svalue.Replace("${{", "${{ '${{' }}"), Type = eventInfo.Source.Type, StaticType = eventInfo.Source.StaticType, ScalarStyle = eventInfo.Source.ScalarStyle });
}
if(svalue.Contains('\n')) {
eventInfo.Style = YamlDotNet.Core.ScalarStyle.Literal;
eventInfo.IsPlainImplicit = false;
eventInfo.IsQuotedImplicit = false;
}
}
base.Emit(eventInfo, emitter);
}
}

public class MyFileProvider : IFileProvider
{
public async Task<string> ReadFile(string repositoryAndRef, string path)
{
if(!string.IsNullOrEmpty(repositoryAndRef)) {
return await Interop.ReadFile($"{repositoryAndRef}/{path}");
}
return await Interop.ReadFile(path);
}
}


[MethodImpl(MethodImplOptions.NoInlining)]
public static async Task<string> ExpandCurrentPipeline(string currentFileName) {
// Console.WriteLine ("Hello, ExpandCurrentPipeline!");
// return "434-" + await Interop.ReadFile(filename);
try {
var content = await Interop.ReadFile(currentFileName);
var context = new Runner.Server.Azure.Devops.Context {
FileProvider = new MyFileProvider(),
TraceWriter = new GitHub.DistributedTask.ObjectTemplating.EmptyTraceWriter(),
Flags = GitHub.DistributedTask.Expressions2.ExpressionFlags.DTExpressionsV1 | GitHub.DistributedTask.Expressions2.ExpressionFlags.ExtendedDirectives
};
var template = await AzureDevops.ReadTemplate(context, currentFileName);
var pipeline = await new Runner.Server.Azure.Devops.Pipeline().Parse(context.ChildContext(template, currentFileName), template);
var newcontent = pipeline.ToContextData().ToJToken().ToString();
var deserializer = new YamlDotNet.Serialization.DeserializerBuilder().Build();
var serializer = new YamlDotNet.Serialization.SerializerBuilder().WithEventEmitter(emitter => {
return new MyEventEmitter(emitter);
}).Build();
return serializer.Serialize(deserializer.Deserialize<Object>(newcontent));
} catch(Exception ex) {
return ex.ToString();
}
}
}
16 changes: 16 additions & 0 deletions src/azure-pipelines-vscode-ext/ext-core/ext-core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetArchitecture>wasm</TargetArchitecture>
<TargetOS>Browser</TargetOS>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseMonoRuntime>true</UseMonoRuntime>
<OutputType>Exe</OutputType>
<WasmEnableES6>true</WasmEnableES6>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Sdk\Sdk.csproj" />
</ItemGroup>
</Project>
Loading

0 comments on commit 9f00e60

Please sign in to comment.