Skip to content

Commit

Permalink
Flowing bits (#376)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kkeirstead authored Feb 2, 2024
1 parent 10f3c72 commit 6cb380a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 66 deletions.
4 changes: 0 additions & 4 deletions .github/actions/action-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,3 @@ module.exports.friendlyDateFromISODate = function(isoDate) {

module.exports.splitVersionTag = splitVersionTag;
module.exports.readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8');
module.exports.readFileSync = (fileName) => fs.readFileSync(fileName, 'utf8');
module.exports.writeFile = (fileName, contents) => util.promisify(fs.writeFile)(fileName, contents);
module.exports.writeFileSync = (fileName, contents) => fs.writeFileSync(fileName, contents);
module.exports.readdir = (dirName, callback) => util.promisify(fs.readdir)(dirName, callback);
69 changes: 27 additions & 42 deletions .github/actions/learning-path-staleness-check/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const actionUtils = require('../action-utils.js');
const fs = require('fs');
const path = require('path');
const prevPathPrefix = "prev/";
const linePrefix = "#L";
const separator = " | ";

modifiedFilesDict = {};
modifiedFilesPathToLearningPathFile = {};
modifiedFilesUrlToFileName = {};

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

const oldNewLinkSeparator = ' -> ';

let modifiedFilesToCommit = [];

function AppendModifiedFilesToCommit(path, core)
{
modifiedFilesToCommit.push(path)
core.setOutput('modifiedFilesToCommit', modifiedFilesToCommit.join(' '))
}

function ReplaceOldWithNewText(content, oldText, newText)
{
return content.replaceAll(oldText, newText);
Expand All @@ -30,14 +24,14 @@ function UpdateModifiedFiles(fileName, path, learningPathFile)
{
modifiedFilesUrlToFileName[path] = fileName;

modifiedFilesDict[path] = modifiedFilesDict[path] ? modifiedFilesDict[path] : new Set();;
modifiedFilesDict[path].add(learningPathFile);
modifiedFilesPathToLearningPathFile[path] = modifiedFilesPathToLearningPathFile[path] ? modifiedFilesPathToLearningPathFile[path] : new Set();;
modifiedFilesPathToLearningPathFile[path].add(learningPathFile);

modifiedFiles = new Set();
for (currPath in modifiedFilesDict)
for (currPath in modifiedFilesPathToLearningPathFile)
{
const fileName = modifiedFilesUrlToFileName[currPath];
modifiedFiles.add(AssembleModifiedFilesOutput(fileName, currPath, Array.from(modifiedFilesDict[currPath])));
modifiedFiles.add(AssembleModifiedFilesOutput(fileName, currPath, Array.from(modifiedFilesPathToLearningPathFile[currPath])));
}
}

Expand Down Expand Up @@ -92,7 +86,7 @@ function AppendLineNumber(text, lineNumber)

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

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

function GetContent(path) {
try {
return actionUtils.readFileSync(path)
return fs.readFileSync(path, 'utf8');
}
catch (error) {}

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

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

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

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

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

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

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

Expand All @@ -142,11 +132,13 @@ function ValidateLinks(learningPathContents, repoURLToSearch, modifiedPRFiles, l
{
// 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))
Expand Down Expand Up @@ -225,10 +217,10 @@ const main = async () => {
if (changedFilePaths === null || changedFilePaths.trim() === "") { return }

// Scan each file in the learningPaths directory
actionUtils.readdir(learningPathDirectory, (_, files) => {
fs.readdir(learningPathDirectory, (_, files) => {
files.forEach(learningPathFile => {
try {
const learningPathContents = GetContent(learningPathDirectory + "/" + learningPathFile)
const learningPathContents = GetContent(path.join(learningPathDirectory, learningPathFile))
if (learningPathContents)
{
ValidateLinks(learningPathContents, repoURLToSearch, changedFilePaths.split(' '), learningPathFile, oldHash, newHash, sourceDirectoryName, excludeLinksArray)
Expand All @@ -241,17 +233,15 @@ const main = async () => {
});
});

actionUtils.writeFileSync(learningPathHashFile, newHash);
AppendModifiedFilesToCommit(learningPathHashFile, core)
fs.writeFileSync(learningPathHashFile, newHash);

// Scan each file in the learningPaths directory
actionUtils.readdir(learningPathDirectory, (_, files) => {
fs.readdir(learningPathDirectory, (_, files) => {

files.forEach(learningPathFile => {
try {
const fullPath = learningPathDirectory + "/" + learningPathFile
const content = actionUtils.readFileSync(fullPath)

var replacedContent = content
const fullPath = path.join(learningPathDirectory, learningPathFile)
let content = fs.readFileSync(fullPath, 'utf8')

let suggestionsArray = Array.from(suggestions);
if (suggestionsArray && suggestionsArray.length > 0) {
Expand All @@ -261,17 +251,12 @@ const main = async () => {
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)
content = ReplaceOldWithNewText(content, oldLink, newLink)
})
}

replacedContent = ReplaceOldWithNewText(replacedContent, oldHash, newHash)

actionUtils.writeFileSync(fullPath, replacedContent);

if (content !== replacedContent) {
AppendModifiedFilesToCommit(fullPath, core)
}
content = ReplaceOldWithNewText(content, oldHash, newHash)
fs.writeFileSync(fullPath, content);
} catch (error) {
console.log("Error: " + error)
console.log("Could not find learning path file: " + learningPathFile)
Expand Down
26 changes: 6 additions & 20 deletions .github/workflows/check-learning-path-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,15 @@ jobs:
- name: Checkout head
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0 # Fetch the entire repo for the below git commit graph operations
persist-credentials: true # need this for opening a PR
fetch-depth: 0
ref: main

- name: Get current SHA
id: get_new_sha
run: |
new_sha=$(git rev-parse HEAD)
echo "new_sha=$new_sha" >> $GITHUB_ENV
- name: Get previous update SHA
id: get_sha
run: |
cd .github
prev_sha=$(cat learning-path-sha.txt)
prev_sha=$(cat .github/learning-path-sha.txt)
echo "prev_sha=$prev_sha" >> $GITHUB_ENV
cd ../
- name: Checkout head
uses: actions/checkout@v4
with:
persist-credentials: true
ref: main
- name: Checkout previous update
uses: actions/checkout@v4
Expand All @@ -64,16 +50,16 @@ jobs:
changedFilePaths: ${{ env.updated_files }}
sourceDirectoryName: 'src'
oldHash: ${{ env.prev_sha }}
newHash: ${{ env.new_sha }}
newHash: ${{ github.sha }}
learningPathHashFile: '.github/learning-path-sha.txt'

- name: Open PR
uses: ./.github/actions/open-pr
with:
files_to_commit: ${{ steps.check-links.outputs.modifiedFilesToCommit }}
files_to_commit: --all -- :!prev
title: "[REQUIRES MANUAL REVIEW] Update Learning Paths"
commit_message: Update Learning Paths
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 }}
branch_name: learningPathUpdates/${{ env.new_sha }}
branch_name: learningPathUpdates/${{ github.sha }}
fail_if_files_unchanged: true
auth_token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 6cb380a

Please sign in to comment.