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

glob patterns are not working during replacements #122

Open
docbill opened this issue Sep 26, 2024 · 5 comments
Open

glob patterns are not working during replacements #122

docbill opened this issue Sep 26, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@docbill
Copy link

docbill commented Sep 26, 2024

Describe the bug
When parsing the sfdx-project.json any replacement patterns using glob are not applied.

To Reproduce

Steps to reproduce the behavior:

  1. Create a project with one or more platformEventSubscriberConfig files, which specify a user tag like SystemUser.
    (Note: This requires you have a valid platform event and platform event subscriber to reference also in the project.)
  2. Create add an element to the "replacements" array like:
    {
    "glob": "src/**/*.platformEventSubscriberConfig-meta.xml",
    "regexToReplace": "[A-Za-z0-9]+User",
    "replaceWithFile": "replacements/EmptyXmlComment"
    }
  3. Create a file "replacements/EmptyXmlComment" that contains
  4. Verify you can deploy your file to an org using the "sf project deploy start" command
  5. Try the same with say a sfp running any stage that deploys the packages like quickdeploy.

Expected behavior
The string SystemUser should be replaced with the empty comment and successfully deploy.

Actual behavior
The replacement does not happen and there is an error that the SystemUser does not exist.

Platform Details (please complete the following information):

sfp -- ❤️ by flxbl.io ❤️ -Version:39.0.3 -Release:June 24

Current runner version: '2.319.1'
Operating System
Ubuntu
22.04.5
LTS
Runner Image
Image: ubuntu-22.04
Version: 20240922.1.0
Included Software: https://github.com/actions/runner-images/blob/ubuntu22/20240922.1/images/ubuntu/Ubuntu2204-Readme.md
Image Release: https://github.com/actions/runner-images/releases/tag/ubuntu22%2F20240922.1
Runner Image Provisioner
2.0.384.1

Additional context
This is particular problematic for files where it is not possible to write a replacement string that is deployable without replacement. As it means the replacement must always happen regardless of DEPLOY_TARGET for every file using that string that must be replaced.

@azlam-abdulsalam
Copy link

@docbill can you confirm where your replacements where stored ? in sfp, the package as such as is installed without the context of the repo. So unless this file is reachable within the context of the package, I do not think it would be supported. We might have to have specific support around it

@docbill
Copy link
Author

docbill commented Oct 3, 2024

@docbill can you confirm where your replacements where stored ? in sfp, the package as such as is installed without the context of the repo. So unless this file is reachable within the context of the package, I do not think it would be supported. We might have to have specific support around it

We store all replacements in a replacement folder in our repo. Here is a relevant sample:

    {
      "glob": "src/transactionlog-subscriber/**/PlatformEventSubscriberConfigs/*.platformEventSubscriberConfig-meta.xml",
      "stringToReplace": "<user>IntegrationUser</user>",
      "replaceWithFile": "replacements/prod/IntegrationUserTag",
      "replaceWhenEnv": [{
				"env": "DEPLOY_TARGET",
				"value": "PROD"
			}]
    }

A completely separate issue is I had to add a validation step in our build pipeline. Because a value like "replacements/PROD/InegrationUserTag" would work locally on a case insensitive file system, but not during a build running in an Linux container.

I will reference that here, as it might help give you further context:

      # New step: Scan sfdx-project.json for "replaceWithFile" entries and check if files exist
      - name: 'Check replaceWithFile existence in sfdx-project.json'
        id: check-replaceWithFile
        run: |
          # Extract "replaceWithFile" values from sfdx-project.json and check if the files exist
          FILES=$(jq -r '.replacements[] | select(.replaceWithFile != null) | .replaceWithFile' sfdx-project.json|sort -u)
          if [[ -n "$FILES" ]]; then
            for file in $FILES; do
              if [[ ! -f "$file" ]]; then
                echo "Error: $file listed in sfdx-project.json does not exist in the branch."
                exit 1
              fi
            done
            echo "Existing files: $FILES"
          fi
        shell: bash

@docbill
Copy link
Author

docbill commented Oct 3, 2024

Here is another sample of a replacement that does not get performed when running sfp during the quickdeploy stage:

    {
      "glob": "src/transactionlog-subscriber/**/*.platformEventSubscriberConfig-meta.xml",
      "regexToReplace": "<user>[A-Za-z0-9]+User</user>",
      "replaceWithEnv": "UNSET_ENV_VARIABLE",
      "allowUnsetEnvVariable": true
    }

(This particular rule was last replacement in the list. It acts as a fall through, when none of the other replacements applied.)

@docbill
Copy link
Author

docbill commented Oct 3, 2024

We do have a workaround. Which is to list the relevent files in the ignores files and then explitly deploy them from a script. e.g.

"postDeploymentScript": "scripts/deploy/subscriber-configs-post.sh",

#!/bin/bash

echo "=== Called $0 $* ==="
trap 'echo "=== Exit($?) $0 $* ==="' EXIT

set -e

files=$(egrep -rl '<user>([A-Za-z0-9]+)User</user>' "${5:-src}" |sed -n -e 's,^\(.*[.]platformEventSubscriberConfig-meta[.]xml\),-d \1,p')

[ -n "$files" ] || ( echo "No files found. Nothing to do."; exit 1 )

sf project deploy start -o "$3" --ignore-conflicts $files 

It is ugly, but it works.

@azlam-abdulsalam
Copy link

Thanks for the detailed write up @docbill. We will look into it

@azlam-abdulsalam azlam-abdulsalam added enhancement New feature or request and removed analysis labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants