CI: Added restore cache from git for client build (#29938)

## Description
Added restore cache from git for client build
#### Type of change
- New feature (non-breaking change which adds functionality)
## Testing
Tested in local fork
#### How Has This Been Tested?

- [X] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
## Checklist:
#### Dev activity
- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my own code
- [X] I have commented my code, particularly in hard-to-understand areas
- [X] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [X] I have added tests that prove my fix is effective or that my
feature works
- [X] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Refactor**
- Optimized the client build workflow to trigger only on relevant
changes or specific events, ensuring resource-efficient operations.
- **Chores**
- Updated workflow conditions to improve the CI/CD process, enhancing
overall development efficiency.
- **Documentation**
- Provided triage instructions to streamline the handling of workflow
changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
yatinappsmith 2023-12-29 15:26:25 +05:30 committed by GitHub
parent c214222cee
commit 7caf93d526
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -74,10 +74,23 @@ jobs:
uses: actions/checkout@v4
with:
fetch-tags: true
- name: Get changed files in the client folder
id: changed-files-specific
uses: tj-actions/changed-files@v41
with:
files: 'app/client/**'
- name: Run step if any file(s) in the client folder change
if: steps.changed-files-specific.outputs.any_changed == 'true'
env:
ALL_CHANGED_FILES: ${{ steps.changed-files-specific.outputs.all_changed_files }}
run: |
echo "One or more files in the server folder has changed."
echo "List all the files that have changed: $ALL_CHANGED_FILES"
# get all the files changes in the cypress/e2e folder
- name: Get added files in cypress/e2e folder
if: inputs.pr != 0
if: inputs.pr != 0 && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
id: files
uses: umani/changed-files@v4.1.0
with:
@ -87,7 +100,7 @@ jobs:
# Check all the newly added files are in ts
- name: Check the newly added files are written in ts
if: inputs.check-test-files == 'true' && inputs.pr != 0
if: inputs.check-test-files == 'true' && inputs.pr != 0 && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
id: check_files
run: |
files=(${{steps.files.outputs.files_created}})
@ -102,7 +115,7 @@ jobs:
# Comment in PR if test files are not written in ts and fail the workflow
- name: Comment in PR if test files are not written in ts
if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' && inputs.pr != 0
if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' && inputs.pr != 0 && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ inputs.pr }}
@ -110,11 +123,11 @@ jobs:
<b>Below new test files are written in js 🔴 </b>
<b>Expected format ts. Please fix and retrigger ok-to-test:</b>
<ol>${{ steps.check_files.outputs.non_ts_files }}</ol>
- if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' && inputs.pr != 0
- if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' && inputs.pr != 0 && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
run: exit 1
- name: Get all the added or changed files in client/src folder
if: inputs.ads-compliant-check == 'true' && inputs.pr != 0 && github.pull_request.base.ref == 'release'
if: inputs.ads-compliant-check == 'true' && inputs.pr != 0 && github.pull_request.base.ref == 'release' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
id: client_files
uses: umani/changed-files@v4.1.0
with:
@ -124,7 +137,7 @@ jobs:
# Check all the newly added files are in ts
- name: ADS compliant check
if: inputs.ads-compliant-check == 'true' && inputs.pr != 0 && github.pull_request.base.ref == 'release'
if: inputs.ads-compliant-check == 'true' && inputs.pr != 0 && github.pull_request.base.ref == 'release' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
id: ads_check
run: |
comment_files=""
@ -143,7 +156,7 @@ jobs:
# Comment in PR if test files are not written in ts and fail the workflow
- name: Comment in PR if test files are not written in ts
if: steps.ads_check.outputs.ads_non_compliant_count != 0 && inputs.ads-compliant-check == 'true' && inputs.pr != 0 && github.pull_request.base.ref == 'release'
if: steps.ads_check.outputs.ads_non_compliant_count != 0 && inputs.ads-compliant-check == 'true' && inputs.pr != 0 && github.pull_request.base.ref == 'release' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ inputs.pr }}
@ -156,6 +169,7 @@ jobs:
# Create a run record exactly at the time of merge to release to
# ensure we compare run details with code at this point
- name: Create Perf Meta
if: steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
continue-on-error: true
run: |
PGPASSWORD='${{secrets.APPSMITH_PERFORMANCE_DB_PASSWORD}}' psql -h '${{secrets.APPSMITH_PERFORMANCE_DB_HOST}}' \
@ -165,6 +179,7 @@ jobs:
# In case this is second attempt try restoring status of the prior attempt from cache
- name: Restore the previous run result
if: steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
uses: actions/cache@v3
with:
path: |
@ -173,15 +188,16 @@ jobs:
# Fetch prior run result
- name: Get the previous run result
if: steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
id: run_result
run: cat ~/run_result 2>/dev/null || echo 'default'
# In case of prior failure run the job
- if: steps.run_result.outputs.run_result != 'success'
- if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
run: echo "I'm alive!" && exit 0
- name: Use Node.js
if: steps.run_result.outputs.run_result != 'success'
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
uses: actions/setup-node@v3
with:
node-version-file: app/client/package.json
@ -190,7 +206,7 @@ jobs:
# when the project lives in a subdirectory: https://github.com/actions/setup-node/issues/488
# Restoring the cache manually instead
- name: Restore Yarn cache
if: steps.run_result.outputs.run_result != 'success'
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
uses: actions/cache@v3
id: cache-dependencies
with:
@ -199,18 +215,18 @@ jobs:
# Install all the dependencies
- name: Install dependencies
if: steps.run_result.outputs.run_result != 'success'
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
run: |
npm install -g yarn
yarn install --immutable
# Type checking before starting the build
- name: Run type check
if: steps.run_result.outputs.run_result != 'success'
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
run: yarn run check-types
- name: Set the build environment based on the branch
if: steps.run_result.outputs.run_result != 'success'
if: steps.run_result.outputs.run_result != 'success' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
id: vars
run: |
set +o pipefail
@ -232,6 +248,7 @@ jobs:
# We burn React environment & the Segment analytics key into the build itself.
# This is to ensure that we don't need to configure it in each installation
- name: Create the bundle
if: steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
run: |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
export REACT_APP_SEGMENT_CE_KEY="${{ secrets.APPSMITH_SEGMENT_CE_KEY }}"
@ -249,13 +266,14 @@ jobs:
# Saving the cache to use it in subsequent runs
- name: Save Yarn cache
uses: actions/cache/save@v3
if: steps.cache-dependencies.outputs.cache-hit != 'true'
if: steps.cache-dependencies.outputs.cache-hit != 'true' && (steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
with:
path: app/client/.yarn/cache
key: v1-yarn3-${{ hashFiles('app/client/yarn.lock') }}
# Restore the previous built bundle if present. If not push the newly built into the cache
- name: Restore the previous bundle
if: steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
uses: actions/cache@v3
with:
path: |
@ -263,9 +281,31 @@ jobs:
key: ${{ github.run_id }}-${{ github.job }}-client
- name: Pack the client build directory
if: steps.changed-files-specific.outputs.any_changed == 'true' || github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
run: |
tar -cvf ./build.tar -C build .
- name: Fetch client build from cache
if: steps.changed-files-specific.outputs.any_changed == 'false' && success() && github.event_name != 'push' && github.event_name != 'workflow_dispatch' && github.event_name != 'schedule'
env:
cachetoken: ${{ secrets.CACHETOKEN }}
reponame: ${{ github.event.repository.name }}
gituser: ${{ secrets.CACHE_GIT_USER }}
gituseremail: ${{ secrets.CACHE_GIT_EMAIL }}
run: |
mkdir cacherepo
cd ./cacherepo
git lfs install
git config --global user.email "$gituseremail"
git config --global user.name "$gituser"
git clone https://$cachetoken@github.com/appsmithorg/cibuildcache.git
git lfs install
if [ "$reponame" = "appsmith" ]; then export repodir="CE"; fi
if [ "$reponame" = "appsmith-ee" ]; then export repodir="EE"; fi
cd cibuildcache/$repodir/release/client
git lfs pull ./build.tar
mv ./build.tar ../../../../../build.tar
# Upload the build artifact so that it can be used by the test & deploy job in the workflow
- name: Upload react build bundle
uses: actions/upload-artifact@v3