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

check dirty git tree after running CI jobs #9804

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

rabi-siddique
Copy link
Contributor

@rabi-siddique rabi-siddique commented Jul 30, 2024

refs: #5140

Copy link

cloudflare-workers-and-pages bot commented Jul 30, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6c0f6cf
Status: ✅  Deploy successful!
Preview URL: https://1dc1fdb1.agoric-sdk.pages.dev
Branch Preview URL: https://rs-check-dirty-tree-post-ci.agoric-sdk.pages.dev

View logs

@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch from ef0027c to c58c5dc Compare July 30, 2024 10:46
@rabi-siddique rabi-siddique added the force:integration Force integration tests to run on PR label Jul 30, 2024
@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch 10 times, most recently from f51b4a8 to 3411ddc Compare July 30, 2024 13:27
@rabi-siddique rabi-siddique changed the title ci: check dirty tree in a post run step check dirty git tree after running CI jobs Jul 30, 2024
@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch 6 times, most recently from f390344 to 1d7851e Compare July 31, 2024 04:00
@rabi-siddique rabi-siddique marked this pull request as ready for review July 31, 2024 05:05
@rabi-siddique rabi-siddique requested a review from mhofman July 31, 2024 05:06
@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch from 1d7851e to 712e7d7 Compare July 31, 2024 05:16
Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

Is there any way we can have some manual tests of this change, maybe as a PR stacked on top of this that creates a dirty file on purpose?

Comment on lines -189 to -193
# Fail if `git status` reports anything other than the following:
# * an untracked endo-sha.txt from above
# * work tree files that have been staged without further changes
# (e.g., package.json or yarn.lock) as indicated by the Y position
# in "XY PATH" being a space
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 make sure we keep this explanation (with an update) around

fi
# Refs: https://github.com/orgs/community/discussions/45342
- name: Validate Git Tree in Root Directory
if: inputs.path == '.'
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused, why do we need to condition on inputs.path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The file path can be either . or ./agoric-sdk, which makes it difficult to determine which composite action is being used. Previously, we could specify the path using the working-directory parameter, but this no longer works properly because we now call a separate composite action.

Another option was to concatenate the path value with .github/actions/with-post-step, but it does not work with the uses keyword.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I totally missed the different uses path. I think it's another reason to use an off-the-shelf action for this, no relative path to deal with.

@@ -0,0 +1,22 @@
// Ref: https://github.com/pyTooling/Actions/blob/main/with-post-step/main.js
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to use an off the shelf action instead of vendoring something in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure about which actions to use. After your suggestion, I checked out run-and-post-run-action, action-post-run, and pytooling actions. I ended up choosing pytooling. Thanks for the help :)

if: inputs.path == '.'
uses: ./.github/actions/with-post-step
with:
main: echo "Checking Git tree for changes in the root directory..."
Copy link
Member

Choose a reason for hiding this comment

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

We want to maintain a check after build and before the test runs too. No need to run the test if the tree is dirty to start with.

@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch 6 times, most recently from 83f94c5 to 3dacff0 Compare August 1, 2024 11:59
@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch 6 times, most recently from d250b2f to 24c19b4 Compare August 1, 2024 13:28
# - Files ending with 'junit.xml'
# - The untracked file 'endo-sha.txt'
# This setup ensures the Git status only flags unexpected modifications or untracked files outside these specified exceptions.
changes=$(git status --porcelain | grep -vE 'junit.xml$' | grep -vE '^\?\? endo-sha.txt$')
Copy link
Member

Choose a reason for hiding this comment

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

This should be maximally strict, and if it is using separate grep invocations, it might as well improve readability by avoiding regular expressions where possible:

Suggested change
changes=$(git status --porcelain | grep -vE 'junit.xml$' | grep -vE '^\?\? endo-sha.txt$')
changes=$(git status --porcelain | grep -vE '/junit\.xml$' | grep -vFx '?? endo-sha.txt')

Comment on lines 2 to 3
# Navigate to the specified directory
cd $1
# Set verbose execution
set -x
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 ensure directory visibility as well.

Suggested change
# Navigate to the specified directory
cd $1
# Set verbose execution
set -x
# Set verbose execution
set -x
# Navigate to the specified directory
cd $1

Comment on lines 7 to 9
# Fail if git status detects changes, ignoring:
# - Files ending with 'junit.xml'
# - The untracked file 'endo-sha.txt'
Copy link
Member

Choose a reason for hiding this comment

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

These exceptions should be explained.

Suggested change
# Fail if git status detects changes, ignoring:
# - Files ending with 'junit.xml'
# - The untracked file 'endo-sha.txt'
# Fail if git status detects changes, ignoring:
# - Files ending with 'junit.xml' (cf. scripts/ci-collect-testruns.sh, invoked by ../post-test/action.yml)
# - The untracked file 'endo-sha.txt' (cf. ./action.yml)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gibson042 Thanks a lot for these handy suggestions. I've made the changes. :)

@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch from 24c19b4 to e924275 Compare August 1, 2024 15:41
@rabi-siddique
Copy link
Contributor Author

@rabi-siddique rabi-siddique requested a review from mhofman August 2, 2024 14:29
@mhofman
Copy link
Member

mhofman commented Aug 2, 2024

@mhofman, we have some failing jobs:
Should we ignore these files by adding a regex for them?

I think it means you've uncovered some case where we have some missing entries in .gitignore ?

Copy link
Member

@mhofman mhofman left a comment

Choose a reason for hiding this comment

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

The failing tests likely indicate we're missing some git ignore entries, and I think it should be the likely fix.

I think junit.xml should also be ignore instead of excluded from the check. I think we made an exception for endo-sha.txt, but I don't remember the exact reason. Possibly because it is staged for some of the flows, but I don't know why we couldn't have forced git add in that case. Maybe @michaelfig can shed some lights.

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

Please use secure bash escaping, and verify that CI passes.

Comment on lines 186 to 190
with:
main: |
bash ${{ inputs.path }}/.github/actions/restore-node/check-git-status.sh ${{ inputs.path }}
post: |
bash ${{ inputs.path }}/.github/actions/restore-node/check-git-status.sh ${{ inputs.path }}
Copy link
Member

Choose a reason for hiding this comment

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

Please use defensive shell escaping in case somebody else copies and pastes this code.

Suggested change
with:
main: |
bash ${{ inputs.path }}/.github/actions/restore-node/check-git-status.sh ${{ inputs.path }}
post: |
bash ${{ inputs.path }}/.github/actions/restore-node/check-git-status.sh ${{ inputs.path }}
with:
main: |
bash "$SRC/.github/actions/restore-node/check-git-status.sh" "$SRC"
post: |
bash "$SRC/.github/actions/restore-node/check-git-status.sh" "$SRC"
env:
SRC: ${{ inputs.path }}

# Set verbose execution
set -x
# Navigate to the specified directory
cd $1
Copy link
Member

Choose a reason for hiding this comment

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

Here, too.

Suggested change
cd $1
cd "$1" || exit $?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestions!

@michaelfig
Copy link
Member

we made an exception for endo-sha.txt, but I don't remember the exact reason.

I know you suggested using git add endo-sha.txt and just ignoring all the indexed files in the restore-node dirty check. I don't remember why that didn't work out.

@mhofman
Copy link
Member

mhofman commented Aug 2, 2024

I know you suggested using git add endo-sha.txt and just ignoring all the indexed files in the restore-node dirty check. I don't remember why that didn't work out.

I'm wondering if we tried simply adding endo-sha.txt to .gitignore?

I know we git stash in some workflows, but I don't think any that relies on endo-sha.txt ?

Even if we needed to support stash, we could do git add -f endo-sha.txt (and any other files needed), followed by git stash --staged

@michaelfig
Copy link
Member

I'm wondering if we tried simply adding endo-sha.txt to .gitignore?

I'm pretty sure we didn't do that.

I know we git stash in some workflows, but I don't think any that relies on endo-sha.txt ?

I only see it in our after-merge.yml around lerna publish. lerna updates the package.jsons, but I don't see how a git stash would make a difference there. I believe that just adding endo-sha.txt to .gitignore instead would obviate the need to do the stash.

@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch 3 times, most recently from b46c189 to 019fb85 Compare August 5, 2024 04:41
Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -15,6 +15,7 @@ upgrade-test-scripts
# same for each proposal, an independent project
proposals/*/.pnp.*
proposals/*/.yarn/*
proposals/a:upgrade-next/*
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about this one, but if you are, I'm still willing to approve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still in the process of understanding this, as it appears to be intermittent. Sometimes artifacts are generated when the associated workflow runs, and other times they are not.

@rabi-siddique rabi-siddique added the automerge:rebase Automatically rebase updates, then merge label Aug 6, 2024
@rabi-siddique rabi-siddique force-pushed the rs-check-dirty-tree-post-ci-job branch from 019fb85 to 6c0f6cf Compare August 6, 2024 04:35
@mergify mergify bot merged commit af5e7ab into master Aug 6, 2024
79 checks passed
@mergify mergify bot deleted the rs-check-dirty-tree-post-ci-job branch August 6, 2024 05:31
@@ -15,6 +15,7 @@ upgrade-test-scripts
# same for each proposal, an independent project
proposals/*/.pnp.*
proposals/*/.yarn/*
proposals/a:upgrade-next/*
Copy link
Member

@mhofman mhofman Aug 6, 2024

Choose a reason for hiding this comment

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

That's definitely too broad. Please revert and use a targeted ignore file inside the proposals/a:upgrade-next folder

You should only have to ignore the generated files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge force:integration Force integration tests to run on PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants