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

feat: env-replace workspace #2251

Merged
merged 2 commits into from
Mar 21, 2024
Merged

feat: env-replace workspace #2251

merged 2 commits into from
Mar 21, 2024

Conversation

chrismclarke
Copy link
Member

@chrismclarke chrismclarke commented Mar 20, 2024

PR Checklist

  • PR title descriptive (can be used in release notes)

Description

  • Create new env-replace workspace used to manage utility methods for future template file replacement
  • Add core replaceFiles method used to rewrite .template files using global environment variables
  • Add basic testing suite and tests

Dev Notes

Whilst drafting a PR to populate android and ios template files I realised the code was quickly becoming unmanageable as there are various combinations of files to convert at different times with variables read from multiple places (e.g. Android config has about 5 file replacements but some need to leave templated strings in whilst others need to replace).

To reduce complexity I've moved the core replacement utility into its own workspace, and will make a follow-up pr to call specific methods from it as required.

The utility is designed to support various folder and filename search and exclusion patterns, as well as variable names to include/exclude. See full list of configuration variables included and test cases for more details.

Rough next steps would be

  • Update deployment config to provide core variables for use in local development (e.g. APP_ID is currently is only populated using github actions, but to run scripts locally would ideally want the id as part of the deployment android config)
  • Replace all hardcoded config files with templates for android, ios, capacitor and firebase configs
  • Add workflows to run selective template replacements as required. E.g. yarn workflow android setup could be used to update all android config files and replace variables such as the appId and versionCode from templates. It could also trigger related workflows such as processing assets.
  • Update github actions to call workflows as required when preparing CI builds

Review Notes

Test suite can be run via

yarn workspace @idemsInternational/env-replace test

Git Issues

Closes #

Screenshots/Videos

If useful, provide screenshot or capture to highlight main changes

@github-actions github-actions bot added the feature Work on app features/modules label Mar 20, 2024
@github-actions github-actions bot added feature Work on app features/modules and removed feature Work on app features/modules labels Mar 20, 2024
@github-actions github-actions bot added feature Work on app features/modules and removed feature Work on app features/modules labels Mar 21, 2024
@chrismclarke chrismclarke changed the title feat: add env-replace workspace, methods and tests feat: env-replace workspace Mar 21, 2024
@github-actions github-actions bot added feature Work on app features/modules and removed feature Work on app features/modules labels Mar 21, 2024
Copy link
Collaborator

@jfmcquade jfmcquade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice, and good to have as a standalone package.

From the proposed next steps:

Add workflows to run selective template replacements as required. E.g. yarn workflow android setup could be used to update all android config files and replace variables such as the appId and versionCode from templates. It could also trigger related workflows such as processing assets.

I like this idea, I think it would make a lot of sense to include multiple workflows such as generating the native icon/splash assets in a command like that, I will keep in mind when working on #2241.
I suppose it might be more user friendly to use a syntax like yarn workflow setup_native --android --ios, where the flags are optional (and default is both). But as we already have the android workflow namespace it's probably not worth refactoring, we can add an equivalent ios one.

const outputPath = resolve(cwd, outputName);
writeFileSync(outputPath, replaceContent);
}
return this.summary;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be nice to log the paths of the output files here (the keys of this.summary) to see what's been generated? Although these files won't necessarily have changed, so perhaps git diffs are a better place to view changes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had previously included a table log, although was concerned whether github actions would still be able to correctly mask any variables populated from secrets if logging after the various manipulations. No harm including as an optional config param to test later however, I'll include the update with next pr (screenshot below for reference)

image

@chrismclarke chrismclarke merged commit af50a8e into master Mar 21, 2024
7 checks passed
@chrismclarke chrismclarke deleted the feat/env-replace-workspace branch March 21, 2024 18:27
@github-actions github-actions bot added feature Work on app features/modules and removed feature Work on app features/modules labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on app features/modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants