chore: checkout the base branch instead of release in cyclic deps check (#39057)
## Description
The CI workflow for cyclic dependency checks has been modified to
reference the base branch instead of the release branch.
Fixes #`Issue Number`
_or_
Fixes `Issue URL`
> [!WARNING]
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._
## Automation
/ok-to-test tags="@tag.Sanity"
### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!WARNING]
> Tests have not run on the HEAD
b77d4bd8b0971cb36cd3c391ac40fa911f75950d yet
> <hr>Thu, 06 Feb 2025 07:18:10 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Chores**
- Enhanced the automated cyclic dependency check to now use the pull
request’s target branch for comparisons.
- Updated naming and output labels in the workflow to provide clearer,
more accurate results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
parent
341d734c3e
commit
3cdb4a335c
|
|
@ -40,12 +40,12 @@ jobs:
|
|||
with:
|
||||
node-version-file: app/client/package.json
|
||||
|
||||
# Globally install the npm package
|
||||
# Globally install the npm package
|
||||
- name: Install dpdm globally
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: npm install -g dpdm@3.14
|
||||
|
||||
# Install all the dependencies
|
||||
# Install all the dependencies
|
||||
- name: Install dependencies
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
|
|
@ -55,51 +55,80 @@ jobs:
|
|||
id: count-cyclic-deps-in-pr
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false > pr_circular_deps.txt
|
||||
dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false | sed '1d; s/^[[:space:]]*[0-9]\{4\})[[:space:]]*/• /; /^[[:space:]]*$/d' \
|
||||
| sort | sed '/^[[:space:]]*$/d' > pr_circular_deps.txt
|
||||
# awk 'NF' pr_circular_deps.txt: Filter out empty lines from the file
|
||||
# wc -l: Count the number of lines in the file
|
||||
# awk '{print $1 - 1}': Subtract 1 from the count because the first line is the header 'Circular Dependencies'
|
||||
pr_count="$(awk 'NF' pr_circular_deps.txt | wc -l | awk '{print $1 - 1}')"
|
||||
pr_count="$(awk 'NF' pr_circular_deps.txt | wc -l)"
|
||||
echo "pr_count=$pr_count" >> $GITHUB_OUTPUT
|
||||
cat pr_circular_deps.txt
|
||||
|
||||
- name: Checkout release branch
|
||||
- name: Checkout base branch
|
||||
uses: actions/checkout@v4
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
with:
|
||||
ref: release
|
||||
ref: ${{ github.event.pull_request.base.ref }}
|
||||
clean: false
|
||||
|
||||
# Install all the dependencies
|
||||
- name: Install dependencies
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
yarn install --immutable
|
||||
|
||||
- name: Count circular dependencies on release branch
|
||||
id: count-cyclic-deps-in-release
|
||||
- name: Count circular dependencies on base branch
|
||||
id: count-cyclic-deps-in-base
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false > release_circular_deps.txt
|
||||
# awk 'NF' release_circular_deps.txt: Filter out empty lines from the file
|
||||
dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false | sed '1d; s/^[[:space:]]*[0-9]\{4\})[[:space:]]*/• /; /^[[:space:]]*$/d' \
|
||||
| sort | sed '/^[[:space:]]*$/d' > base_branch_circular_deps.txt
|
||||
# awk 'NF' base_branch_circular_deps.txt: Filter out empty lines from the file
|
||||
# wc -l: Count the number of lines in the file
|
||||
# awk '{print $1 - 1}': Subtract 1 from the count because the first line is the header 'Circular Dependencies'
|
||||
release_count="$(awk 'NF' release_circular_deps.txt | wc -l | awk '{print $1 - 1}')"
|
||||
echo "release_count=$release_count" >> $GITHUB_OUTPUT
|
||||
cat release_circular_deps.txt
|
||||
base_branch_count="$(awk 'NF' base_branch_circular_deps.txt | wc -l)"
|
||||
echo "base_branch_count=$base_branch_count" >> $GITHUB_OUTPUT
|
||||
cat base_branch_circular_deps.txt
|
||||
|
||||
- name: Compare circular dependencies
|
||||
id: compare-deps
|
||||
if: steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
release_count="${{ steps.count-cyclic-deps-in-release.outputs.release_count }}"
|
||||
base_branch_count="${{ steps.count-cyclic-deps-in-base.outputs.base_branch_count }}"
|
||||
pr_count="${{ steps.count-cyclic-deps-in-pr.outputs.pr_count }}"
|
||||
diff="$((pr_count - release_count))"
|
||||
diff="$((pr_count - base_branch_count))"
|
||||
|
||||
if [ "$diff" -gt 0 ]; then
|
||||
echo "has_more_cyclic_deps=true" >> "$GITHUB_OUTPUT"
|
||||
echo "diff=$diff" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
- name: Save diff
|
||||
if: steps.compare-deps.outputs.has_more_cyclic_deps == 'true' && steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
{ diff -u base_branch_circular_deps.txt pr_circular_deps.txt || true; } > diff_output.txt
|
||||
|
||||
- name: Log diff in circular dependencies between PR and base branch
|
||||
id: log-compare-circular-deps
|
||||
if: steps.compare-deps.outputs.has_more_cyclic_deps == 'true' && steps.changed-files.outputs.any_changed == 'true'
|
||||
run: |
|
||||
# Capture added dependencies (lines starting with '+' but not the diff header lines)
|
||||
added=$(grep -E '^\+[^+]' diff_output.txt | sed 's/^\+//') || true
|
||||
|
||||
# Only output the "Dependencies added:" header if there are any added dependencies.
|
||||
if [[ -n "$added" ]]; then
|
||||
echo "Dependencies added:" >> diff.txt
|
||||
echo "$added" >> diff.txt
|
||||
echo "" >> diff.txt
|
||||
fi
|
||||
|
||||
# Capture removed dependencies (lines starting with '-' but not the diff header lines)
|
||||
removed=$(grep -E '^-[^-]' diff_output.txt | sed 's/^-//') || true
|
||||
|
||||
# Only output the "Dependencies removed:" header if there are any removed dependencies.
|
||||
if [[ -n "$removed" ]]; then
|
||||
echo "Dependencies removed:" >> diff.txt
|
||||
echo "$removed" >> diff.txt
|
||||
fi
|
||||
|
||||
cat diff.txt
|
||||
# Comment on the PR if cyclic dependencies are found
|
||||
- name: Comment the result on PR
|
||||
if: steps.compare-deps.outputs.has_more_cyclic_deps == 'true' && steps.changed-files.outputs.any_changed == 'true'
|
||||
|
|
@ -107,8 +136,9 @@ jobs:
|
|||
with:
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
script: |
|
||||
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
|
||||
const prNumber = context.payload.pull_request.number;
|
||||
const message = `🔴🔴🔴 Cyclic Dependency Check:\n\nThis PR has increased the number of cyclic dependencies by ${{steps.compare-deps.outputs.diff}}, when compared with the release branch.\n\nRefer [this document](https://appsmith.notion.site/How-to-check-cyclic-dependencies-c47b08fe5f2f4261a3a234b19e13f2db) to identify the cyclic dependencies introduced by this PR.`;
|
||||
const message = `🔴🔴🔴 Cyclic Dependency Check:\n\nThis PR has increased the number of cyclic dependencies by ${{steps.compare-deps.outputs.diff}}, when compared with the ${{github.event.pull_request.base.ref}} branch.\n\nRefer [this document](https://appsmith.notion.site/How-to-check-cyclic-dependencies-c47b08fe5f2f4261a3a234b19e13f2db) to identify the cyclic dependencies introduced by this PR.\n\nYou can view the dependency diff in the [run log](${runUrl}). Look for the **check-cyclic-dependencies** job in the run.`;
|
||||
github.issues.createComment({
|
||||
...context.repo,
|
||||
issue_number: prNumber,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user