Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git diff Step Fails with “fatal: bad object” Error in GitHub Action #31432

Open
fabrizzio-dotCMS opened this issue Feb 20, 2025 · 0 comments

Comments

@fabrizzio-dotCMS
Copy link
Contributor

Parent Issue

#26300

Problem Statement

One of the steps in our main.yaml workflow runs a git diff operation to compare GitHub events before and after a change. The output of this git diff command is written to a changed-files.txt file, which is then used in a subsequent step to report modified files.

The file is tools/dotcms-cli/action/.github/workflows/main.yml

The Code that needs the fix looks like this:

      - name: Get changes
        run: |
          git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt

      - name: List changed files
        run: |
          while IFS= read -r line
          do
            echo "\"$line\" was changed"
          done < changed_files.txt

These two steps are used to list the files that have changed between events.

the proposed fix looks as follows:

- name: Get changes
        run: |
          git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt 2>/dev/null || echo -n "" > changed_files.txt

      - name: List changed files
        run: |
          while IFS= read -r line
          do
            echo "\"$line\" was changed"
          done < changed_files.txt

Steps to Reproduce

it isn't clear how this can happen
However

  • I created an empty repo on GitHub
  • I cloned the repo locally
  • Checked out the demo and the git pushed
  • then pushed the changes with the required workflows
  • and finally added a .env file
  • Then when I felt the GHA was ready I added an image under
    files/working/en-us/demo.dotcms.com/images/
    and git pushed to the remote repo

Then the error came up

Acceptance Criteria

•	The git diff step should always find valid commit references.
•	If an issue occurs, the step should recover gracefully and proceed without breaking the workflow.

dotCMS Version

current main

Proposed Objective

Technical User Experience

Proposed Priority

Please Select

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Next 1-3 Sprints
Development

No branches or pull requests

2 participants