Skip to content
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

Learning Paths Automation #5904

Closed
wants to merge 227 commits into from
Closed

Learning Paths Automation #5904

wants to merge 227 commits into from

Conversation

kkeirstead
Copy link
Member

Summary

This PR adds new workflows to aid in keeping learning paths up-to-date. This is a simplified version of what I previously demoed (I removed the Issue step in the middle now that we're auto-applying the suggestions), with the following flow:

  • Once a week (or on a different interval), "Check Learning Path Links" kicks off. This workflow compares the current state of the codebase with the previous one, as determined by a placeholder file "learning-path-sha.txt".
  • Upon completion, "Submit Learning Path PR" kicks off. This creates a PR that includes details about modified files, things to manually review, automatic suggestions, and files that are 'out-of-sync' (i.e. not tied to the correct SHA). The commit hashes within the learning path files are automatically updated, and the suggestions are automatically applied (via line-number changes to links).
  • This PR needs to be manually reviewed by whoever is handling the release and dependabot updates - outside of large refactors, this should be as simple as clicking on the PR's hyperlinks to ensure everything looks correct (and manually changing any of the links that need manual review due to more drastic changes).

There are a number of ways this could be improved (such as stable tags instead of commit hashes or increasing what this can handle automatically), but I'm trying not to over-engineer V1 of this so we can start using it here and in other repos. If we notice pain points, updates can be made to address them, but hopefully this should reduce the burden of keeping the learning paths up to date. By not running on every PR, this should hopefully alleviate some of the concerns from the first prototype about this getting in the way for every commit.

This is an example run on my fork - this simulates miscellaneous changes being made over the course of a week, and what PR would be auto-generated. The auto-applied suggestions handle in-file adjustments, and files that have ambiguous links or were renamed/deleted are listed under manually review. The "Out Of Sync" section shows that configuration.md has a link referencing main instead of the correct hash.

Release Notes Entry

* Create check-learning-path-links.yml

* 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 ActivityExtensions.cs

* 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 check-learning-path-links.yml

* 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 check-learning-path-links.yml

* Update check-learning-path-links.yml

* Update check-learning-path-links.yml

* Update check-learning-path-links.yml

* Update submit-linter-suggestions.yml

* Update submit-linter-suggestions.yml

* Create submit-learning-paths-staleness-check.yml

* Update check-learning-path-links.yml

* Update check-learning-path-links.yml

* Update check-learning-path-links.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update check-learning-path-links.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update check-learning-path-links.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update check-learning-path-links.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update submit-learning-paths-staleness-check.yml

* Update TestAssemblies.cs

* Update CollectionRulePipeline.cs

* Update submit-learning-paths-staleness-check.yml

* Update CollectionRulePipeline.cs

* Update CollectionRulePipeline.cs

* Update submit-learning-paths-staleness-check.yml

* Update ActivityExtensions.cs

* Update CollectionRulePipeline.cs

* Update TestAssemblies.cs
@kkeirstead kkeirstead requested a review from a team as a code owner January 29, 2024 18:20

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

working-directory: ./head
run: |
mkdir -p ./learning-path-review
echo -n "${{ steps.check-links.outputs.modifiedFiles }}" > ./learning-path-review/modifiedFiles
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.

Using substitution expressions here is a script injection risk. All of these should be passed in via an env block instead to avoid the risk.

Example:

if [ "$release_type" == "rtm" ]; then
sed -i "/<PreReleaseVersionLabel>.*/a\ \ \ \ <DotnetFinalVersionKind>release<\/DotnetFinalVersionKind>" $versionFile
fi
echo "release_version_file=$versionFile" >> $GITHUB_ENV
env:
release_type: ${{ inputs.release_type }}
release_version: ${{ inputs.release_version }}

name: 'Check Learning Path Links'
on:
schedule: # Run once a week
- cron: '0 0 * * 1'
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.

I'd be in favor of this running every other week or once a month. As it stands every week is a bit of noise for a manual review PR since there will always be changes everytime the HEAD commit is updated.

- name: Checkout head
uses: actions/checkout@v4
with:
persist-credentials: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for persisted credentials? This is a security risk, especially since the token has elevated permissions and this step is ran first. Depending on the reason we can refactor this a couple different ways to minimize the risk.

manuallyReview=${manuallyReview//,/<br />}
manuallyReviewSection="<h2>Manually Review:</h2>${manuallyReview}<br />"
if test -z "$manuallyReview"; then
manuallyReviewSection=""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: formatting, let's fix the indentation on the conditionals to make it easier to read.

manuallyReview=$(cat ./learning-path-review/manuallyReview)
manuallyReview=${manuallyReview//,/<br />}
manuallyReviewSection="<h2>Manually Review:</h2>${manuallyReview}<br />"
if test -z "$manuallyReview"; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's switch all of these if statements to use the bracket commands instead of explicit test as that's more conventional in bash scripts.

e.g. if [ -z "$manuallyReview" ]

Copy link
Member

@schmittjoseph schmittjoseph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking on security related comments

@@ -0,0 +1,117 @@
name: 'Submit Learning Path PR'
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.

I'm not sure I see the value of having split workflows here. It's adding a lot of complexity (and potential security risks) without adding value now that the proposed issue step has been removed.

Let's consolidate the split workflows and actions into a single one instead. If we consolidate them, then the action can simply generate a report (pr body) instead of outputting several variables and having a bash script do it which is more prone to script injections.

@kkeirstead
Copy link
Member Author

Closing this to prevent churn while testing/debugging new changes...I made the mistake of merging directly from my fork's main branch where I had been running the workflow. Will make sure comments are not lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants