From 18af2cf98d2001c24267003780a44328df11bb3d Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 28 May 2025 14:03:42 -0400 Subject: [PATCH 01/32] intentionally create a useOnyx canBeMissing error For testing purposes this commit introduces a useOnyx lint error by removing a canBeMissing error. --- src/pages/TransactionReceiptPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/TransactionReceiptPage.tsx b/src/pages/TransactionReceiptPage.tsx index faf4fd42f8d3..8350f1eaacdb 100644 --- a/src/pages/TransactionReceiptPage.tsx +++ b/src/pages/TransactionReceiptPage.tsx @@ -22,7 +22,7 @@ function TransactionReceipt({route}: TransactionReceiptProps) { const reportID = route.params.reportID; const transactionID = route.params.transactionID; const action = route.params.action; - const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); const [transactionMain] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {canBeMissing: true}); const [transactionDraft] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {canBeMissing: true}); const [reportMetadata = {isLoadingInitialReportActions: true}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {canBeMissing: true}); From 0d5685c6cae83a6fb3452855976f8a8c043b7fca Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 28 May 2025 15:45:47 -0400 Subject: [PATCH 02/32] scripts: add lintChanged.sh Add a script for error handling of git merge-base and git diff for checking for changes between the common ancestor of origin/main and the current branch HEAD. Updates npm run to use this script. --- package.json | 2 +- scripts/lintChanged.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100755 scripts/lintChanged.sh diff --git a/package.json b/package.json index cc0b8cc38294..bfada48d9ae9 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=0 --cache --cache-location=node_modules/.cache/eslint", - "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 eslint --max-warnings=0 --config ./.eslintrc.changed.js $(git diff --diff-filter=AMR --name-only origin/main HEAD -- \"*.ts\" \"*.tsx\")", + "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh", "lint-watch": "npx eslint-watch --watch --changed", "shellcheck": "./scripts/shellCheck.sh", "prettier": "prettier --write .", diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh new file mode 100755 index 000000000000..25641ba3e2ad --- /dev/null +++ b/scripts/lintChanged.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Checks for changes between the common ancestor of origin/main and the +# current HEAD. + +source scripts/shellUtils.sh + +MERGE_BASE_SHA_HASH=$(git merge-base origin/main HEAD) +# Check if output is empty. +if [ -z "${MERGE_BASE_SHA_HASH}" ]; then + error "git merge-base did not return any output" + exit 1 +fi + +# Check if the output of merge-base is a single SHA-1 commit hash. +if ! [[ "${MERGE_BASE_SHA_HASH}" =~ ^[a-fA-F0-9]{40}$ ]]; then + error "git merge-base returned unexpected output" + exit 1 +fi + +DIFF_OUTPUT=$(git --no-pager diff --diff-filter=AMR --name-only "${MERGE_BASE_SHA_HASH}" HEAD -- '*.ts' '*.tsx') + +# Check if there were any changes. +if [ -z "${MERGE_BASE_SHA_HASH}" ]; then + error "git diff returned no changed files" + exit 1 +fi + +# Ensure this script is running inside an npm run context +if [[ -n "$npm_lifecycle_event" ]]; then + eslint --max-warnings=0 --config ./.eslintrc.changed.js "${DIFF_OUTPUT}" +else + error "This script is meant to run by using npm run lint-changed" +fi From eefdc1e0ddf230139b51e40dc72b224da47439a9 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 28 May 2025 15:53:02 -0400 Subject: [PATCH 03/32] github-actions: lint-changed change depth to 30000 Change the depth of the fetch so that we pull enough commits to run git merge-base and see the common ancestor. --- .github/workflows/lint-changed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 6c7a638b55a9..35d9e2337b34 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -29,7 +29,7 @@ jobs: - name: Run ESLint to check for deprecation warnings run: | # This will just fetch the latest commit from main - git fetch origin main --no-tags --depth=1 + git fetch origin main --no-tags --depth=30000 # shellcheck disable=SC2046 npm run lint-changed From 248e644d38b18b68aa192b3049facaad6679e0fb Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 28 May 2025 16:38:53 -0400 Subject: [PATCH 04/32] fix: change the checkout action to fetch further Remove the fetch origin main from the ESLint deprecation warning. Add the fetch-depth param to checkout. --- .github/workflows/lint-changed.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 35d9e2337b34..d87e90723ebf 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,6 +20,8 @@ jobs: - name: Checkout # v4 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 + with: + fetch-depth: 30000 - name: Setup Node uses: ./.github/actions/composite/setupNode @@ -28,8 +30,5 @@ jobs: - name: Run ESLint to check for deprecation warnings run: | - # This will just fetch the latest commit from main - git fetch origin main --no-tags --depth=30000 - # shellcheck disable=SC2046 npm run lint-changed From 05e29327d30378572dbf4041f9a23a7763374e3b Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 28 May 2025 16:45:32 -0400 Subject: [PATCH 05/32] fix-wip: add fetch back --- .github/workflows/lint-changed.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index d87e90723ebf..56e825d73088 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -30,5 +30,8 @@ jobs: - name: Run ESLint to check for deprecation warnings run: | + # This will just fetch the latest commit from main + git fetch origin main --no-tags --depth=30000 + # shellcheck disable=SC2046 npm run lint-changed From bdc335cc27cb95c3d0dd84955f97e8644d140d66 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 10:53:13 -0400 Subject: [PATCH 06/32] scripts: lintChanged.sh fix style and clean logic Fix style and add additional bash safety to variable assignments. Add new rerun in NPM context checks. Combine error cases for merge-base. --- scripts/lintChanged.sh | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index 25641ba3e2ad..b6ff708d0c99 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -1,34 +1,32 @@ #!/bin/bash -# Checks for changes between the common ancestor of origin/main and the -# current HEAD. +# Lints .ts and .tsx files that have changed in this branch -source scripts/shellUtils.sh +set -eu -MERGE_BASE_SHA_HASH=$(git merge-base origin/main HEAD) -# Check if output is empty. -if [ -z "${MERGE_BASE_SHA_HASH}" ]; then - error "git merge-base did not return any output" - exit 1 -fi +TOP="$(realpath "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)/..")" +readonly TOP +source "${TOP}/scripts/shellUtils.sh" -# Check if the output of merge-base is a single SHA-1 commit hash. -if ! [[ "${MERGE_BASE_SHA_HASH}" =~ ^[a-fA-F0-9]{40}$ ]]; then +MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" +# Check if output is empty or malformed +if [[ -z "${MERGE_BASE_SHA_HASH}" ]] || ! [[ "${MERGE_BASE_SHA_HASH}" =~ ^[a-fA-F0-9]{40}$ ]]; then error "git merge-base returned unexpected output" exit 1 fi -DIFF_OUTPUT=$(git --no-pager diff --diff-filter=AMR --name-only "${MERGE_BASE_SHA_HASH}" HEAD -- '*.ts' '*.tsx') - +DIFF_OUTPUT="$(git --no-pager diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" # Check if there were any changes. -if [ -z "${MERGE_BASE_SHA_HASH}" ]; then - error "git diff returned no changed files" +# shellcheck disable=SC2181 # Long command +if [[ $? -ne 0 ]] ; then + error "git diff failed" exit 1 fi # Ensure this script is running inside an npm run context -if [[ -n "$npm_lifecycle_event" ]]; then - eslint --max-warnings=0 --config ./.eslintrc.changed.js "${DIFF_OUTPUT}" -else - error "This script is meant to run by using npm run lint-changed" +IS_NPM_CONTEXT="${npm_lifecycle_event:-}" +if [[ -z $IS_NPM_CONTEXT ]]; then + info "Re-executing this script from an npm context" + exec npx -c "NODE_OPTIONS=--max_old_space_size=8192 ${BASH_SOURCE[0]} $*" fi +eslint --max-warnings=0 --config ./.eslintrc.changed.js "${DIFF_OUTPUT}" \ No newline at end of file From 97005d07b5d99d6406f369a145784f685420d0ef Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 11:02:42 -0400 Subject: [PATCH 07/32] scripts: lintChanged.sh unify style Unify style on curly braces and semicolons. Remove the no-pager option from the diff output --- scripts/lintChanged.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index b6ff708d0c99..6c4877859738 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -10,15 +10,15 @@ source "${TOP}/scripts/shellUtils.sh" MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" # Check if output is empty or malformed -if [[ -z "${MERGE_BASE_SHA_HASH}" ]] || ! [[ "${MERGE_BASE_SHA_HASH}" =~ ^[a-fA-F0-9]{40}$ ]]; then +if [[ -z "$MERGE_BASE_SHA_HASH" ]] || ! [[ "$MERGE_BASE_SHA_HASH" =~ ^[a-fA-F0-9]{40}$ ]]; then error "git merge-base returned unexpected output" exit 1 fi -DIFF_OUTPUT="$(git --no-pager diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" +DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" # Check if there were any changes. # shellcheck disable=SC2181 # Long command -if [[ $? -ne 0 ]] ; then +if [[ $? -ne 0 ]]; then error "git diff failed" exit 1 fi @@ -29,4 +29,4 @@ if [[ -z $IS_NPM_CONTEXT ]]; then info "Re-executing this script from an npm context" exec npx -c "NODE_OPTIONS=--max_old_space_size=8192 ${BASH_SOURCE[0]} $*" fi -eslint --max-warnings=0 --config ./.eslintrc.changed.js "${DIFF_OUTPUT}" \ No newline at end of file +eslint --max-warnings=0 --config ./.eslintrc.changed.js "$DIFF_OUTPUT" \ No newline at end of file From 4f9bc6791188ac518fc1727ab21da5b3f817972f Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 11:29:08 -0400 Subject: [PATCH 08/32] scripts: lintChanged.sh add CI/local checks Move the NPM checking logic to top of script. Add CI variable checks to detect if local or on CI. Clean some comments. This commit is a stopgap using depth=30000 until a better solution is implemented. --- .github/workflows/lint-changed.yml | 3 --- scripts/lintChanged.sh | 23 ++++++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 56e825d73088..d87e90723ebf 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -30,8 +30,5 @@ jobs: - name: Run ESLint to check for deprecation warnings run: | - # This will just fetch the latest commit from main - git fetch origin main --no-tags --depth=30000 - # shellcheck disable=SC2046 npm run lint-changed diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index 6c4877859738..d9d869a37baa 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -8,6 +8,21 @@ TOP="$(realpath "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) readonly TOP source "${TOP}/scripts/shellUtils.sh" +# Ensure this script is running inside an npm run context +if [[ -z "${npm_lifecycle_event:-}" ]]; then + info "Re-executing this script from an npm context" + exec npx -c "NODE_OPTIONS=--max_old_space_size=8192 ${BASH_SOURCE[0]} $*" +fi + +# Fetch the commit history to include the merge-base commit +if [[ -z "${CI:-}" ]]; then + info "Running lintChanged locally." + git fetch origin main --no-tags +else + info "Running lintChanged on CI." + git fetch origin main --no-tags --depth=30000 +fi + MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" # Check if output is empty or malformed if [[ -z "$MERGE_BASE_SHA_HASH" ]] || ! [[ "$MERGE_BASE_SHA_HASH" =~ ^[a-fA-F0-9]{40}$ ]]; then @@ -16,17 +31,11 @@ if [[ -z "$MERGE_BASE_SHA_HASH" ]] || ! [[ "$MERGE_BASE_SHA_HASH" =~ ^[a-fA-F0-9 fi DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" -# Check if there were any changes. +# Check if there were any changes # shellcheck disable=SC2181 # Long command if [[ $? -ne 0 ]]; then error "git diff failed" exit 1 fi -# Ensure this script is running inside an npm run context -IS_NPM_CONTEXT="${npm_lifecycle_event:-}" -if [[ -z $IS_NPM_CONTEXT ]]; then - info "Re-executing this script from an npm context" - exec npx -c "NODE_OPTIONS=--max_old_space_size=8192 ${BASH_SOURCE[0]} $*" -fi eslint --max-warnings=0 --config ./.eslintrc.changed.js "$DIFF_OUTPUT" \ No newline at end of file From 62eedc95c3561a322de8c022c20371d221e4cc76 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 14:51:08 -0400 Subject: [PATCH 09/32] workflows: lint-changed: add commit count logic Add logic to the lint-changed workflow to query for a merge-base, then calculate the number of commits from the base to the HEAD, and perform a checkout with minimal depth needed. Updated lintChanged.sh script to remove CI specific code, and use the same logic. --- .github/workflows/lint-changed.yml | 31 ++++++++++++++++++++++++++++-- scripts/lintChanged.sh | 8 +------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index d87e90723ebf..e5fa693c5989 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -17,17 +17,44 @@ jobs: if: ${{ github.actor != 'OSBotify' || github.event_name == 'workflow_call' }} runs-on: ubuntu-latest steps: + - name: Fetch merge base SHA from API + id: merge_base + run: | + MERGE_BASE_SHA="$(gh api repos/$REPO/compare/$PR_BASE_SHA...$PR_HEAD_SHA \ + | jq -r '.merge_base_commit.sha')" + echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + + - name: Count commits between merge base and HEAD + id: count + run: | + echo "Comparing $BASE...$HEAD" + + COMMIT_COUNT=$(gh api repos/${{ github.repository }}/compare/$BASE...main \ + --jq '.total_commits') + + echo "Number of commits between $BASE and $HEAD: $COMMIT_COUNT" + echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} + - name: Checkout + if: steps.count.outputs.count != '0' # v4 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: - fetch-depth: 30000 + fetch-depth: ${{ steps.count.outputs.count }} - name: Setup Node uses: ./.github/actions/composite/setupNode with: IS_DESKTOP_BUILD: true - + - name: Run ESLint to check for deprecation warnings run: | # shellcheck disable=SC2046 diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index d9d869a37baa..868ffe4fb72a 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -15,13 +15,7 @@ if [[ -z "${npm_lifecycle_event:-}" ]]; then fi # Fetch the commit history to include the merge-base commit -if [[ -z "${CI:-}" ]]; then - info "Running lintChanged locally." - git fetch origin main --no-tags -else - info "Running lintChanged on CI." - git fetch origin main --no-tags --depth=30000 -fi +git fetch origin main --no-tags MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" # Check if output is empty or malformed From 005dc2e711c6b626625e88d4b4bb1d93d48dd023 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 15:09:51 -0400 Subject: [PATCH 10/32] workflows: lint-changed: shellcheck fixes --- .github/workflows/lint-changed.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index e5fa693c5989..56738fd34930 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,9 +20,9 @@ jobs: - name: Fetch merge base SHA from API id: merge_base run: | - MERGE_BASE_SHA="$(gh api repos/$REPO/compare/$PR_BASE_SHA...$PR_HEAD_SHA \ - | jq -r '.merge_base_commit.sha')" - echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" + API_CALL="repos/${REPO}/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" + MERGE_BASE_SHA="$(gh api "$API_CALL"| jq -r '.merge_base_commit.sha')" + echo "MERGE_BASE_SHA={$MERGE_BASE_SHA}" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} @@ -32,12 +32,11 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | - echo "Comparing $BASE...$HEAD" + # echo "Comparing ${BASE}...${HEAD}" + API_CALL="repos/${{ github.repository }}/compare/${BASE}...main" + COMMIT_COUNT=$(gh api "$API_CALL" --jq '.total_commits') - COMMIT_COUNT=$(gh api repos/${{ github.repository }}/compare/$BASE...main \ - --jq '.total_commits') - - echo "Number of commits between $BASE and $HEAD: $COMMIT_COUNT" + # echo "Number of commits between ${BASE} and ${HEAD}: ${COMMIT_COUNT}" echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b0b50e56ad0b3754a378887a9dadd34a00347431 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 15:12:21 -0400 Subject: [PATCH 11/32] Revert "workflows: lint-changed: shellcheck fixes" This reverts commit 8e8d27075d3e5d00b42d200d264d5980747a5758. Bug was introduced --- .github/workflows/lint-changed.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 56738fd34930..e5fa693c5989 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,9 +20,9 @@ jobs: - name: Fetch merge base SHA from API id: merge_base run: | - API_CALL="repos/${REPO}/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" - MERGE_BASE_SHA="$(gh api "$API_CALL"| jq -r '.merge_base_commit.sha')" - echo "MERGE_BASE_SHA={$MERGE_BASE_SHA}" >> "$GITHUB_OUTPUT" + MERGE_BASE_SHA="$(gh api repos/$REPO/compare/$PR_BASE_SHA...$PR_HEAD_SHA \ + | jq -r '.merge_base_commit.sha')" + echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} REPO: ${{ github.repository }} @@ -32,11 +32,12 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | - # echo "Comparing ${BASE}...${HEAD}" - API_CALL="repos/${{ github.repository }}/compare/${BASE}...main" - COMMIT_COUNT=$(gh api "$API_CALL" --jq '.total_commits') + echo "Comparing $BASE...$HEAD" - # echo "Number of commits between ${BASE} and ${HEAD}: ${COMMIT_COUNT}" + COMMIT_COUNT=$(gh api repos/${{ github.repository }}/compare/$BASE...main \ + --jq '.total_commits') + + echo "Number of commits between $BASE and $HEAD: $COMMIT_COUNT" echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 487aa6bd2cce9915ac3763a8f0c0c7be19719a27 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 15:25:43 -0400 Subject: [PATCH 12/32] workflows: lint-changed: fix the shellcheck errors --- .github/workflows/lint-changed.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index e5fa693c5989..7f8fe7ff2bfb 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,7 +20,7 @@ jobs: - name: Fetch merge base SHA from API id: merge_base run: | - MERGE_BASE_SHA="$(gh api repos/$REPO/compare/$PR_BASE_SHA...$PR_HEAD_SHA \ + MERGE_BASE_SHA="$(gh api repos/"$REPO"/compare/"$PR_BASE_SHA"..."$PR_HEAD_SHA" \ | jq -r '.merge_base_commit.sha')" echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" env: @@ -32,16 +32,13 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | - echo "Comparing $BASE...$HEAD" - - COMMIT_COUNT=$(gh api repos/${{ github.repository }}/compare/$BASE...main \ - --jq '.total_commits') - - echo "Number of commits between $BASE and $HEAD: $COMMIT_COUNT" + COMMIT_COUNT="$(gh api repos/"$REPO"/compare/"$BASE"...main \ + --jq '.total_commits')" echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} + REPO: ${{ github.repository }} - name: Checkout if: steps.count.outputs.count != '0' From b99a4e0ca2685224bd2eabc815f6e22a16d9542c Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 16:29:03 -0400 Subject: [PATCH 13/32] workflows: lint-changed remove checkout condition When count is zero, we still want to fetch. Also we want to do shallow fetch, zero fetch-depth is all history --- .github/workflows/lint-changed.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 7f8fe7ff2bfb..762799c21623 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -41,11 +41,10 @@ jobs: REPO: ${{ github.repository }} - name: Checkout - if: steps.count.outputs.count != '0' # v4 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: - fetch-depth: ${{ steps.count.outputs.count }} + fetch-depth: ${{ max(1, fromJson(steps.count.outputs.count)) }} - name: Setup Node uses: ./.github/actions/composite/setupNode From 10289538b42c67986ecb59fd8d657975d8231cf1 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 16:36:59 -0400 Subject: [PATCH 14/32] workflows: lint-changed.yml replace max logic Use ternary logic to replace the max operation for github actions --- .github/workflows/lint-changed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 762799c21623..b3f29defb2f4 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -44,7 +44,7 @@ jobs: # v4 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: - fetch-depth: ${{ max(1, fromJson(steps.count.outputs.count)) }} + fetch-depth: ${{ fromJSON(steps.count.outputs.count) > 0 && steps.count.outputs.count || '1' }} - name: Setup Node uses: ./.github/actions/composite/setupNode From f3be8ab582e900d094cc27633ac0e893ab8bf9f4 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 29 May 2025 17:16:04 -0400 Subject: [PATCH 15/32] scripts: lintChanged.sh: handle large file count --- scripts/lintChanged.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index 868ffe4fb72a..ccdddbb06c19 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -24,12 +24,22 @@ if [[ -z "$MERGE_BASE_SHA_HASH" ]] || ! [[ "$MERGE_BASE_SHA_HASH" =~ ^[a-fA-F0-9 exit 1 fi -DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" -# Check if there were any changes -# shellcheck disable=SC2181 # Long command +# Get the diff output and check status +GIT_DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" +# shellcheck disable=SC2181 if [[ $? -ne 0 ]]; then - error "git diff failed" - exit 1 + error "git diff failed" + exit 1 fi -eslint --max-warnings=0 --config ./.eslintrc.changed.js "$DIFF_OUTPUT" \ No newline at end of file +# Populate an array with changed files to handle large number of changes. +DIFF_FILES=() +# Use a here-string to pass the output into the function +read_lines_into_array DIFF_FILES <<< "$GIT_DIFF_OUTPUT" + +# Run eslint on the changed files +if [ "${#DIFF_FILES[@]}" -gt 0 ]; then + eslint --max-warnings=0 --config ./.eslintrc.changed.js "${DIFF_FILES[@]}" +else + info "No TypeScript files changed" +fi From b90f49cd7a49fba2d789ef334573a41f01b76243 Mon Sep 17 00:00:00 2001 From: rory Date: Wed, 21 May 2025 09:37:39 -0700 Subject: [PATCH 16/32] Use tag instead of app version for release link --- .github/workflows/deploy.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 363ca9dad665..e08755fbc9b5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -752,7 +752,7 @@ jobs: channel: '#announce', attachments: [{ color: 'good', - text: `🎉️ Successfully deployed ${process.env.AS_REPO} to ${{ github.ref == 'refs/heads/production' && 'production' || 'staging' }} 🎉️`, + text: `🎉️ Successfully deployed ${process.env.AS_REPO} to ${{ github.ref == 'refs/heads/production' && 'production' || 'staging' }} 🎉️`, }] } env: @@ -769,7 +769,7 @@ jobs: channel: '#deployer', attachments: [{ color: 'good', - text: `🎉️ Successfully deployed ${process.env.AS_REPO} to ${{ github.ref == 'refs/heads/production' && 'production' || 'staging' }} 🎉️`, + text: `🎉️ Successfully deployed ${process.env.AS_REPO} to ${{ github.ref == 'refs/heads/production' && 'production' || 'staging' }} 🎉️`, }] } env: @@ -787,7 +787,7 @@ jobs: channel: '#expensify-open-source', attachments: [{ color: 'good', - text: `🎉️ Successfully deployed ${process.env.AS_REPO} to production 🎉️`, + text: `🎉️ Successfully deployed ${process.env.AS_REPO} to production 🎉️`, }] } env: From 1e48052cbbd6e5128bf90d7a56dc0baecf1ac1e2 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Fri, 30 May 2025 13:08:18 -0400 Subject: [PATCH 17/32] trigger workflows, will revert --- .github/workflows/lint-changed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index b3f29defb2f4..6132b063764c 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -34,7 +34,7 @@ jobs: run: | COMMIT_COUNT="$(gh api repos/"$REPO"/compare/"$BASE"...main \ --jq '.total_commits')" - echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" + echo "count="$COMMIT_COUNT"" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} From a1ea4f30e6cdfdfd3e8be81771c6c9b90eddae90 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Fri, 30 May 2025 13:08:43 -0400 Subject: [PATCH 18/32] Revert "trigger workflows, will revert" This reverts commit 1e48052cbbd6e5128bf90d7a56dc0baecf1ac1e2. --- .github/workflows/lint-changed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 6132b063764c..b3f29defb2f4 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -34,7 +34,7 @@ jobs: run: | COMMIT_COUNT="$(gh api repos/"$REPO"/compare/"$BASE"...main \ --jq '.total_commits')" - echo "count="$COMMIT_COUNT"" >> "$GITHUB_OUTPUT" + echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} From 38564ebfa42c93c2c206cf7de830fe3a925bf760 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Mon, 2 Jun 2025 14:01:13 -0400 Subject: [PATCH 19/32] apply suggestions Apply style, bash safety, additional logging suggestions. Co-authored-by: Rafe Colton <1058475+rafecolton@users.noreply.github.com> --- .github/workflows/lint-changed.yml | 10 +++++----- scripts/lintChanged.sh | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index b3f29defb2f4..3ae44f88a64c 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,25 +20,25 @@ jobs: - name: Fetch merge base SHA from API id: merge_base run: | - MERGE_BASE_SHA="$(gh api repos/"$REPO"/compare/"$PR_BASE_SHA"..."$PR_HEAD_SHA" \ + MERGE_BASE_SHA="$(gh api "repos/$REPO/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" \ | jq -r '.merge_base_commit.sha')" echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository }} + REPO: ${{ github.repository }} PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - - name: Count commits between merge base and HEAD + - name: Count commits between merge base and HEAD id: count run: | - COMMIT_COUNT="$(gh api repos/"$REPO"/compare/"$BASE"...main \ + COMMIT_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" \ --jq '.total_commits')" echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} - REPO: ${{ github.repository }} + REPO: ${{ github.repository }} - name: Checkout # v4 diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index ccdddbb06c19..eff98f094303 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -18,18 +18,18 @@ fi git fetch origin main --no-tags MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" +readonly MERGE_BASE_SHA_HASH + # Check if output is empty or malformed if [[ -z "$MERGE_BASE_SHA_HASH" ]] || ! [[ "$MERGE_BASE_SHA_HASH" =~ ^[a-fA-F0-9]{40}$ ]]; then - error "git merge-base returned unexpected output" + error "git merge-base returned unexpected output: $MERGE_BASE_SHA_HASH" exit 1 fi # Get the diff output and check status -GIT_DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')" -# shellcheck disable=SC2181 -if [[ $? -ne 0 ]]; then - error "git diff failed" - exit 1 +if ! GIT_DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_HASH" HEAD -- '*.ts' '*.tsx')"; then + error "git diff failed - output: $GIT_DIFF_OUTPUT" + exit 1 fi # Populate an array with changed files to handle large number of changes. From b57c422bd3751eabae66af701a41df95651d71ff Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Mon, 2 Jun 2025 14:17:19 -0400 Subject: [PATCH 20/32] scripts: lintChanged: remove array logic Remove the array logic and add necessary shellcheck disable. Resolves [this suggestion](https://github.com/Expensify/App/pull/62993/files#r2121791420). --- scripts/lintChanged.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index eff98f094303..7107abeaf361 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -32,14 +32,10 @@ if ! GIT_DIFF_OUTPUT="$(git diff --diff-filter=AMR --name-only "$MERGE_BASE_SHA_ exit 1 fi -# Populate an array with changed files to handle large number of changes. -DIFF_FILES=() -# Use a here-string to pass the output into the function -read_lines_into_array DIFF_FILES <<< "$GIT_DIFF_OUTPUT" - # Run eslint on the changed files -if [ "${#DIFF_FILES[@]}" -gt 0 ]; then - eslint --max-warnings=0 --config ./.eslintrc.changed.js "${DIFF_FILES[@]}" +if [[ -n "$GIT_DIFF_OUTPUT" ]] ; then + # shellcheck disable=SC2086 # For multiple files in variable + eslint --max-warnings=0 --config ./.eslintrc.changed.js $GIT_DIFF_OUTPUT else - info "No TypeScript files changed" -fi + info "No TypeScript files changed" +fi \ No newline at end of file From 2dc41f4ee58c55ea9a8938044b9cc57ab1b2567e Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Mon, 2 Jun 2025 14:21:01 -0400 Subject: [PATCH 21/32] Update .github/workflows/lint-changed.yml make jq usage the same Co-authored-by: Rafe Colton <1058475+rafecolton@users.noreply.github.com> --- .github/workflows/lint-changed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 3ae44f88a64c..fb268409ebb8 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -33,7 +33,7 @@ jobs: id: count run: | COMMIT_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" \ - --jq '.total_commits')" + | jq -r '.total_commits')" echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 7a1518632f8abaae76e8783b93ec749488cfb87f Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:00:01 -0400 Subject: [PATCH 22/32] Apply suggestions from code review Indentation and multi-line breaks. Co-authored-by: Rafe Colton <1058475+rafecolton@users.noreply.github.com> --- .github/workflows/lint-changed.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index fb268409ebb8..b636185feffe 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,8 +20,7 @@ jobs: - name: Fetch merge base SHA from API id: merge_base run: | - MERGE_BASE_SHA="$(gh api "repos/$REPO/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" \ - | jq -r '.merge_base_commit.sha')" + MERGE_BASE_SHA="$(gh api "repos/$REPO/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" | jq -r '.merge_base_commit.sha')" echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -32,8 +31,7 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | - COMMIT_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" \ - | jq -r '.total_commits')" + COMMIT_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" | jq -r '.total_commits')" echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 5e3491e5ed262c72da002e785e2100b1904e12bd Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Tue, 3 Jun 2025 09:09:58 -0400 Subject: [PATCH 23/32] scripts: lintChanged.sh: add newline EOF Co-authored-by: Rafe Colton <1058475+rafecolton@users.noreply.github.com> --- scripts/lintChanged.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index 7107abeaf361..03a833ea9b53 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -38,4 +38,4 @@ if [[ -n "$GIT_DIFF_OUTPUT" ]] ; then eslint --max-warnings=0 --config ./.eslintrc.changed.js $GIT_DIFF_OUTPUT else info "No TypeScript files changed" -fi \ No newline at end of file +fi From b7e99b0e040e71fe81f61b4ef22cbe5a184b8fb8 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Tue, 3 Jun 2025 12:30:10 -0400 Subject: [PATCH 24/32] Revert "intentionally create a useOnyx canBeMissing error" This reverts commit 18af2cf98d2001c24267003780a44328df11bb3d. --- src/pages/TransactionReceiptPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/TransactionReceiptPage.tsx b/src/pages/TransactionReceiptPage.tsx index 8350f1eaacdb..faf4fd42f8d3 100644 --- a/src/pages/TransactionReceiptPage.tsx +++ b/src/pages/TransactionReceiptPage.tsx @@ -22,7 +22,7 @@ function TransactionReceipt({route}: TransactionReceiptProps) { const reportID = route.params.reportID; const transactionID = route.params.transactionID; const action = route.params.action; - const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`); + const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {canBeMissing: true}); const [transactionMain] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {canBeMissing: true}); const [transactionDraft] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {canBeMissing: true}); const [reportMetadata = {isLoadingInitialReportActions: true}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {canBeMissing: true}); From 03cf5d5347ba1c125474f4064dac015e2f1f6e00 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Tue, 3 Jun 2025 15:58:56 -0400 Subject: [PATCH 25/32] fix: scripts: lintChanged.sh: unshallow branch Unshallow the current working branch or HEAD if it is detected. This addresses a problem when we shallow fetch (depth=1) origin/main, i.e. merge main into a PR branch. This would lead the `git merge-base` to fail as we wouldn't have enough history of our PR branch to run. --- scripts/lintChanged.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index 03a833ea9b53..eb5bf7af3107 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -15,8 +15,17 @@ if [[ -z "${npm_lifecycle_event:-}" ]]; then fi # Fetch the commit history to include the merge-base commit +info "Fetching origin/main" git fetch origin main --no-tags +CURRENT_BRANCH="$(git branch --show-current)" +readonly CURRENT_BRANCH + +if [[ "$CURRENT_BRANCH" != "main" ]] && [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then + info "The current branch was fetched shallow, fetching again unshallow." + git fetch --unshallow origin HEAD +fi + MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" readonly MERGE_BASE_SHA_HASH From 6f3736140decca15df385683cf90721442b96ecf Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Tue, 3 Jun 2025 16:16:18 -0400 Subject: [PATCH 26/32] cspell config: Add unshallow to the words --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 183fe18ac807..be80221510d8 100644 --- a/cspell.json +++ b/cspell.json @@ -595,6 +595,7 @@ "Unmigrated", "unredacted", "unscrollable", + "unshallow", "unsubmitted", "UNSWIPEABLE", "Unvalidated", From 18c3c6de00698218febe5e473d7d68fb2e3a0b23 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 4 Jun 2025 13:37:36 -0400 Subject: [PATCH 27/32] lint-changed: fix fetch-depth The fetch-depth had a minimum of 1 commit, this would fetch the merge commit created by GitHub on a PR. This led us to fetching origin main with full history in the lintChanged.sh script. Setting a minimum of 2 for depth allows us to fetch: 1. the merge commit of the PR 2. the minimum number of commits needed to include merge-base --- .github/workflows/lint-changed.yml | 7 ++++--- scripts/lintChanged.sh | 8 -------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index b636185feffe..269f88a80bd9 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -31,8 +31,9 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | - COMMIT_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" | jq -r '.total_commits')" - echo "count=$COMMIT_COUNT" >> "$GITHUB_OUTPUT" + RAW_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" | jq -r '.total_commits')" + ADJUSTED_COUNT=$((RAW_COUNT + 2)) + echo "count=$ADJUSTED_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} @@ -42,7 +43,7 @@ jobs: # v4 uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 with: - fetch-depth: ${{ fromJSON(steps.count.outputs.count) > 0 && steps.count.outputs.count || '1' }} + fetch-depth: ${{ fromJSON(steps.count.outputs.count) }} - name: Setup Node uses: ./.github/actions/composite/setupNode diff --git a/scripts/lintChanged.sh b/scripts/lintChanged.sh index eb5bf7af3107..30c170109276 100755 --- a/scripts/lintChanged.sh +++ b/scripts/lintChanged.sh @@ -18,14 +18,6 @@ fi info "Fetching origin/main" git fetch origin main --no-tags -CURRENT_BRANCH="$(git branch --show-current)" -readonly CURRENT_BRANCH - -if [[ "$CURRENT_BRANCH" != "main" ]] && [[ "$(git rev-parse --is-shallow-repository)" == "true" ]]; then - info "The current branch was fetched shallow, fetching again unshallow." - git fetch --unshallow origin HEAD -fi - MERGE_BASE_SHA_HASH="$(git merge-base origin/main HEAD)" readonly MERGE_BASE_SHA_HASH From ca3f78d755db0732e7e4220402f884b66cdee7fc Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Wed, 4 Jun 2025 16:45:55 -0400 Subject: [PATCH 28/32] Revert "cspell config: Add unshallow to the words" This reverts commit 6f3736140decca15df385683cf90721442b96ecf. Unnecessary cspell changes. --- cspell.json | 1 - 1 file changed, 1 deletion(-) diff --git a/cspell.json b/cspell.json index be80221510d8..183fe18ac807 100644 --- a/cspell.json +++ b/cspell.json @@ -595,7 +595,6 @@ "Unmigrated", "unredacted", "unscrollable", - "unshallow", "unsubmitted", "UNSWIPEABLE", "Unvalidated", From 8cc3ee05ca5c3bf88792399a68771fce7be1d5b0 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 5 Jun 2025 10:16:41 -0400 Subject: [PATCH 29/32] Apply suggestions from code review Use github.token instead of secrets. Co-authored-by: Rory Abraham <47436092+roryabraham@users.noreply.github.com> --- .github/workflows/lint-changed.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 269f88a80bd9..bcaf90640829 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -23,7 +23,7 @@ jobs: MERGE_BASE_SHA="$(gh api "repos/$REPO/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" | jq -r '.merge_base_commit.sha')" echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} @@ -35,7 +35,7 @@ jobs: ADJUSTED_COUNT=$((RAW_COUNT + 2)) echo "count=$ADJUSTED_COUNT" >> "$GITHUB_OUTPUT" env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ github.token }} BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} REPO: ${{ github.repository }} From db58cf12744e1560160adff1a6a124d48cf3b737 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 5 Jun 2025 15:23:51 -0400 Subject: [PATCH 30/32] workflows: lint-changed.yml: remove call to api Remove unnecessary call to the GH api for getting merge-base. --- .github/workflows/lint-changed.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index bcaf90640829..4ea24e7d3c9e 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -17,17 +17,6 @@ jobs: if: ${{ github.actor != 'OSBotify' || github.event_name == 'workflow_call' }} runs-on: ubuntu-latest steps: - - name: Fetch merge base SHA from API - id: merge_base - run: | - MERGE_BASE_SHA="$(gh api "repos/$REPO/compare/${PR_BASE_SHA}...${PR_HEAD_SHA}" | jq -r '.merge_base_commit.sha')" - echo "MERGE_BASE_SHA=$MERGE_BASE_SHA" >> "$GITHUB_OUTPUT" - env: - GH_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} - PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} - - name: Count commits between merge base and HEAD id: count run: | @@ -36,7 +25,7 @@ jobs: echo "count=$ADJUSTED_COUNT" >> "$GITHUB_OUTPUT" env: GH_TOKEN: ${{ github.token }} - BASE: ${{ steps.merge_base.outputs.MERGE_BASE_SHA }} + BASE: ${{ github.event.pull_request.base.sha }} REPO: ${{ github.repository }} - name: Checkout From 5b73da2e7b6a6458e66bb11f337cdc93e09f7341 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 5 Jun 2025 17:17:14 -0400 Subject: [PATCH 31/32] workflows: lint-changed: add comment to explain +2 --- .github/workflows/lint-changed.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index 4ea24e7d3c9e..f634398863c6 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,7 +20,9 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | + # Fetch the number of commits from base up to and including main. RAW_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" | jq -r '.total_commits')" + # When fetching we need to fetch the history + base + temp merge commit, thus +2. ADJUSTED_COUNT=$((RAW_COUNT + 2)) echo "count=$ADJUSTED_COUNT" >> "$GITHUB_OUTPUT" env: From de2156f1d81784aab979afe0c6363235c611aa39 Mon Sep 17 00:00:00 2001 From: Dylan Le <54580990+MacroLens@users.noreply.github.com> Date: Thu, 5 Jun 2025 20:05:09 -0400 Subject: [PATCH 32/32] workflows: lint-changed: add more detailed comment --- .github/workflows/lint-changed.yml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint-changed.yml b/.github/workflows/lint-changed.yml index f634398863c6..7bba2072bdd6 100644 --- a/.github/workflows/lint-changed.yml +++ b/.github/workflows/lint-changed.yml @@ -20,9 +20,25 @@ jobs: - name: Count commits between merge base and HEAD id: count run: | - # Fetch the number of commits from base up to and including main. + # Compare the base commit and HEAD to get the count of commits after base + # up to and including HEAD. Add 2 to this total when fetching history. + # + # When opening a PR, GitHub will create a merge commit that squashes + # your changes for use in the workflow. So your history locally + # may look like + # o---o---o---B - development + # / + # ---o---1---C---o---o---A - main + # Note that the `1` is the merge-base of development and main. The + # number of commits after `1` upto and including `A` is 4. + # In the workflow, GitHub squashs development, so it becomes: + # ---o---1---C---o---o---A - main + # \--M - PR branch + # Where `M`` is the new squashed commit. To fetch enough history to + # include the merge base, we need to fetch `M`, `A` through `C` and + # `1` for total of 4+2=6 commits. The +2 commits accounts for the + # base `1` and merge commit `M`. RAW_COUNT="$(gh api "repos/$REPO/compare/${BASE}...main" | jq -r '.total_commits')" - # When fetching we need to fetch the history + base + temp merge commit, thus +2. ADJUSTED_COUNT=$((RAW_COUNT + 2)) echo "count=$ADJUSTED_COUNT" >> "$GITHUB_OUTPUT" env: