From 8f0cc6e31e54ca18ba21ef21b8aa5bc6c09670bd Mon Sep 17 00:00:00 2001 From: Satyam Jha Date: Wed, 15 Jan 2025 12:23:33 +0530 Subject: [PATCH 1/2] updated pull-request.yml to auto-commit changes in pubspec.lock --- .github/workflows/pull-request.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 81dc22964..36057e9bd 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -22,12 +22,15 @@ jobs: Flutter-Codebase-Check: name: Checking codebase runs-on: ubuntu-latest + permissions: + contents: write #needs: PR-Greeting steps: - uses: actions/checkout@v4 with: # ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} - uses: actions/setup-java@v4 with: distribution: 'zulu' # See 'Supported distributions' for available options @@ -43,6 +46,18 @@ jobs: run: cd talawa_lint && flutter pub get && cd .. - name: Running pub get to fetch dependencies run: flutter pub get + - name: Check and commit pubspec.lock changes + run: | + if [[ $(git status --porcelain pubspec.lock) ]]; then + echo "Changes detected in pubspec.lock. Auto-committing updates." + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add pubspec.lock + git commit -a -m "Automated update of pubspec.lock" + git push origin HEAD:${{ github.head_ref }} + else + echo "No changes in pubspec.lock." + fi - name: Checking for correct formatting of code run: dart format --set-exit-if-changed . - name: Count lines of code in each file @@ -58,7 +73,6 @@ jobs: git branch git checkout -b temp_branch git branch - git stash push -m lock_file pubspec.lock git checkout develop-postgres git pull git branch From bc8169dc946a41c14b3baaf4f00354bd67245d9f Mon Sep 17 00:00:00 2001 From: Satyam Jha Date: Wed, 15 Jan 2025 21:40:45 +0530 Subject: [PATCH 2/2] added codeRabbit suggestions --- .github/workflows/pull-request.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 36057e9bd..ee566dd43 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -47,14 +47,19 @@ jobs: - name: Running pub get to fetch dependencies run: flutter pub get - name: Check and commit pubspec.lock changes + env: + HEAD_REF: ${{ github.head_ref }} run: | if [[ $(git status --porcelain pubspec.lock) ]]; then echo "Changes detected in pubspec.lock. Auto-committing updates." git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add pubspec.lock - git commit -a -m "Automated update of pubspec.lock" - git push origin HEAD:${{ github.head_ref }} + git commit -a -m "chore: Auto-update pubspec.lock in PR #${{ github.event.pull_request.number }}" + if ! git push origin HEAD:"$HEAD_REF"; then + echo "Failed to push changes. Please check if you have the correct permissions." + exit 1 + fi else echo "No changes in pubspec.lock." fi