Skip to content

Commit 6cb380a

Browse files
authored
Flowing bits (#376)
* Update index.js * Update check-learning-path-links.yml * Update EgressHelper.cs * Update check-learning-path-links.yml * Update index.js * Update index.js * Update EgressHelper.cs * Update check-learning-path-links.yml * Update EgressHelper.cs * Update index.js * Update check-learning-path-links.yml * Update action.yml * Update action.yml * Update check-learning-path-links.yml * Update action.yml * Update check-learning-path-links.yml * Update action.yml * Update check-learning-path-links.yml * Update action.yml * Update action.yml * Update index.js * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update action.yml * Update index.js * Update check-learning-path-links.yml * Update index.js * Update index.js * Update index.js * Update check-learning-path-links.yml * Update action.yml * Update check-learning-path-links.yml * Update action.yml * Update check-learning-path-links.yml * Update index.js * Update check-learning-path-links.yml * Update EgressHelper.cs * Update index.js * Update EgressHelper.cs * Update index.js * Update check-learning-path-links.yml * Update index.js * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update index.js * Update check-learning-path-links.yml * Update check-learning-path-links.yml * Update index.js * Update index.js * Update index.js * Update index.js * Update action-utils.js * Update ServiceCollectionExtensions.cs * Update ServiceCollectionExtensions.cs * Update EgressHelper.cs
1 parent 10f3c72 commit 6cb380a

3 files changed

Lines changed: 33 additions & 66 deletions

File tree

.github/actions/action-utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,3 @@ module.exports.friendlyDateFromISODate = function(isoDate) {
5151

5252
module.exports.splitVersionTag = splitVersionTag;
5353
module.exports.readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8');
54-
module.exports.readFileSync = (fileName) => fs.readFileSync(fileName, 'utf8');
55-
module.exports.writeFile = (fileName, contents) => util.promisify(fs.writeFile)(fileName, contents);
56-
module.exports.writeFileSync = (fileName, contents) => fs.writeFileSync(fileName, contents);
57-
module.exports.readdir = (dirName, callback) => util.promisify(fs.readdir)(dirName, callback);

.github/actions/learning-path-staleness-check/index.js

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const actionUtils = require('../action-utils.js');
2+
const fs = require('fs');
3+
const path = require('path');
24
const prevPathPrefix = "prev/";
35
const linePrefix = "#L";
46
const separator = " | ";
57

6-
modifiedFilesDict = {};
8+
modifiedFilesPathToLearningPathFile = {};
79
modifiedFilesUrlToFileName = {};
810

911
var outOfSync = new Set();
@@ -13,14 +15,6 @@ var modifiedFiles = new Set();
1315

1416
const oldNewLinkSeparator = ' -> ';
1517

16-
let modifiedFilesToCommit = [];
17-
18-
function AppendModifiedFilesToCommit(path, core)
19-
{
20-
modifiedFilesToCommit.push(path)
21-
core.setOutput('modifiedFilesToCommit', modifiedFilesToCommit.join(' '))
22-
}
23-
2418
function ReplaceOldWithNewText(content, oldText, newText)
2519
{
2620
return content.replaceAll(oldText, newText);
@@ -30,14 +24,14 @@ function UpdateModifiedFiles(fileName, path, learningPathFile)
3024
{
3125
modifiedFilesUrlToFileName[path] = fileName;
3226

33-
modifiedFilesDict[path] = modifiedFilesDict[path] ? modifiedFilesDict[path] : new Set();;
34-
modifiedFilesDict[path].add(learningPathFile);
27+
modifiedFilesPathToLearningPathFile[path] = modifiedFilesPathToLearningPathFile[path] ? modifiedFilesPathToLearningPathFile[path] : new Set();;
28+
modifiedFilesPathToLearningPathFile[path].add(learningPathFile);
3529

3630
modifiedFiles = new Set();
37-
for (currPath in modifiedFilesDict)
31+
for (currPath in modifiedFilesPathToLearningPathFile)
3832
{
3933
const fileName = modifiedFilesUrlToFileName[currPath];
40-
modifiedFiles.add(AssembleModifiedFilesOutput(fileName, currPath, Array.from(modifiedFilesDict[currPath])));
34+
modifiedFiles.add(AssembleModifiedFilesOutput(fileName, currPath, Array.from(modifiedFilesPathToLearningPathFile[currPath])));
4135
}
4236
}
4337

@@ -92,7 +86,7 @@ function AppendLineNumber(text, lineNumber)
9286

9387
function CheckForEndOfLink(str, startIndex)
9488
{
95-
const illegalCharIndex = str.substr(startIndex).search("[(), '\`\"\}\{]|\. "); // This regex isn't perfect, but should cover most cases.
89+
const illegalCharIndex = str.substr(startIndex).search("[(), '\`\"\}\{]|\. |\.\n"); // This regex isn't perfect, but should cover most cases.
9690
return illegalCharIndex;
9791
}
9892

@@ -103,7 +97,7 @@ function StripLineNumber(link, linePrefixIndex)
10397

10498
function GetContent(path) {
10599
try {
106-
return actionUtils.readFileSync(path)
100+
return fs.readFileSync(path, 'utf8');
107101
}
108102
catch (error) {}
109103

@@ -112,21 +106,17 @@ function GetContent(path) {
112106

113107
function ConstructOutputText(core)
114108
{
115-
var manuallyReviewSection = "<h2>Manually Review:</h2>" + Array.from(manuallyReview).join("<br />") + "<br />";
116-
if (manuallyReview.size === 0) { manuallyReviewSection = ""; }
109+
var body = "";
117110

118-
var outOfSyncSection = "<h2>Links With Out Of Sync Commit Hashes:</h2>" + Array.from(outOfSync).join("<br />") + "<br />";
119-
if (outOfSync.size === 0) { outOfSyncSection = ""; }
111+
if (manuallyReview.size > 0) { body += "<h2>Manually Review:</h2>" + Array.from(manuallyReview).join("<br />") + "<br />"; }
120112

121-
var suggestionsSection = "<h2>Auto-Applied Suggestions:</h2>" + Array.from(suggestions).join("<br />") + "<br />";
122-
if (suggestions.size === 0) { suggestionsSection = ""; }
113+
if (outOfSync.size > 0) { body += "<h2>Links With Out Of Sync Commit Hashes:</h2>" + Array.from(outOfSync).join("<br />") + "<br />"; }
123114

124-
var modifiedFilesSection = "<h2>Modified Files:</h2>" + Array.from(modifiedFiles).join("<br />") + "<br />";
125-
if (modifiedFiles.size === 0) { modifiedFilesSection = ""; }
115+
if (suggestions.size > 0) { body += "<h2>Auto-Applied Suggestions:</h2>" + Array.from(suggestions).join("<br />") + "<br />"; }
126116

127-
var body = modifiedFilesSection + manuallyReviewSection + outOfSyncSection + suggestionsSection;
128-
console.log("body=" + body);
117+
if (modifiedFiles.size > 0) { body += "<h2>Modified Files:</h2>" + Array.from(modifiedFiles).join("<br />") + "<br />"; }
129118

119+
console.log("body=" + body);
130120
core.setOutput('outputText', body);
131121
}
132122

@@ -142,11 +132,13 @@ function ValidateLinks(learningPathContents, repoURLToSearch, modifiedPRFiles, l
142132
{
143133
// Clean up the link, determine if it has a line number suffix
144134
const endOfLink = startOfLink + CheckForEndOfLink(learningPathContents, startOfLink)
135+
145136
const link = learningPathContents.substring(startOfLink, endOfLink);
146137

147138
if (excludeLinksArray.some(excludeLink => link.toLowerCase().includes(excludeLink))) { continue; }
148139

149140
const pathStartIndex = link.indexOf(sourceDirectoryName);
141+
150142
if (pathStartIndex === -1) { continue }
151143

152144
if (!link.includes(oldHash))
@@ -225,10 +217,10 @@ const main = async () => {
225217
if (changedFilePaths === null || changedFilePaths.trim() === "") { return }
226218

227219
// Scan each file in the learningPaths directory
228-
actionUtils.readdir(learningPathDirectory, (_, files) => {
220+
fs.readdir(learningPathDirectory, (_, files) => {
229221
files.forEach(learningPathFile => {
230222
try {
231-
const learningPathContents = GetContent(learningPathDirectory + "/" + learningPathFile)
223+
const learningPathContents = GetContent(path.join(learningPathDirectory, learningPathFile))
232224
if (learningPathContents)
233225
{
234226
ValidateLinks(learningPathContents, repoURLToSearch, changedFilePaths.split(' '), learningPathFile, oldHash, newHash, sourceDirectoryName, excludeLinksArray)
@@ -241,17 +233,15 @@ const main = async () => {
241233
});
242234
});
243235

244-
actionUtils.writeFileSync(learningPathHashFile, newHash);
245-
AppendModifiedFilesToCommit(learningPathHashFile, core)
236+
fs.writeFileSync(learningPathHashFile, newHash);
246237

247238
// Scan each file in the learningPaths directory
248-
actionUtils.readdir(learningPathDirectory, (_, files) => {
239+
fs.readdir(learningPathDirectory, (_, files) => {
240+
249241
files.forEach(learningPathFile => {
250242
try {
251-
const fullPath = learningPathDirectory + "/" + learningPathFile
252-
const content = actionUtils.readFileSync(fullPath)
253-
254-
var replacedContent = content
243+
const fullPath = path.join(learningPathDirectory, learningPathFile)
244+
let content = fs.readFileSync(fullPath, 'utf8')
255245

256246
let suggestionsArray = Array.from(suggestions);
257247
if (suggestionsArray && suggestionsArray.length > 0) {
@@ -261,17 +251,12 @@ const main = async () => {
261251
var newLink = suggestionArray[1]
262252
oldLink = oldLink.substring(oldLink.indexOf('(') + 1, oldLink.lastIndexOf(')'))
263253
newLink = newLink.substring(newLink.indexOf('(') + 1, newLink.lastIndexOf(')'))
264-
replacedContent = ReplaceOldWithNewText(replacedContent, oldLink, newLink)
254+
content = ReplaceOldWithNewText(content, oldLink, newLink)
265255
})
266256
}
267257

268-
replacedContent = ReplaceOldWithNewText(replacedContent, oldHash, newHash)
269-
270-
actionUtils.writeFileSync(fullPath, replacedContent);
271-
272-
if (content !== replacedContent) {
273-
AppendModifiedFilesToCommit(fullPath, core)
274-
}
258+
content = ReplaceOldWithNewText(content, oldHash, newHash)
259+
fs.writeFileSync(fullPath, content);
275260
} catch (error) {
276261
console.log("Error: " + error)
277262
console.log("Could not find learning path file: " + learningPathFile)

.github/workflows/check-learning-path-links.yml

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,15 @@ jobs:
1818
- name: Checkout head
1919
uses: actions/checkout@v4
2020
with:
21-
persist-credentials: false
22-
fetch-depth: 0 # Fetch the entire repo for the below git commit graph operations
21+
persist-credentials: true # need this for opening a PR
22+
fetch-depth: 0
2323
ref: main
2424

25-
- name: Get current SHA
26-
id: get_new_sha
27-
run: |
28-
new_sha=$(git rev-parse HEAD)
29-
echo "new_sha=$new_sha" >> $GITHUB_ENV
30-
3125
- name: Get previous update SHA
3226
id: get_sha
3327
run: |
34-
cd .github
35-
prev_sha=$(cat learning-path-sha.txt)
28+
prev_sha=$(cat .github/learning-path-sha.txt)
3629
echo "prev_sha=$prev_sha" >> $GITHUB_ENV
37-
cd ../
38-
39-
- name: Checkout head
40-
uses: actions/checkout@v4
41-
with:
42-
persist-credentials: true
43-
ref: main
4430
4531
- name: Checkout previous update
4632
uses: actions/checkout@v4
@@ -64,16 +50,16 @@ jobs:
6450
changedFilePaths: ${{ env.updated_files }}
6551
sourceDirectoryName: 'src'
6652
oldHash: ${{ env.prev_sha }}
67-
newHash: ${{ env.new_sha }}
53+
newHash: ${{ github.sha }}
6854
learningPathHashFile: '.github/learning-path-sha.txt'
6955

7056
- name: Open PR
7157
uses: ./.github/actions/open-pr
7258
with:
73-
files_to_commit: ${{ steps.check-links.outputs.modifiedFilesToCommit }}
59+
files_to_commit: --all -- :!prev
7460
title: "[REQUIRES MANUAL REVIEW] Update Learning Paths"
7561
commit_message: Update Learning Paths
7662
body: This PR was auto generated and will not be automatically merged in - adjustments should be made manually as-needed.<br />${{ steps.check-links.outputs.outputText }}
77-
branch_name: learningPathUpdates/${{ env.new_sha }}
63+
branch_name: learningPathUpdates/${{ github.sha }}
7864
fail_if_files_unchanged: true
7965
auth_token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)