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

sfdx sgd:source:delta not producing a package.xml with changes #275

Closed
1 task
Deelane opened this issue Mar 22, 2022 · 6 comments
Closed
1 task

sfdx sgd:source:delta not producing a package.xml with changes #275

Deelane opened this issue Mar 22, 2022 · 6 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Deelane
Copy link

Deelane commented Mar 22, 2022

Issue verification check :

  • does the current repository is fully deployable at the commit sha given to the from parameter of the command ?

What is the problem

--- No changes are reflected at all in any of the generated package.xml files after running sfdx sgd:source:delta in github actions. Changes were confirmed to exist in the pull request after running git diff (posted at the bottom). Running the command sfdx sgd:source:delta --to dev --from uat --output . locally provides the correct package.xml (the code in the workflow was sfdx sgd:source:delta --to ${{ env.HEAD_REF }}--from ${{ env.BASE_REF }} --output . at first with HEAD_REF being uat and BASE_REF being dev). These should both provide the same result in actions as I have tried them locally and produced the correct delta package.xml. Am I doing something wrong here?

What is parameter and their value you used

          sfdx sgd:source:delta --to pr --from ${{ env.BASE_REF }} --output .
          echo "--- package.xml generated with added and modified metadata ---"
          cat package/package.xml
          echo "--- destructiveChanges.xml ---"
          cat destructiveChanges/destructiveChanges.xml
          echo "--- destructiveChanges/package.xml ---"
          cat destructiveChanges/package.xml

What is the expected result

{
  "error": null,
  "output": ".",
  "success": true,
  "warnings": []
}
--- package.xml generated with added and modified metadata ---
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>googleDriveAPI_v3</members>
        <members>googleDriveAPI_v3_Tests</members>
        <name>ApexClass</name>
    </types>
    <version>54.0</version>
</Package>
--- destructiveChanges.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>54.0</version>
</Package>
--- destructiveChanges/package.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>54.0</version>
</Package>

What is the actual result

{
  "error": null,
  "output": ".",
  "success": true,
  "warnings": []
}
--- package.xml generated with added and modified metadata ---
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>54.0</version>
</Package>
--- destructiveChanges.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>54.0</version>
</Package>
--- destructiveChanges/package.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>54.0</version>
</Package>

Steps to reproduce

      - name: Get branch refs
        run: |
          echo "HEAD_REF=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
          echo "BASE_REF=$(echo ${GITHUB_BASE_REF} | tr / -)" >> $GITHUB_ENV
          
      - name: Install SFDX & SFDX Git Delta
        run: |
          npm install sfdx-cli
          echo y | node_modules/sfdx-cli/bin/run plugins:install sfdx-git-delta
          git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
          git fetch --all
          git checkout -b pr 
          git --no-pager diff --name-status pr origin/${{ env.BASE_REF }}

      - name: Generate package.xml
        run: |
          sfdx sgd:source:delta --to pr --from ${{ env.BASE_REF }} --output .
          echo "--- package.xml generated with added and modified metadata ---"
          cat package/package.xml
          echo "--- destructiveChanges.xml ---"
          cat destructiveChanges/destructiveChanges.xml
          echo "--- destructiveChanges/package.xml ---"
          cat destructiveChanges/package.xml

Execution context


**Operating System: Ubuntu 20.04.3 LTS (Ubuntu Latest on github actions)

yarn version:

node version:

git version:

sfdx version:

sgd plugin version:

Optional more information


Provide the output of those command line :
$ git diff --name-status --no-renames

D	force-app/main/default/classes/googleDriveAPI_v3.cls

D	force-app/main/default/classes/googleDriveAPI_v3.cls-meta.xml

D	force-app/main/default/classes/googleDriveAPI_v3_Tests.cls

D	force-app/main/default/classes/googleDriveAPI_v3_Tests.cls-meta.xml
@Deelane Deelane added the bug Something isn't working label Mar 22, 2022
@Deelane Deelane changed the title [BUG NAME] sfdx sgd:source:delta not producing a package.xml with changes Mar 22, 2022
@scolladon scolladon added the good first issue Good for newcomers label Mar 22, 2022
@scolladon
Copy link
Owner

Hi @Deelane !

Thanks for raising this issue, and sorry for the inconvenience.

There is something I do not understand here, it seems the command sfdx sgd:source:delta --to dev --from uat --output . works locally.
But the command sfdx sgd:source:delta --to pr --from ${{ env.BASE_REF }} --output . does not work when running in the github action.

The only things I can see that is different is the --to parameter. Locally it is set to dev and in the CI it is set to pr.
Maybe the issue comes from here, the two execution are not the same.

