diff --git a/.github/workflows/url_check_workflow.yml b/.github/workflows/url_check_workflow.yml index 6b1e884f0d..81d39d1340 100644 --- a/.github/workflows/url_check_workflow.yml +++ b/.github/workflows/url_check_workflow.yml @@ -10,7 +10,8 @@ jobs: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - name: Setup dotnet uses: actions/setup-dotnet@v3 @@ -22,3 +23,17 @@ jobs: cd "URL Test" dotnet build /p:Configuration=Release /v:quiet /p:WarningLevel=1 URLTest.csproj dotnet run bin/Debug/net6.0/process.dll + continue-on-error: true + + - name: Push to Branch + run: |- + if [[ $(git diff | wc -m) == 0 ]]; then + exit 0 + fi + BRANCH=github-action-url-test + git config user.name GitHub Actions + git config user.email github-actions@github.com + git checkout -b $BRANCH + git add . + git commit -m "Code generated by URLTest" + git push --set-upstream origin $BRANCH -f \ No newline at end of file diff --git a/URL Test/Program.cs b/URL Test/Program.cs index 0f3afc90ce..9bf01429c6 100644 --- a/URL Test/Program.cs +++ b/URL Test/Program.cs @@ -15,6 +15,7 @@ using QuantConnect; using QuantConnect.Logging; +using QuantConnect.Util; using System; using System.Collections.Generic; using System.Diagnostics; @@ -44,13 +45,13 @@ public class Program const string path = ".."; const string root = "https://www.quantconnect.com/"; const string leanIo = "https://www.lean.io/"; - const string strategyPhp = "../03 Writing Algorithms/42 Strategy Library/02 Tutorials.php"; - static readonly string[] leanIoFolder = new string[] {"05 Lean CLI", "06 LEAN Engine"}; - static readonly string[] ignoreFiles = new string[] {"../Resources/indicators/using-indicator.php"}; + const string strategyPhp = $"{path}/03 Writing Algorithms/42 Strategy Library/02 Tutorials.php"; + static readonly string[] leanIoFolder = new[] { "05 Lean CLI", "06 LEAN Engine" }; + static readonly string[] ignoreFiles = new[] { $"{path}/Resources/indicators/using-indicator.php" }; static void Main() { - var leanIoErrorUrls = new string[] { + var leanIoErrorUrls = new [] { "/docs/v2/cloud-platform", "/docs/v2/local-platform", "/docs/v2/writing-algorithm", "/docs/v2/research-environment" }; @@ -237,8 +238,11 @@ private static Dictionary> GetAllUrls() foreach (var file in allFiles) { - foreach (var line in File.ReadAllLines(file)) + var hasRelativeLink = false; + var lines = File.ReadAllLines(file); + for (var i = 0; i < lines.Length; i++) { + var line = lines[i]; var end = line.IndexOf("href"); if (end < 0 ) continue; var start = line[..end].IndexOf("> GetAllUrls() { if (url[0] == '#') { + var old_url = url; url = pathToLink(file, 1) + url; + lines[i] = line = line.Replace(old_url, url.Replace(root, "/")); + hasRelativeLink = true; } else if (url.Contains("mailto:")) { @@ -305,6 +312,10 @@ private static Dictionary> GetAllUrls() } } } + if (hasRelativeLink) + { + File.WriteAllLines(file, lines); + } } foreach (var file in ignoreFiles)