forked from actions/runner
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Azure Pipelines Extension (Prototype) (#233)
* add vscode-ext * add build script
- Loading branch information
1 parent
6c63a81
commit 9f00e60
Showing
15 changed files
with
7,622 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
build | ||
dist | ||
.vscode-test-web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / deploy
|
||
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.