-
Notifications
You must be signed in to change notification settings - Fork 119
Learning Paths Automation #5904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
227 commits
Select commit
Hold shift + click to select a range
7dbd0fb
Put Learning Path In-Progress Staleness Checker Back In Main
kkeirstead 0d45cbd
Update architecture.md
kkeirstead 67cf509
Update collectionrules.md
kkeirstead 1673989
Update collectionrules.md
kkeirstead 5b5de00
Update check-learning-path-links.yml
kkeirstead 9ce6f72
Update check-learning-path-links.yml
kkeirstead 0598e8a
Update check-learning-path-links.yml
kkeirstead 88ac574
Update submit-linter-suggestions.yml
kkeirstead e7d6ae7
Update check-learning-path-links.yml
kkeirstead 8fba8a1
Update submit-learning-paths-staleness-check.yml
kkeirstead c5895d0
Update submit-learning-paths-staleness-check.yml
kkeirstead 7c7530d
Update submit-learning-paths-staleness-check.yml
kkeirstead 7c8f459
Update submit-learning-paths-staleness-check.yml
kkeirstead bf6c353
Update submit-learning-paths-staleness-check.yml
kkeirstead 7d7aa67
Update submit-learning-paths-staleness-check.yml
kkeirstead 8bb85e2
Update submit-learning-paths-staleness-check.yml
kkeirstead 944ea6d
Update submit-learning-paths-staleness-check.yml
kkeirstead a960d51
Update submit-learning-paths-staleness-check.yml
kkeirstead 506152d
Update submit-learning-paths-staleness-check.yml
kkeirstead 84604ad
Update submit-linter-suggestions.yml
kkeirstead c360b09
Update check-learning-path-links.yml
kkeirstead 62d84cb
Update check-learning-path-links.yml
kkeirstead 82c54b4
Update configuration.md
kkeirstead 0a1a0f7
Update collectionrules.md
kkeirstead b287d1b
Update testing.md
kkeirstead 0d1afa3
Update check-learning-path-links.yml
kkeirstead cee5e3e
Create check-learning-path-links.yml
kkeirstead 16b85eb
Create submit-learning-paths-staleness-check.yml
kkeirstead 9394604
Update CollectionRulePipelineState.cs
kkeirstead 68ba9e9
Update collectionrules.md
kkeirstead 022fe98
Create check-learning-path-links-anchor.yml
kkeirstead bc9c983
Update check-learning-path-links-anchor.yml
kkeirstead eae3a25
Update check-learning-path-links-anchor.yml
kkeirstead 8374303
Update check-learning-path-links-anchor.yml
kkeirstead 0db0016
Update check-learning-path-links-anchor.yml
kkeirstead f9f3876
Update check-learning-path-links-anchor.yml
kkeirstead 701008b
Update check-learning-path-links.yml
kkeirstead 843999f
Create learning-path-sha
kkeirstead e4b4780
Rename learning-path-sha to learning-path-sha.txt
kkeirstead 8d2ed6a
Update check-learning-path-links.yml
kkeirstead 711252c
Update check-learning-path-links.yml
kkeirstead 2757cc3
Merge branch 'dotnet:main' into main
kkeirstead cb2f02b
Merge branch 'main' into kkeirstead/AddLearningPathStalenessWorkflow
kkeirstead c56fa15
Merge pull request #261 from kkeirstead/kkeirstead/AddLearningPathSta…
kkeirstead 2a88074
Update check-learning-path-links.yml
kkeirstead eaa404a
Update check-learning-path-links.yml
kkeirstead ab976a3
Update check-learning-path-links.yml
kkeirstead e7c58d3
Update learning-path-sha.txt
kkeirstead 945807d
Update learning-path-sha.txt
kkeirstead eff79e2
Update check-learning-path-links.yml
kkeirstead 0895a6a
Update check-learning-path-links.yml
kkeirstead be97bff
Update check-learning-path-links.yml
kkeirstead 4494324
Update check-learning-path-links.yml
kkeirstead bef96bf
Update check-learning-path-links.yml
kkeirstead 4eeba5d
Update check-learning-path-links.yml
kkeirstead a486546
Update learning-path-sha.txt
kkeirstead ace309c
Update check-learning-path-links.yml
kkeirstead 465dce9
Update check-learning-path-links.yml
kkeirstead 2111e60
Update check-learning-path-links.yml
kkeirstead a211c7d
Update learning-path-sha.txt
kkeirstead c7c3b3a
Create submit-stale-learning-path-issue.yml
kkeirstead 190a505
Update check-learning-path-links.yml
kkeirstead 23049ea
Update submit-stale-learning-path-issue.yml
kkeirstead 6e9e510
Update EgressHelper.cs
kkeirstead 9a5d1f2
Update check-learning-path-links.yml
kkeirstead 7f5ff7b
Update submit-stale-learning-path-issue.yml
kkeirstead 6033ca9
Update submit-stale-learning-path-issue.yml
kkeirstead c72f5d4
Update submit-stale-learning-path-issue.yml
kkeirstead f8a6fae
Update submit-stale-learning-path-issue.yml
kkeirstead cfebc7c
Update submit-stale-learning-path-issue.yml
kkeirstead 1cc3da5
Update submit-stale-learning-path-issue.yml
kkeirstead 54a6812
Update submit-stale-learning-path-issue.yml
kkeirstead 274db27
Update submit-stale-learning-path-issue.yml
kkeirstead 823f758
Update submit-stale-learning-path-issue.yml
kkeirstead 5eae261
Update submit-stale-learning-path-issue.yml
kkeirstead 17cd018
Update submit-stale-learning-path-issue.yml
kkeirstead f2a7e2c
Update submit-stale-learning-path-issue.yml
kkeirstead 386d6a2
Update submit-stale-learning-path-issue.yml
kkeirstead 58e9bc0
Update learning-path-sha.txt
kkeirstead a5d0c59
Update EgressHelper.cs
kkeirstead 44d2f29
Create scan-for-learning-path-update-comments.yml
kkeirstead acaaf35
Create create_learning_path_update_pr.yml
kkeirstead 3a240d7
Update and rename create_learning_path_update_pr.yml to create-learni…
kkeirstead 90fcc49
Update create-learning-path-update.yml
kkeirstead 2473eaa
Update create-learning-path-update.yml
kkeirstead 3bd654f
Update create-learning-path-update.yml
kkeirstead 7fb1f7b
Update create-learning-path-update.yml
kkeirstead c83582b
Update create-learning-path-update.yml
kkeirstead 1ba6f86
Update create-learning-path-update.yml
kkeirstead 8da66d5
Update create-learning-path-update.yml
kkeirstead 8e1a8d6
Update scan-for-learning-path-update-comments.yml
kkeirstead c482b96
Update create-learning-path-update.yml
kkeirstead e7dec34
Update create-learning-path-update.yml
kkeirstead 0136c87
Update create-learning-path-update.yml
kkeirstead ccecf7b
Update egress.md
kkeirstead 8ac1b8f
Update configuration.md
kkeirstead 6a2e424
Update create-learning-path-update.yml
kkeirstead cb9567f
Update submit-stale-learning-path-issue.yml
kkeirstead e97654d
Update submit-stale-learning-path-issue.yml
kkeirstead aa0e813
Update submit-stale-learning-path-issue.yml
kkeirstead 1d56135
Update api.md
kkeirstead 41885de
Update collectionrules.md
kkeirstead 9637669
Update configuration.md
kkeirstead 312bb91
Update testing.md
kkeirstead b7d04ca
Update egress.md
kkeirstead 53a0afb
Update learning-path-sha.txt
kkeirstead c88b427
Update EgressHelper.cs
kkeirstead 8d11485
Update check-learning-path-links.yml
kkeirstead 370f1fb
Merge branch 'dotnet:main' into main
kkeirstead 9136b99
Update EgressHelper.cs
kkeirstead 52adc14
Update EgressHelper.cs
kkeirstead 69d76b6
Update learning-path-sha.txt
kkeirstead 6a8b650
Update create-learning-path-update.yml
kkeirstead 77af0ae
Update check-learning-path-links.yml
kkeirstead f27a24b
Update scan-for-learning-path-update-comments.yml
kkeirstead e37e25a
Update create-learning-path-update.yml
kkeirstead e7e08c0
Update scan-for-learning-path-update-comments.yml
kkeirstead 8546a5b
Update scan-for-to-do-comments.yml
kkeirstead 1cd92ec
Update scan-for-to-do-comments.yml
kkeirstead 71914d8
Update scan-for-learning-path-update-comments.yml
kkeirstead 8015caa
Update create-learning-path-update.yml
kkeirstead bd0b171
Update scan-for-learning-path-update-comments.yml
kkeirstead 6ca7e20
Update scan-for-learning-path-update-comments.yml
kkeirstead de545b8
Update scan-for-learning-path-update-comments.yml
kkeirstead 29e6db3
Update create-learning-path-update.yml
kkeirstead dd8f585
Update create-learning-path-update.yml
kkeirstead 5484736
Update scan-for-learning-path-update-comments.yml
kkeirstead bb2c28b
Update create-learning-path-update.yml
kkeirstead 7eff2fd
Update scan-for-learning-path-update-comments.yml
kkeirstead c8d184e
Update Learning Path Links
invalid-email-address 5071b6f
Update submit-stale-learning-path-issue.yml
kkeirstead 1a5dfba
Merge pull request #289 from kkeirstead/bot/learningPathUpdates/7eff2…
kkeirstead 47685e7
Update EgressHelper.cs
kkeirstead 09fce46
Update submit-stale-learning-path-issue.yml
kkeirstead da10a90
Update check-learning-path-links.yml
kkeirstead c3d2182
Update check-learning-path-links.yml
kkeirstead 8459ff7
Update check-learning-path-links.yml
kkeirstead 333417e
Update submit-stale-learning-path-issue.yml
kkeirstead 20959a2
Update check-learning-path-links.yml
kkeirstead 4af46e7
Update submit-stale-learning-path-issue.yml
kkeirstead bd48ba2
Update configuration.md
kkeirstead 2005c6e
Update check-learning-path-links.yml
kkeirstead 795d63a
Update architecture.md
kkeirstead a9c2888
Update configuration.md
kkeirstead 0a6fbf8
Update configuration.md
kkeirstead a911870
Update aks.md
kkeirstead 13fd703
Rename EgressHelper.cs to EgressHelperTEMP.cs
kkeirstead 30b794e
Rename EgressHelperTEMP.cs to EgressHelper.cs
kkeirstead 47e7c80
Update check-learning-path-links.yml
kkeirstead 6b9d061
Update submit-stale-learning-path-issue.yml
kkeirstead afdd7c0
Delete .github/workflows/submit-learning-paths-staleness-check.yml
kkeirstead 7ee6f16
Delete .github/workflows/check-learning-path-links-anchor.yml
kkeirstead d74672e
Update submit-stale-learning-path-issue.yml
kkeirstead 17808f2
Update submit-stale-learning-path-issue.yml
kkeirstead b32edc1
Update and rename submit-stale-learning-path-issue.yml to submit-lear…
kkeirstead 3a74409
Update and rename scan-for-learning-path-update-comments.yml to scan-…
kkeirstead e343e69
Update scan-for-learning-path-comments.yml
kkeirstead 6656e64
Update and rename create-learning-path-update.yml to submit-learning-…
kkeirstead 944656c
Update scan-for-learning-path-comments.yml
kkeirstead 90551b9
Update submit-learning-path-pr.yml
kkeirstead 3e4b077
Update check-learning-path-links.yml
kkeirstead 404b484
Update check-learning-path-links.yml
kkeirstead f45983f
Update configuration.md
kkeirstead da4874b
Update submit-learning-path-issue.yml
kkeirstead c8e72b6
Update scan-for-learning-path-comments.yml
kkeirstead 96dcc63
Update submit-learning-path-pr.yml
kkeirstead 885ade7
Update submit-learning-path-pr.yml
kkeirstead e4a7465
Update submit-learning-path-pr.yml
kkeirstead 63a4315
Delete .github/workflows/submit-to-do-issue.yml
kkeirstead 8a6c1ed
Create submit-to-do-issue.yml
kkeirstead 820b7dd
Delete .github/workflows/submit-learning-path-issue.yml
kkeirstead b2aafd4
Delete .github/workflows/scan-for-learning-path-comments.yml
kkeirstead c198c72
Update check-learning-path-links.yml
kkeirstead e33dfb5
Update check-learning-path-links.yml
kkeirstead e760400
Update check-learning-path-links.yml
kkeirstead 8b93d30
Update Learning Paths
invalid-email-address 3b4d5e1
Update egress.md
kkeirstead 945678a
Merge pull request #332 from kkeirstead/bot/learningPathUpdates/e7604…
kkeirstead 88f8a4d
Update CollectionRuleOptions.cs
kkeirstead 5d36cc1
Update collectionrules.md
kkeirstead 0ccb077
Update ServiceCollectionExtensions.cs
kkeirstead 508030e
Update and rename ConfigShowCommandHandler.cs to ConfigShowCommandHan…
kkeirstead be02c3d
Update CollectCommandHandler.cs
kkeirstead 5dd67fb
Update TargetFrameworkMonikerTraitAttribute.cs
kkeirstead f951005
Update testing.md
kkeirstead 47a07b6
Update EgressHelper.cs
kkeirstead 17b1017
Update EgressExtension.cs
kkeirstead df4ec82
Update ServiceCollectionExtensions.cs
kkeirstead 9da2478
Update EgressExtension.cs
kkeirstead b4fb1d6
Update and rename ConfigShowCommandHandlerTEST.cs to ConfigShowComman…
kkeirstead 458f303
Update CollectCommandHandler.cs
kkeirstead 9f83714
Update TargetFrameworkMonikerTraitAttribute.cs
kkeirstead 0182113
Update CollectionRuleOptions.cs
kkeirstead 151a730
Update CollectionRulePipelineState.cs
kkeirstead f076b0f
Update EgressHelper.cs
kkeirstead 5e4d90f
Update submit-linter-suggestions.yml
kkeirstead 74be50b
Update submit-to-do-issue.yml
kkeirstead e55607f
Update testing.md
kkeirstead c8c2de5
Update check-learning-path-links.yml
kkeirstead 241194b
Update submit-learning-path-pr.yml
kkeirstead b84dfd6
Merge branch 'dotnet:main' into main
kkeirstead dfbe294
Update collectionrules.md
kkeirstead a59cc50
Update api.md
kkeirstead 34aa1a3
Update aks.md
kkeirstead 82da20e
Update configuration.md
kkeirstead 090dd8c
Update egress.md
kkeirstead b34294d
Update testing.md
kkeirstead e35fc7d
Update learning-path-sha.txt
kkeirstead 8bdc20a
Create index.js
kkeirstead 8540f4c
Create action.yml
kkeirstead 6882f9c
Rename action.yml to action.yml
kkeirstead 952f10c
Rename index.js to index.js
kkeirstead 1a348ba
Create index.js
kkeirstead ea1dd10
Create action.yml
kkeirstead 02341c2
Rename .github/apply-learning-path-updates/action.yml to .github/acti…
kkeirstead d427f0c
Rename .github/apply-learning-path-updates/index.js to .github/action…
kkeirstead 19b027a
Update index.js
kkeirstead 6e08498
Update index.js
kkeirstead 033256f
Update submit-learning-path-pr.yml
kkeirstead 8cf3318
Update check-learning-path-links.yml
kkeirstead 544d8c3
Merge pull request #335 from kkeirstead/kkeirstead/LearningPathStalen…
kkeirstead f886104
Update ServiceCollectionExtensions.cs
kkeirstead 7fae97a
Update ServiceCollectionExtensions.cs
kkeirstead 42c9dc3
Update api.md
kkeirstead b8b605f
Update collectionrules.md
kkeirstead 214cbf4
Update configuration.md
kkeirstead d353d8b
Update egress.md
kkeirstead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
name: 'UpdateLearningPathCommitHashes Action' | ||
description: 'Checks the links in the learning paths for staleness' | ||
inputs: | ||
oldHash: | ||
description: 'The commit hash to replace with the newHash in the learning path directory' | ||
required: true | ||
learningPathsDirectory: | ||
description: 'The directory where the learning paths reside (e.g. documentation/learningPath)' | ||
required: true | ||
suggestions: | ||
description: 'The auto-generated suggestions from the prior workflow' | ||
required: false | ||
learningPathHashFile: | ||
description: 'The file where the commit hash being used for the learning paths is kept' | ||
required: true | ||
newHash: | ||
description: 'The commit hash used to replace the oldHash in the learning path directory' | ||
required: true | ||
|
||
runs: | ||
using: 'node16' | ||
main: 'index.js' |
This file contains hidden or 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,73 @@ | ||
const actionUtils = require('../action-utils.js'); | ||
|
||
const suggestionsSeparator = ','; | ||
const oldNewLinkSeparator = ' -> '; | ||
let modifiedFiles = []; | ||
|
||
function AppendModifiedFiles(path) | ||
{ | ||
modifiedFiles.push(path) | ||
core.setOutput('modifiedFiles', modifiedFiles.join(' ')) | ||
} | ||
|
||
function ReplaceOldWithNewText(content, oldText, newText) | ||
{ | ||
return content.replace(new RegExp(oldText, 'g'), newText); | ||
} | ||
|
||
const main = async () => { | ||
|
||
const [core] = await actionUtils.installAndRequirePackages("@actions/core"); | ||
|
||
try { | ||
const learningPathDirectory = core.getInput('learningPathsDirectory', { required: true }); | ||
const learningPathHashFile = core.getInput('learningPathHashFile', { required: true }); | ||
const suggestions = core.getInput('suggestions', { required: false }); | ||
const oldHash = core.getInput('oldHash', { required: true }); | ||
const newHash = core.getInput('newHash', { required: true }); | ||
|
||
actionUtils.writeFile(learningPathHashFile, newHash); | ||
AppendModifiedFiles(learningPathHashFile) | ||
|
||
// Scan each file in the learningPaths directory | ||
actionUtils.readdir(learningPathDirectory, (_, files) => { | ||
files.forEach(learningPathFile => { | ||
try { | ||
const fullPath = learningPathDirectory + "/" + learningPathFile | ||
const content = actionUtils.readFileSync(fullPath, "utf8") | ||
|
||
var replacedContent = content | ||
|
||
if (suggestions !== null && suggestions.trim() !== "") { | ||
const suggestionsArray = suggestions.split(suggestionsSeparator) | ||
suggestionsArray.forEach(suggestion => { | ||
const suggestionArray = suggestion.split(oldNewLinkSeparator) | ||
var oldLink = suggestionArray[0] | ||
var newLink = suggestionArray[1] | ||
oldLink = oldLink.substring(oldLink.indexOf('(') + 1, oldLink.lastIndexOf(')')) | ||
newLink = newLink.substring(newLink.indexOf('(') + 1, newLink.lastIndexOf(')')) | ||
replacedContent = ReplaceOldWithNewText(replacedContent, oldLink, newLink) | ||
}) | ||
} | ||
|
||
replacedContent = ReplaceOldWithNewText(replacedContent, oldHash, newHash) | ||
|
||
actionUtils.writeFile(learningPathDirectory + "/" + learningPathFile, replacedContent); | ||
|
||
if (content !== replacedContent) { | ||
AppendModifiedFiles(fullPath) | ||
} | ||
} catch (error) { | ||
console.log("Error: " + error) | ||
console.log("Could not find learning path file: " + learningPathFile) | ||
} | ||
}); | ||
}); | ||
|
||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
// Call the main function to run the action | ||
main(); |
This file contains hidden or 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,27 @@ | ||
name: 'CheckLearningPathLinks Action' | ||
description: 'Checks the links in the learning paths for staleness' | ||
inputs: | ||
repoURLToSearch: | ||
description: 'The repo referenced in the learning path docs (in URL form)' | ||
required: true | ||
learningPathsDirectory: | ||
description: 'The directory where the learning paths reside (e.g. documentation/learningPath)' | ||
required: true | ||
changedFilePaths: | ||
description: 'Paths to the changed files' | ||
required: false | ||
sourceDirectoryName: | ||
description: 'The name of the top-level directory (e.g. src) - only files inside this directory will be included in the search' | ||
required: true | ||
oldHash: | ||
description: 'The hash currently being used by the learning path' | ||
required: true | ||
newHash: | ||
description: 'The hash to be inserted into the updated learning path' | ||
required: true | ||
excludeLinks: | ||
description: 'Comma separated strings to exclude from processing' | ||
required: false | ||
runs: | ||
using: 'node16' | ||
main: 'index.js' |
This file contains hidden or 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,227 @@ | ||
const actionUtils = require('../action-utils.js'); | ||
const prevPathPrefix = "prev/"; | ||
const headPathPrefix = "head/"; | ||
const linePrefix = "#L"; | ||
const separator = " | "; | ||
const sourceDirectoryName = core.getInput('sourceDirectoryName', { required: true }); | ||
const oldHash = core.getInput('oldHash', { required: true }); | ||
const newHash = core.getInput('newHash', { required: true }); | ||
const excludeLinks = core.getInput('excludeLinks', { required: false }); | ||
const excludeLinksArray = excludeLinks ? excludeLinks.split(',').map(function(item) { return item.toLowerCase().trim() }) : []; | ||
|
||
modifiedFilesDict = {}; | ||
modifiedFilesUrlToFileName = {}; | ||
|
||
var outOfSync = new Set(); | ||
var manuallyReview = new Set(); | ||
var suggestions = new Set(); | ||
|
||
function UpdateModifiedFiles(fileName, path, learningPathFile) | ||
{ | ||
modifiedFilesUrlToFileName[path] = fileName; | ||
|
||
modifiedFilesDict[path] = modifiedFilesDict[path] ? modifiedFilesDict[path] : new Set();; | ||
modifiedFilesDict[path].add(learningPathFile); | ||
|
||
var modifiedFiles = new Set(); | ||
for (currPath in modifiedFilesDict) | ||
{ | ||
const fileName = modifiedFilesUrlToFileName[currPath]; | ||
modifiedFiles.add(AssembleModifiedFilesOutput(fileName, currPath, Array.from(modifiedFilesDict[currPath]))); | ||
} | ||
|
||
SetOutput('modifiedFiles', modifiedFiles) | ||
} | ||
|
||
function AssembleModifiedFilesOutput(fileName, path, learningPathFiles) | ||
{ | ||
return CreateLink(fileName, path, undefined) + separator + BoldedText(learningPathFiles.join(" ")); | ||
} | ||
|
||
function BoldedText(text) | ||
{ | ||
return "**" + text + "**"; | ||
} | ||
|
||
function UpdateManuallyReview(fileName, path, learningPathFile, learningPathLineNumber, lineNumber = undefined) | ||
{ | ||
manuallyReview.add(AssembleOutput(fileName, path, undefined, lineNumber, undefined, learningPathFile, learningPathLineNumber)) | ||
SetOutput('manuallyReview', manuallyReview) | ||
} | ||
|
||
function UpdateOutOfSync(link, learningPathFile) | ||
{ | ||
outOfSync.add(link + separator + BoldedText(learningPathFile)) | ||
SetOutput('outOfSync', outOfSync) | ||
} | ||
|
||
// Suggestions - A line reference has changed in this PR, and the PR Author should update the line accordingly. | ||
// There are edge cases where this may make an incorrect recommendation, so the PR author should verify that | ||
// this is the correct line to reference. | ||
function UpdateSuggestions(fileName, oldPath, newPath, learningPathFile, learningPathLineNumber, oldLineNumber, newLineNumber) | ||
{ | ||
suggestions.add(AssembleOutput(fileName, oldPath, newPath, oldLineNumber, newLineNumber, learningPathFile, learningPathLineNumber)) | ||
SetOutput('suggestions', suggestions) | ||
} | ||
|
||
function SetOutput(outputName, outputSet) | ||
{ | ||
core.setOutput(outputName, Array.from(outputSet).join(",")) | ||
} | ||
|
||
function CreateLink(fileName, path, lineNumber) | ||
{ | ||
var codeFileLink = "[" + fileName + "]" + "(" + path + ")" | ||
return AppendLineNumber(codeFileLink, lineNumber) | ||
} | ||
|
||
function AssembleOutput(fileName, oldPath, newPath, oldLineNumber, newLineNumber, learningPathFile, learningPathLineNumber) | ||
{ | ||
var codeFileLink = CreateLink(fileName, oldPath, oldLineNumber) | ||
|
||
if (newPath && newLineNumber) { | ||
codeFileLink += " -> " + CreateLink(fileName, newPath, newLineNumber) | ||
} | ||
|
||
return codeFileLink + separator + BoldedText(AppendLineNumber(learningPathFile, learningPathLineNumber, undefined)); | ||
} | ||
|
||
function AppendLineNumber(text, lineNumber) | ||
{ | ||
if (!lineNumber) { return text } | ||
|
||
return text + " " + linePrefix + lineNumber | ||
} | ||
|
||
function CheckForEndOfLink(str, startIndex) | ||
{ | ||
const illegalCharIndex = str.substr(startIndex).search("[(), '\`\"\}\{]|\. "); // This regex isn't perfect, but should cover most cases. | ||
return illegalCharIndex; | ||
} | ||
|
||
function StripLineNumber(link, linePrefixIndex) | ||
{ | ||
return link.substring(0, linePrefixIndex); | ||
} | ||
|
||
function GetContent(path) { | ||
try { | ||
return actionUtils.readFileSync(path, "utf8") | ||
} | ||
catch (error) {} | ||
|
||
return undefined; | ||
} | ||
|
||
function ValidateLinks(learningPathContents, repoURLToSearch, modifiedPRFiles, learningPathFile) | ||
{ | ||
// Get all indices where a link to the repo is found within the current learning path file | ||
var linkIndices = []; | ||
for(var pos = learningPathContents.indexOf(repoURLToSearch); pos !== -1; pos = learningPathContents.indexOf(repoURLToSearch, pos + 1)) { | ||
linkIndices.push(pos); | ||
} | ||
|
||
for(let startOfLink of linkIndices) | ||
{ | ||
// Clean up the link, determine if it has a line number suffix | ||
const endOfLink = startOfLink + CheckForEndOfLink(learningPathContents, startOfLink) | ||
const link = learningPathContents.substring(startOfLink, endOfLink); | ||
|
||
if (excludeLinksArray.some(excludeLink => link.toLowerCase().includes(excludeLink))) { continue; } | ||
|
||
const pathStartIndex = link.indexOf(sourceDirectoryName); | ||
if (pathStartIndex === -1) { continue } | ||
|
||
if (!link.includes(oldHash)) | ||
{ | ||
UpdateOutOfSync(link, learningPathFile); | ||
continue | ||
} | ||
|
||
const linePrefixIndex = link.indexOf(linePrefix); | ||
const linkHasLineNumber = linePrefixIndex !== -1; | ||
const pathEndIndex = linkHasLineNumber ? linePrefixIndex : endOfLink; | ||
|
||
// Check if the file being referenced by the link is one of the modified files in the PR | ||
const linkFilePath = link.substring(pathStartIndex, pathEndIndex); | ||
if (modifiedPRFiles.includes(linkFilePath)) | ||
{ | ||
const fileName = linkFilePath.substring(linkFilePath.lastIndexOf('/') + 1); | ||
|
||
UpdateModifiedFiles(fileName, linkHasLineNumber ? StripLineNumber(link, linePrefixIndex) : link, learningPathFile); | ||
|
||
// This is the line number in the learning path file that contains the link - not the #L line number in the link itself | ||
const learningPathLineNumber = learningPathContents.substring(0, startOfLink).split("\n").length; | ||
|
||
var headContent = GetContent(headPathPrefix + linkFilePath) | ||
if (!headContent) { | ||
UpdateManuallyReview(fileName, link, learningPathFile, learningPathLineNumber); | ||
continue | ||
} | ||
const headContentLines = headContent.toString().split("\n"); | ||
|
||
if (!linkHasLineNumber) { continue; } | ||
const oldLineNumber = Number(link.substring(linePrefixIndex + linePrefix.length, link.length)); | ||
|
||
var prevContent = GetContent(prevPathPrefix + linkFilePath) | ||
if (!prevContent) { continue; } | ||
const prevContentLines = prevContent.toString().split("\n"); | ||
|
||
if (prevContentLines.length < oldLineNumber) | ||
{ | ||
UpdateManuallyReview(fileName, link, learningPathFile, learningPathLineNumber, oldLineNumber); | ||
} | ||
else if (headContentLines.length < oldLineNumber || prevContentLines[oldLineNumber - 1].trim() !== headContentLines[oldLineNumber - 1].trim()) | ||
{ | ||
const newLineNumberLast = headContentLines.lastIndexOf(prevContentLines[oldLineNumber - 1]) + 1; | ||
const newLineNumberFirst = headContentLines.indexOf(prevContentLines[oldLineNumber - 1]) + 1; | ||
|
||
if (newLineNumberLast !== newLineNumberFirst) // Multiple matches found in the file | ||
{ | ||
UpdateManuallyReview(fileName, link, learningPathFile, learningPathLineNumber, oldLineNumber); | ||
} | ||
else | ||
{ | ||
let updatedLink = StripLineNumber(link.replace(oldHash, newHash), linePrefixIndex) + linePrefix + newLineNumberFirst; | ||
UpdateSuggestions(fileName, link, updatedLink, learningPathFile, learningPathLineNumber, oldLineNumber, newLineNumberFirst); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const main = async () => { | ||
|
||
const [core] = await actionUtils.installAndRequirePackages("@actions/core"); | ||
|
||
try { | ||
const learningPathDirectory = core.getInput('learningPathsDirectory', { required: true }); | ||
const repoURLToSearch = core.getInput('repoURLToSearch', { required: true }); | ||
const headLearningPathsDirectory = headPathPrefix + learningPathDirectory; | ||
const changedFilePaths = core.getInput('changedFilePaths', {required: false}); | ||
|
||
if (changedFilePaths === null || changedFilePaths.trim() === "") { return } | ||
|
||
// Scan each file in the learningPaths directory | ||
actionUtils.readdir(headLearningPathsDirectory, (_, files) => { | ||
files.forEach(learningPathFile => { | ||
try { | ||
const learningPathContents = GetContent(headLearningPathsDirectory + "/" + learningPathFile) | ||
if (learningPathContents) | ||
{ | ||
ValidateLinks(learningPathContents, repoURLToSearch, changedFilePaths.split(' '), learningPathFile) | ||
} | ||
} catch (error) { | ||
console.log("Error: " + error) | ||
console.log("Could not find learning path file: " + learningPathFile) | ||
} | ||
}); | ||
}); | ||
|
||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
// Call the main function to run the action | ||
main(); |
This file contains hidden or 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 @@ | ||
341ff64a6097fe0bc66950e254e6160abcf77b84 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid creating a regex expression from an arbitrary variable here.
content.replaceAll(oldText, newText)
should work here instead