Skip to content

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
wants to merge 227 commits into from
Closed
Show file tree
Hide file tree
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 Oct 2, 2023
0d45cbd
Update architecture.md
kkeirstead Oct 2, 2023
67cf509
Update collectionrules.md
kkeirstead Oct 2, 2023
1673989
Update collectionrules.md
kkeirstead Oct 2, 2023
5b5de00
Update check-learning-path-links.yml
kkeirstead Oct 2, 2023
9ce6f72
Update check-learning-path-links.yml
kkeirstead Oct 3, 2023
0598e8a
Update check-learning-path-links.yml
kkeirstead Oct 3, 2023
88ac574
Update submit-linter-suggestions.yml
kkeirstead Oct 3, 2023
e7d6ae7
Update check-learning-path-links.yml
kkeirstead Oct 3, 2023
8fba8a1
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
c5895d0
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
7c7530d
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
7c8f459
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
bf6c353
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
7d7aa67
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
8bb85e2
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
944ea6d
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
a960d51
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
506152d
Update submit-learning-paths-staleness-check.yml
kkeirstead Oct 3, 2023
84604ad
Update submit-linter-suggestions.yml
kkeirstead Oct 4, 2023
c360b09
Update check-learning-path-links.yml
kkeirstead Oct 4, 2023
62d84cb
Update check-learning-path-links.yml
kkeirstead Oct 4, 2023
82c54b4
Update configuration.md
kkeirstead Oct 4, 2023
0a1a0f7
Update collectionrules.md
kkeirstead Oct 4, 2023
b287d1b
Update testing.md
kkeirstead Oct 4, 2023
0d1afa3
Update check-learning-path-links.yml
kkeirstead Oct 6, 2023
cee5e3e
Create check-learning-path-links.yml
kkeirstead Oct 6, 2023
16b85eb
Create submit-learning-paths-staleness-check.yml
kkeirstead Oct 6, 2023
9394604
Update CollectionRulePipelineState.cs
kkeirstead Oct 6, 2023
68ba9e9
Update collectionrules.md
kkeirstead Oct 6, 2023
022fe98
Create check-learning-path-links-anchor.yml
kkeirstead Oct 6, 2023
bc9c983
Update check-learning-path-links-anchor.yml
kkeirstead Oct 6, 2023
eae3a25
Update check-learning-path-links-anchor.yml
kkeirstead Oct 6, 2023
8374303
Update check-learning-path-links-anchor.yml
kkeirstead Oct 6, 2023
0db0016
Update check-learning-path-links-anchor.yml
kkeirstead Oct 6, 2023
f9f3876
Update check-learning-path-links-anchor.yml
kkeirstead Oct 6, 2023
701008b
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
843999f
Create learning-path-sha
kkeirstead Jan 22, 2024
e4b4780
Rename learning-path-sha to learning-path-sha.txt
kkeirstead Jan 22, 2024
8d2ed6a
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
711252c
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
2757cc3
Merge branch 'dotnet:main' into main
kkeirstead Jan 22, 2024
cb2f02b
Merge branch 'main' into kkeirstead/AddLearningPathStalenessWorkflow
kkeirstead Jan 22, 2024
c56fa15
Merge pull request #261 from kkeirstead/kkeirstead/AddLearningPathSta…
kkeirstead Jan 22, 2024
2a88074
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
eaa404a
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
ab976a3
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
e7c58d3
Update learning-path-sha.txt
kkeirstead Jan 22, 2024
945807d
Update learning-path-sha.txt
kkeirstead Jan 22, 2024
eff79e2
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
0895a6a
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
be97bff
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
4494324
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
bef96bf
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
4eeba5d
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
a486546
Update learning-path-sha.txt
kkeirstead Jan 22, 2024
ace309c
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
465dce9
Update check-learning-path-links.yml
kkeirstead Jan 22, 2024
2111e60
Update check-learning-path-links.yml
kkeirstead Jan 23, 2024
a211c7d
Update learning-path-sha.txt
kkeirstead Jan 23, 2024
c7c3b3a
Create submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
190a505
Update check-learning-path-links.yml
kkeirstead Jan 23, 2024
23049ea
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
6e9e510
Update EgressHelper.cs
kkeirstead Jan 23, 2024
9a5d1f2
Update check-learning-path-links.yml
kkeirstead Jan 23, 2024
7f5ff7b
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
6033ca9
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
c72f5d4
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
f8a6fae
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
cfebc7c
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
1cc3da5
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
54a6812
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
274db27
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
823f758
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
5eae261
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
17cd018
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
f2a7e2c
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
386d6a2
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
58e9bc0
Update learning-path-sha.txt
kkeirstead Jan 23, 2024
a5d0c59
Update EgressHelper.cs
kkeirstead Jan 23, 2024
44d2f29
Create scan-for-learning-path-update-comments.yml
kkeirstead Jan 23, 2024
acaaf35
Create create_learning_path_update_pr.yml
kkeirstead Jan 23, 2024
3a240d7
Update and rename create_learning_path_update_pr.yml to create-learni…
kkeirstead Jan 23, 2024
90fcc49
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
2473eaa
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
3bd654f
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
7fb1f7b
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
c83582b
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
1ba6f86
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
8da66d5
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
8e1a8d6
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 23, 2024
c482b96
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
e7dec34
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
0136c87
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
ccecf7b
Update egress.md
kkeirstead Jan 23, 2024
8ac1b8f
Update configuration.md
kkeirstead Jan 23, 2024
6a2e424
Update create-learning-path-update.yml
kkeirstead Jan 23, 2024
cb9567f
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
e97654d
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
aa0e813
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 23, 2024
1d56135
Update api.md
kkeirstead Jan 24, 2024
41885de
Update collectionrules.md
kkeirstead Jan 24, 2024
9637669
Update configuration.md
kkeirstead Jan 24, 2024
312bb91
Update testing.md
kkeirstead Jan 24, 2024
b7d04ca
Update egress.md
kkeirstead Jan 24, 2024
53a0afb
Update learning-path-sha.txt
kkeirstead Jan 24, 2024
c88b427
Update EgressHelper.cs
kkeirstead Jan 24, 2024
8d11485
Update check-learning-path-links.yml
kkeirstead Jan 24, 2024
370f1fb
Merge branch 'dotnet:main' into main
kkeirstead Jan 24, 2024
9136b99
Update EgressHelper.cs
kkeirstead Jan 24, 2024
52adc14
Update EgressHelper.cs
kkeirstead Jan 24, 2024
69d76b6
Update learning-path-sha.txt
kkeirstead Jan 24, 2024
6a8b650
Update create-learning-path-update.yml
kkeirstead Jan 24, 2024
77af0ae
Update check-learning-path-links.yml
kkeirstead Jan 24, 2024
f27a24b
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
e37e25a
Update create-learning-path-update.yml
kkeirstead Jan 24, 2024
e7e08c0
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
8546a5b
Update scan-for-to-do-comments.yml
kkeirstead Jan 24, 2024
1cd92ec
Update scan-for-to-do-comments.yml
kkeirstead Jan 24, 2024
71914d8
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
8015caa
Update create-learning-path-update.yml
kkeirstead Jan 24, 2024
bd0b171
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
6ca7e20
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
de545b8
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
29e6db3
Update create-learning-path-update.yml
kkeirstead Jan 24, 2024
dd8f585
Update create-learning-path-update.yml
kkeirstead Jan 24, 2024
5484736
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
bb2c28b
Update create-learning-path-update.yml
kkeirstead Jan 24, 2024
7eff2fd
Update scan-for-learning-path-update-comments.yml
kkeirstead Jan 24, 2024
c8d184e
Update Learning Path Links
invalid-email-address Jan 24, 2024
5071b6f
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 24, 2024
1a5dfba
Merge pull request #289 from kkeirstead/bot/learningPathUpdates/7eff2…
kkeirstead Jan 24, 2024
47685e7
Update EgressHelper.cs
kkeirstead Jan 24, 2024
09fce46
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 24, 2024
da10a90
Update check-learning-path-links.yml
kkeirstead Jan 24, 2024
c3d2182
Update check-learning-path-links.yml
kkeirstead Jan 24, 2024
8459ff7
Update check-learning-path-links.yml
kkeirstead Jan 24, 2024
333417e
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 25, 2024
20959a2
Update check-learning-path-links.yml
kkeirstead Jan 25, 2024
4af46e7
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 25, 2024
bd48ba2
Update configuration.md
kkeirstead Jan 25, 2024
2005c6e
Update check-learning-path-links.yml
kkeirstead Jan 25, 2024
795d63a
Update architecture.md
kkeirstead Jan 25, 2024
a9c2888
Update configuration.md
kkeirstead Jan 25, 2024
0a6fbf8
Update configuration.md
kkeirstead Jan 25, 2024
a911870
Update aks.md
kkeirstead Jan 25, 2024
13fd703
Rename EgressHelper.cs to EgressHelperTEMP.cs
kkeirstead Jan 25, 2024
30b794e
Rename EgressHelperTEMP.cs to EgressHelper.cs
kkeirstead Jan 25, 2024
47e7c80
Update check-learning-path-links.yml
kkeirstead Jan 25, 2024
6b9d061
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 25, 2024
afdd7c0
Delete .github/workflows/submit-learning-paths-staleness-check.yml
kkeirstead Jan 25, 2024
7ee6f16
Delete .github/workflows/check-learning-path-links-anchor.yml
kkeirstead Jan 25, 2024
d74672e
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 25, 2024
17808f2
Update submit-stale-learning-path-issue.yml
kkeirstead Jan 25, 2024
b32edc1
Update and rename submit-stale-learning-path-issue.yml to submit-lear…
kkeirstead Jan 25, 2024
3a74409
Update and rename scan-for-learning-path-update-comments.yml to scan-…
kkeirstead Jan 25, 2024
e343e69
Update scan-for-learning-path-comments.yml
kkeirstead Jan 25, 2024
6656e64
Update and rename create-learning-path-update.yml to submit-learning-…
kkeirstead Jan 25, 2024
944656c
Update scan-for-learning-path-comments.yml
kkeirstead Jan 25, 2024
90551b9
Update submit-learning-path-pr.yml
kkeirstead Jan 25, 2024
3e4b077
Update check-learning-path-links.yml
kkeirstead Jan 25, 2024
404b484
Update check-learning-path-links.yml
kkeirstead Jan 25, 2024
f45983f
Update configuration.md
kkeirstead Jan 25, 2024
da4874b
Update submit-learning-path-issue.yml
kkeirstead Jan 25, 2024
c8e72b6
Update scan-for-learning-path-comments.yml
kkeirstead Jan 25, 2024
96dcc63
Update submit-learning-path-pr.yml
kkeirstead Jan 26, 2024
885ade7
Update submit-learning-path-pr.yml
kkeirstead Jan 26, 2024
e4a7465
Update submit-learning-path-pr.yml
kkeirstead Jan 26, 2024
63a4315
Delete .github/workflows/submit-to-do-issue.yml
kkeirstead Jan 26, 2024
8a6c1ed
Create submit-to-do-issue.yml
kkeirstead Jan 26, 2024
820b7dd
Delete .github/workflows/submit-learning-path-issue.yml
kkeirstead Jan 26, 2024
b2aafd4
Delete .github/workflows/scan-for-learning-path-comments.yml
kkeirstead Jan 26, 2024
c198c72
Update check-learning-path-links.yml
kkeirstead Jan 26, 2024
e33dfb5
Update check-learning-path-links.yml
kkeirstead Jan 26, 2024
e760400
Update check-learning-path-links.yml
kkeirstead Jan 26, 2024
8b93d30
Update Learning Paths
invalid-email-address Jan 26, 2024
3b4d5e1
Update egress.md
kkeirstead Jan 26, 2024
945678a
Merge pull request #332 from kkeirstead/bot/learningPathUpdates/e7604…
kkeirstead Jan 26, 2024
88f8a4d
Update CollectionRuleOptions.cs
kkeirstead Jan 26, 2024
5d36cc1
Update collectionrules.md
kkeirstead Jan 26, 2024
0ccb077
Update ServiceCollectionExtensions.cs
kkeirstead Jan 26, 2024
508030e
Update and rename ConfigShowCommandHandler.cs to ConfigShowCommandHan…
kkeirstead Jan 26, 2024
be02c3d
Update CollectCommandHandler.cs
kkeirstead Jan 26, 2024
5dd67fb
Update TargetFrameworkMonikerTraitAttribute.cs
kkeirstead Jan 26, 2024
f951005
Update testing.md
kkeirstead Jan 26, 2024
47a07b6
Update EgressHelper.cs
kkeirstead Jan 26, 2024
17b1017
Update EgressExtension.cs
kkeirstead Jan 26, 2024
df4ec82
Update ServiceCollectionExtensions.cs
kkeirstead Jan 29, 2024
9da2478
Update EgressExtension.cs
kkeirstead Jan 29, 2024
b4fb1d6
Update and rename ConfigShowCommandHandlerTEST.cs to ConfigShowComman…
kkeirstead Jan 29, 2024
458f303
Update CollectCommandHandler.cs
kkeirstead Jan 29, 2024
9f83714
Update TargetFrameworkMonikerTraitAttribute.cs
kkeirstead Jan 29, 2024
0182113
Update CollectionRuleOptions.cs
kkeirstead Jan 29, 2024
151a730
Update CollectionRulePipelineState.cs
kkeirstead Jan 29, 2024
f076b0f
Update EgressHelper.cs
kkeirstead Jan 29, 2024
5e4d90f
Update submit-linter-suggestions.yml
kkeirstead Jan 29, 2024
74be50b
Update submit-to-do-issue.yml
kkeirstead Jan 29, 2024
e55607f
Update testing.md
kkeirstead Jan 29, 2024
c8c2de5
Update check-learning-path-links.yml
kkeirstead Jan 29, 2024
241194b
Update submit-learning-path-pr.yml
kkeirstead Jan 29, 2024
b84dfd6
Merge branch 'dotnet:main' into main
kkeirstead Jan 29, 2024
dfbe294
Update collectionrules.md
kkeirstead Jan 29, 2024
a59cc50
Update api.md
kkeirstead Jan 29, 2024
34aa1a3
Update aks.md
kkeirstead Jan 29, 2024
82da20e
Update configuration.md
kkeirstead Jan 29, 2024
090dd8c
Update egress.md
kkeirstead Jan 29, 2024
b34294d
Update testing.md
kkeirstead Jan 29, 2024
e35fc7d
Update learning-path-sha.txt
kkeirstead Jan 29, 2024
8bdc20a
Create index.js
kkeirstead Jan 29, 2024
8540f4c
Create action.yml
kkeirstead Jan 29, 2024
6882f9c
Rename action.yml to action.yml
kkeirstead Jan 29, 2024
952f10c
Rename index.js to index.js
kkeirstead Jan 29, 2024
1a348ba
Create index.js
kkeirstead Jan 29, 2024
ea1dd10
Create action.yml
kkeirstead Jan 29, 2024
02341c2
Rename .github/apply-learning-path-updates/action.yml to .github/acti…
kkeirstead Jan 29, 2024
d427f0c
Rename .github/apply-learning-path-updates/index.js to .github/action…
kkeirstead Jan 29, 2024
19b027a
Update index.js
kkeirstead Jan 29, 2024
6e08498
Update index.js
kkeirstead Jan 29, 2024
033256f
Update submit-learning-path-pr.yml
kkeirstead Jan 29, 2024
8cf3318
Update check-learning-path-links.yml
kkeirstead Jan 29, 2024
544d8c3
Merge pull request #335 from kkeirstead/kkeirstead/LearningPathStalen…
kkeirstead Jan 29, 2024
f886104
Update ServiceCollectionExtensions.cs
kkeirstead Jan 29, 2024
7fae97a
Update ServiceCollectionExtensions.cs
kkeirstead Jan 29, 2024
42c9dc3
Update api.md
kkeirstead Jan 29, 2024
b8b605f
Update collectionrules.md
kkeirstead Jan 29, 2024
214cbf4
Update configuration.md
kkeirstead Jan 29, 2024
d353d8b
Update egress.md
kkeirstead Jan 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/actions/apply-learning-path-updates/action.yml
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'
73 changes: 73 additions & 0 deletions .github/actions/apply-learning-path-updates/index.js
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);
Copy link
Member

@schmittjoseph schmittjoseph Jan 29, 2024

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

}

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();
27 changes: 27 additions & 0 deletions .github/actions/learning-path-staleness-check/action.yml
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'
227 changes: 227 additions & 0 deletions .github/actions/learning-path-staleness-check/index.js
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();
1 change: 1 addition & 0 deletions .github/learning-path-sha.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
341ff64a6097fe0bc66950e254e6160abcf77b84
Loading