Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds publishing check and makes Sharpliner self-hosted (#29)
**Makes the project use the pipeline defined using Sharpliner inside the `Sharpliner.CI` project!** Adds an AzDO task that will verify whether you have published and commited all changes into YAML files. (resolves #3) The many empty arrays in the YAML will be gone once we check in aaubry/YamlDotNet#608
- Loading branch information
Showing
9 changed files
with
159 additions
and
35 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
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
72 changes: 72 additions & 0 deletions
72
src/Sharpliner/AzureDevOps/Tasks/SharplinerValidateTask.cs
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,72 @@ | ||
using System; | ||
using YamlDotNet.Core; | ||
using YamlDotNet.Core.Events; | ||
using YamlDotNet.Serialization; | ||
|
||
namespace Sharpliner.AzureDevOps.Tasks | ||
{ | ||
/// <summary> | ||
/// This task verifies that you didn't forget to check in your YAML pipeline changes. | ||
/// </summary> | ||
public record SharplinerValidateTask : Step, IYamlConvertible | ||
{ | ||
private readonly string _pipelineProject; | ||
private readonly bool _isPosix; | ||
|
||
/// <summary> | ||
/// This task verifies that you didn't forget to check in your YAML pipeline changes. | ||
/// </summary> | ||
/// <param name="pipelineProject">Path to the .csproj where pipelines are defined</param> | ||
/// <param name="isPosix">True for bash, false for PowerShell (based on OS)</param> | ||
public SharplinerValidateTask(string pipelineProject, bool isPosix, string displayName = "Validate YAML is published") | ||
: base(displayName) | ||
{ | ||
if (string.IsNullOrEmpty(pipelineProject)) | ||
{ | ||
throw new ArgumentException($"'{nameof(pipelineProject)}' cannot be null or empty.", nameof(pipelineProject)); | ||
} | ||
|
||
_pipelineProject = pipelineProject; | ||
_isPosix = isPosix; | ||
} | ||
|
||
private string GetValidationScript() => string.Join( | ||
"\n", | ||
_isPosix | ||
? new[] | ||
{ | ||
$"dotnet build \"{_pipelineProject}\"", | ||
"if [[ `git status --porcelain | grep -i '.ya\\?ml$'` ]]; then", | ||
$" echo 'Please rebuild {_pipelineProject} locally and commit the YAML changes' 1>&2", | ||
" exit 1", | ||
"else", | ||
" echo 'Check succeeded - no YAML changes needed'", | ||
" exit 0", | ||
"fi", | ||
} | ||
: new[] | ||
{ | ||
$"dotnet build \"{_pipelineProject}\"", | ||
"$results = Invoke-Expression \"git status --porcelain\" | Select-String -Pattern \"\\.ya?ml$\"", | ||
"if (!$results) {", | ||
" Write-Host 'Check succeeded - no YAML changes needed'", | ||
" exit 0", | ||
"} else {", | ||
$" Write-Error 'Please rebuild {_pipelineProject} locally and commit the YAML changes'", | ||
" exit 1", | ||
"}", | ||
}); | ||
|
||
public void Read(IParser parser, Type expectedType, ObjectDeserializer nestedObjectDeserializer) => throw new NotImplementedException(); | ||
|
||
public void Write(IEmitter emitter, ObjectSerializer nestedObjectSerializer) | ||
{ | ||
emitter.Emit(new MappingStart()); | ||
emitter.Emit(new Scalar(_isPosix ? "bash" : "powershell")); | ||
emitter.Emit(new Scalar(GetValidationScript())); | ||
emitter.Emit(new Scalar("displayName")); | ||
emitter.Emit(new Scalar(DisplayName)); | ||
emitter.Emit(new MappingEnd()); | ||
} | ||
} | ||
} |
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