Another thing I noticed is that you are not using the checkout github action, is there a specific reason ?
You could consider it and use the fetch-depth parameter to make sure all the commits are retrieved into the CI (checkout tends to retrieve only the latest commit)

@Deelane
Copy link
Author

Deelane commented Mar 22, 2022

Hi scolladon,

I actually omitted the entirety of the code, but I am indeed using the checkout action. Also, I should have specified that I have ran both commands both locally and remote. That is, I have tried --to pr and --from uat, as well as --to dev and --from uat both locally and on actions. I have actually ran more than just that locally/on actions, including HEAD and HEAD^ and also hardcoding dev and uat as --to and --from. Every time I am able to successfully create a package containing the correct diffs locally but unsuccessfully remotely. Here is the whole file for reference:

# Unique name for this workflow
name: Pull Request - Dev to UAT

on:
  pull_request:
    types:
      - opened
    branches:    
      - 'uat'
      - 'UAT'

# Jobs to be executed
jobs:
  uat-org-test:
    runs-on: ubuntu-latest
    steps:
      # Install Salesforce CLI
      - name: Install Salesforce CLI
        run: |
          wget https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
          mkdir sfdx-cli
          tar xJf sfdx-linux-amd64.tar.xz -C sfdx-cli --strip-components 1
          ./sfdx-cli/install
          
      # Checkout the code in the pull request
      - name: 'Checkout source code'
        uses: actions/checkout@v2

      # Store secret for dev hub org
      - name: 'Populate auth file with DEVHUB_SFDX_URL_UAT secret'
        shell: bash
        run: 'echo ${{ secrets.DEVHUB_SFDX_URL_UAT}} > ./DEVHUB_SFDX_URL_UAT.txt'

      # Authenticate dev hub
      # Authorizes org using SFDX auth url stored in a file
      - name: 'Authenticate Dev Hub'
        run: 'sfdx force:auth:sfdxurl:store -f ./DEVHUB_SFDX_URL_UAT.txt -a devhub -d'
        
      # Remove auth file
      - name: "Remove auth file"
        run: rm -f ./DEVHUB_SFDX_URL_UAT.txt
      
      # Set config username for CLI Commands
      - name: "Set config username for CLI commands"
        run: sfdx config:set defaultusername=${{secrets.DEVHUB_SFDX_USER_UAT}} defaultdevhubusername=${{secrets.DEVHUB_SFDX_USER_UAT}}

      # Store branch ids
      - name: Get branch refs
        run: |
          echo "HEAD_REF=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV
          echo "BASE_REF=$(echo ${GITHUB_BASE_REF} | tr / -)" >> $GITHUB_ENV
          
      # Install SFDX & SFDX Git Delta
      - name: Install SFDX & SFDX Git Delta
        run: |
          npm install sfdx-cli
          echo y | node_modules/sfdx-cli/bin/run plugins:install sfdx-git-delta
          git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
          git fetch --all
          git checkout -b pr 
          git --no-pager diff --name-status pr origin/${{ env.BASE_REF }}


      # Generate manifest
      - name: Generate package.xml
        run: |
          sfdx sgd:source:delta --to pr --from ${{ env.BASE_REF }} --output .
          echo "--- package.xml generated with added and modified metadata ---"
          cat package/package.xml
          echo "--- destructiveChanges.xml ---"
          cat destructiveChanges/destructiveChanges.xml
          echo "--- destructiveChanges/package.xml ---"
          cat destructiveChanges/package.xml

      # Test deploy of source code to UAT org
      # Validate deploy but do not actually deploy (-c flag)
      - name: 'Test deploy of source code'
        run: sfdx force:source:deploy -c -x ./package/package.xml -l RunAllTestsInOrg --verbose

@scolladon
Copy link
Owner

Ok thanks, that is helpful.

I can still see git operation in the "Install SFDX & SFDX Git Delta" step:

git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch --all
git checkout -b pr

Why it is doing it ?

Also the checkout v2 step does not fetch every commit, it should be configured to fetch every commit so the git diff can be done inside the CI

@Deelane
Copy link
Author

Deelane commented Mar 23, 2022

Those are honestly me just trying to fix the issue. Some people recommended fetching refs to fix the issue I was having and another was achieving success by checking out a new branch. However, I can confirm that changing the fetch depth to 0 did not fix the issue.

@scolladon
Copy link
Owner

Hi @Deelane !

I tried something on my own and built a CI in our reproduction playground

I created a PR to be able to look at it, you can check the PR status and the related github action here
One thing I noticed is that it is working only when I preffix the from branch with origin/ (per exemple origin/main), I think it could be the reason why you have the current behaviour in your CI/CD

@Deelane
Copy link
Author

Deelane commented Mar 23, 2022

Adding origin fixed it, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants