Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
21 stars 12 forks source link

fix(sage-monorepo): enable `nx affected` to compare HEAD to the official main branch #2538

Closed tschaffter closed 4 months ago

tschaffter commented 4 months ago

Close #2537

Changelog

Preview

In the context of a pull request created from a fork, the CI workflow was checking out the source repository (fork) and branch that triggered the PR with the action actions/checkout@v4 (now updated to v4). Instead, we should rely on the default behavior of this action to checkout a merge commit created from 1) the last commit pushed to the base branch (the official, upstream main branch) and 2) the last commit pushed to the source branch used to create this PR.

Example: This workflow run reports the SHA of the merged commit, f9bc2a178306146a2278c4a171e5361b10a802f5:

Disabling automatic garbage collection
Setting up auth
Fetching the repository
  /usr/bin/git -c protocol.version=2 fetch --prune --no-recurse-submodules origin +refs/heads/*:refs/remotes/origin/* +refs/tags/*:refs/tags/* +f9bc2a178306146a2278c4a171e5361b10a802f5:refs/remotes/pull/2538/merge
  From https://github.com/Sage-Bionetworks/sage-monorepo
   * [new branch]        gh-pages   -> origin/gh-pages
   * [new branch]        main       -> origin/main
   * [new ref]           f9bc2a178306146a2278c4a171e5361b10a802f5 -> pull/2538/merge
Determining the checkout info
Checking out the ref
/usr/bin/git log -1 --format='%H'
'f9bc2a178306146a2278c4a171e5361b10a802f5'

We can then head to https://github.com/Sage-Bionetworks/sage-monorepo/commit/f9bc2a178306146a2278c4a171e5361b10a802f5 to see the two parent commits that were used to create this merge commit.

image

where:

The action nrwl/nx-set-shas@v4 now properly derives the Base and Head SHA. Note that this action does not necessarily set the Base SHA to point to the last commit of the base branch. Instead, the Base SHA should by default point to the last "successful" commit pushed. This behavior can be customized using the inputs of the the action nrwl/nx-set-shas@v4.