Skip to content

Commit 9fab791

Browse files
Xml to markdown with Workflow (#132)
* essential functions of script * saving md * saving md * saving md * saving md * saving md * saving md checking how it looks on github * saving md * Test action * test action * Create main.yml * Update main.yml * Moved MarkdownOut files to the XML project The markdown out proj was framework 4.5 * Update main.yml * use system specific set path directory seperator for file access * Update main.yml * Update main.yml * Update main.yml * Update main.yml * Update main.yml * Update main.yml * Update main.yml * remove extra files and rename output MD file * Update and rename main.yml to ConvertGuidelinesXmlToMarkdown.yml * Update ConvertGuidelinesXmlToMarkdown.yml * Print C# guidelines as a heading at top of file * Update ConvertGuidelinesXmlToMarkdown.yml * Update ConvertGuidelinesXmlToMarkdown.yml * new coding guidelines MD File created * Apply suggestions from code review Co-authored-by: Kevin B <[email protected]> * Added IntelliTect Analyzers and suppressed some null string warnings. The null public parameter warnings were apart of code copied from an old project. This code isn't going to be used in production, so I didn't refactor. * Guideline class now has correct GetHashCode and Equals methods * Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Trying to figure out how to have a string env variable for the job Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml Update ConvertGuidelinesXmlToMarkdown.yml positive logic git hub actions proceed only if the xml file was modified in the previous commit ( git diff HEAD~1 HEAD) get xml filename as argument Update ConvertGuidelinesXmlToMarkdown.yml * Use simple-diff action * Update ConvertGuidelinesXmlToMarkdown.yml Co-authored-by: twofingerrightclick <[email protected]> Co-authored-by: Kevin B <[email protected]>
1 parent 31d6c3f commit 9fab791

File tree

13 files changed

+1286
-302
lines changed

13 files changed

+1286
-302
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#if the guidelines xml file is modified between commits to the master branch the associate markdown file is updated
2+
name: Update csharp Markdown
3+
4+
on:
5+
push:
6+
branches:
7+
- 'master'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
XmlFileName: "Guidelines(8th Edition).xml"
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
ref: ${{ github.ref }}
20+
- name: Simple Diff
21+
uses: mudlabs/[email protected]
22+
id: diff
23+
with:
24+
# The path of the file or folder to find in the commits diff tree.
25+
path: ./docs/${{ env.XmlFileName }}
26+
# continue even if the xml file if the file isn't found in the diff tree (it wasn't changed). strict=true causes the action to fail otherwise
27+
strict : false
28+
- name: Guidelines xml status
29+
run: |
30+
echo "${{ env.XmlFileName }} modified = ${{ steps.diff.outputs.modified }}"
31+
echo "${{ steps.diff.outputs.name }}"
32+
33+
- name: Setup .NET Core
34+
uses: actions/setup-dotnet@v1
35+
with:
36+
dotnet-version: 3.1.301
37+
if: steps.diff.outputs.modified == true
38+
39+
- name: restore_compile_run_createMD
40+
run: |
41+
dotnet restore
42+
dotnet run --configuration Release --project ./XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj
43+
./XMLtoMD/GuidelineXmlToMD/bin/Release/netcoreapp3.1/GuidelineXmlToMD "${{ env.XmlFileName }}"
44+
if: steps.diff.outputs.modified == true
45+
46+
- name: Create commit and push to CodingGuideLinesMDUpdate
47+
run: |
48+
git config user.name '${{ github.actor }}'
49+
git config user.email '${{ github.actor }}@users.noreply.github.com'
50+
git add -A
51+
git commit -m "new coding guidelines MD File created"
52+
git push origin '${{ github.ref }}'
53+
if: steps.diff.outputs.modified == true
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "<Pending>")]
9+
[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "From an Old Github Project, not for production")]
10+
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "<Pending>")]
11+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
3+
4+
namespace GuidelineXmlToMD
5+
{
6+
public class Guideline
7+
{
8+
public string Key { get; set; } = "";
9+
public string Text { get; set; } = "";
10+
11+
public string Severity { get; set; } = "";
12+
13+
public string Section { get; set; } = "";
14+
public string Subsection { get; set; } = "";
15+
16+
public List<string> Comments { get;} = new List<string>();
17+
18+
public override int GetHashCode()
19+
{
20+
return Key.GetHashCode();
21+
}
22+
23+
public override bool Equals(object obj)
24+
{
25+
Guideline otherGuideline = obj as Guideline;
26+
27+
return otherGuideline != null && string.Equals(otherGuideline.Key, this.Key);
28+
}
29+
30+
}
31+
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Xml.Linq;
6+
7+
namespace GuidelineXmlToMD
8+
{
9+
static class GuidelineXmlFileReader
10+
{
11+
public const string _Guideline = "guideline";
12+
public const string _Key = "key";
13+
public const string _Severity = "severity";
14+
15+
public const string _Section = "section";
16+
public const string _Subsection = "subsection";
17+
public const string _Comments = "comments";
18+
19+
20+
public static ICollection<Guideline> ReadExisitingGuidelinesFile(string pathToExistingGuidelinesXml)
21+
{
22+
23+
XDocument previousGuidelines = XDocument.Load(pathToExistingGuidelinesXml);
24+
25+
HashSet<Guideline> guidelines = new HashSet<Guideline>();
26+
27+
foreach (XElement guidelineFromXml in previousGuidelines.Root.DescendantNodes().OfType<XElement>())
28+
{
29+
Guideline guideline = new Guideline();
30+
guideline.Severity = guidelineFromXml.Attribute(_Severity)?.Value;
31+
guideline.Subsection = guidelineFromXml.Attribute(_Subsection)?.Value;
32+
guideline.Section = guidelineFromXml.Attribute(_Section)?.Value;
33+
guideline.Text = guidelineFromXml?.Value;
34+
guideline.Key = guidelineFromXml.Attribute(_Key)?.Value;
35+
36+
guidelines.Add(guideline);
37+
}
38+
return guidelines;
39+
}
40+
41+
}
42+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Folder Include="MarkdownOut\" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="IntelliTect.Analyzers" Version="0.1.8" />
14+
</ItemGroup>
15+
16+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30225.117
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GuidelineXmlToMD", "GuidelineXmlToMD.csproj", "{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {A1FCF330-0100-466C-A566-FF92F0B59E10}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace MarkdownOut {
2+
3+
/// <summary>
4+
/// A container for extension methods related to Markdown styling and formatting.
5+
/// </summary>
6+
public static class MdExtensions {
7+
8+
/// <summary>
9+
/// Styles one or more substrings of the provided string using the specified
10+
/// <see cref="MdStyle"/>.
11+
/// </summary>
12+
/// <param name="str">The string containing the substring to style.</param>
13+
/// <param name="substring">The substring to style.</param>
14+
/// <param name="style">The Markdown style to apply.</param>
15+
/// <param name="firstOnly">
16+
/// If true, only the first occurrence of the substring is styled; otherwise, all
17+
/// occurrences of the substring are styled.
18+
/// </param>
19+
/// <returns>
20+
/// The selectively styled string. If <paramref name="str"/> does not contain any
21+
/// occurrences of <paramref name="substring"/>, it is returned unchanged.
22+
/// </returns>
23+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "<Pending>")]
24+
public static string StyleSubstring(this string str, string substring, MdStyle style,
25+
bool firstOnly = false) {
26+
if (string.IsNullOrEmpty(str))
27+
{
28+
throw new System.ArgumentException("cannot stylize empty string", nameof(str));
29+
}
30+
31+
if (string.IsNullOrEmpty(substring))
32+
{
33+
throw new System.ArgumentException("cannot stylize empty string", nameof(str));
34+
}
35+
36+
if (!firstOnly) {
37+
return str?.Replace(substring, MdText.Style(substring, style), System.StringComparison.Ordinal);
38+
}
39+
int pos = str.IndexOf(substring, System.StringComparison.Ordinal);
40+
if (pos < 0) {
41+
return str;
42+
}
43+
return str.Substring(0, pos) + MdText.Style(substring, style)
44+
+ str.Substring(pos + substring.Length);
45+
}
46+
}
47+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
namespace MarkdownOut {
2+
3+
/// <summary>
4+
/// Specifies a Markdown format to apply to a line or block of text. Formats are applied with a
5+
/// prefix string and, unlike Markdown styles (see <see cref="MdStyle"/>), cannot be selectively
6+
/// applied to substrings.
7+
/// </summary>
8+
public enum MdFormat {
9+
10+
/// <summary>
11+
/// No text format.
12+
/// </summary>
13+
None,
14+
15+
/// <summary>
16+
/// Heading 1 text format (inserts the string <c>"# "</c> in front of text).
17+
/// </summary>
18+
Heading1,
19+
20+
/// <summary>
21+
/// Heading 2 text format (inserts the string <c>"## "</c> in front of text).
22+
/// </summary>
23+
Heading2,
24+
25+
/// <summary>
26+
/// Heading 3 text format (inserts the string <c>"### "</c> in front of text).
27+
/// </summary>
28+
Heading3,
29+
30+
/// <summary>
31+
/// Heading 4 text format (inserts the string <c>"#### "</c> in front of text).
32+
/// </summary>
33+
Heading4,
34+
35+
/// <summary>
36+
/// Heading 5 text format (inserts the string <c>"##### "</c> in front of text).
37+
/// </summary>
38+
Heading5,
39+
40+
/// <summary>
41+
/// Heading 6 text format (inserts the string <c>"###### "</c> in front of text).
42+
/// </summary>
43+
Heading6,
44+
45+
/// <summary>
46+
/// Quote text format (inserts the string <c>"> "</c> in front of text).
47+
/// </summary>
48+
Quote,
49+
50+
/// <summary>
51+
/// Unordered list item text format (inserts the string <c>"- "</c> in front of text).
52+
/// </summary>
53+
UnorderedListItem,
54+
55+
/// <summary>
56+
/// Ordered list item text format (inserts the string <c>"1. "</c> in front of text).
57+
/// </summary>
58+
OrderedListItem,
59+
60+
/// <summary>
61+
/// Creates a link to the heading that matches text to write (formats the text as [Foo](#foo)).
62+
/// </summary>
63+
InternalLink,
64+
}
65+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace MarkdownOut {
2+
3+
/// <summary>
4+
/// Specifies a Markdown style to apply to a string of text. Styles are applied by wrapping text
5+
/// with a special string on each side and can be selectively applied to substrings.
6+
/// </summary>
7+
public enum MdStyle {
8+
9+
/// <summary>
10+
/// No text styling.
11+
/// </summary>
12+
None,
13+
14+
/// <summary>
15+
/// Italic text styling (surrounds text with a single <c>*</c> character on each side).
16+
/// </summary>
17+
Italic,
18+
19+
/// <summary>
20+
/// Bold text styling (surrounds text with two <c>*</c> characters on each side).
21+
/// </summary>
22+
Bold,
23+
24+
/// <summary>
25+
/// Bold italic text styling (surrounds text with three <c>*</c> characters on each side).
26+
/// </summary>
27+
BoldItalic,
28+
29+
/// <summary>
30+
/// Code text styling (surrounds text with a single <c>`</c> character on each side).
31+
/// </summary>
32+
Code,
33+
34+
/// <summary>
35+
/// Strike-through text styling (surrounds text with two <c>~</c> characters on each side).
36+
/// This style may not be supported by all Markdown parsers.
37+
/// </summary>
38+
StrikeThrough,
39+
}
40+
}

0 commit comments

Comments
 (0)