{"id":15038522,"url":"https://github.com/lucianopalmeida/variable-injector","last_synced_at":"2025-04-09T23:41:10.959Z","repository":{"id":34759651,"uuid":"156038010","full_name":"LucianoPAlmeida/variable-injector","owner":"LucianoPAlmeida","description":"Continuous Integration Tool for Swift Projects","archived":false,"fork":false,"pushed_at":"2024-03-02T14:50:28.000Z","size":91,"stargazers_count":99,"open_issues_count":2,"forks_count":21,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-25T02:42:17.995Z","etag":null,"topics":["ci-pipeline","codegen","continuous-delivery","continuous-integration","devops","environment","environment-variables","ios","macos","pipelines","substitutions","swift","swift-language","swift-package-manager","values-injected","workflow","xcode11"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LucianoPAlmeida.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-04T01:10:46.000Z","updated_at":"2024-07-18T03:58:43.743Z","dependencies_parsed_at":"2024-07-18T04:08:44.568Z","dependency_job_id":null,"html_url":"https://github.com/LucianoPAlmeida/variable-injector","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucianoPAlmeida%2Fvariable-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucianoPAlmeida%2Fvariable-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucianoPAlmeida%2Fvariable-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LucianoPAlmeida%2Fvariable-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LucianoPAlmeida","download_url":"https://codeload.github.com/LucianoPAlmeida/variable-injector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131467,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci-pipeline","codegen","continuous-delivery","continuous-integration","devops","environment","environment-variables","ios","macos","pipelines","substitutions","swift","swift-language","swift-package-manager","values-injected","workflow","xcode11"],"created_at":"2024-09-24T20:38:45.662Z","updated_at":"2025-04-09T23:41:10.938Z","avatar_url":"https://github.com/LucianoPAlmeida.png","language":"Swift","readme":"[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n\n# :warning: Deprecated :warning:\n\nThis tool is deprecated and will no longer be updated by the maintainer. \n\n\n# Swift Variable Injector\n\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/LucianoPAlmeida/variable-injector/workflows/CI/badge.svg?branch=master)](https://github.com/LucianoPAlmeida/variable-injector/actions)\n[![Swift](https://img.shields.io/badge/Swift-5.9-orange.svg)](https://swift.org)\n[![Xcode](https://img.shields.io/badge/Xcode-15.0-blue.svg)](https://developer.apple.com/xcode)\n[![SPM](https://img.shields.io/badge/SPM-orange.svg)](https://swift.org/package-manager/)\n\nVariable injector is a very simple project with the goal of inject CI pipelines environment variables values into **Swift** code static values before compilation and Continuous deployment to a specific environment(Development, Testing or Production) where we can define the values injected for each build and deployment e.g. an API URL that the App uses and is different for each environment. Also, it allows us to not expose our production keys and values in statically in our code.\n\nThe project uses [SwiftSyntax](https://github.com/apple/swift-syntax) to perform a reliable substitutions of static literal strings with the CI environment variables values.\n\n## Installation\n\n### Manual Installation\n\nJust clone the repo and run `make install`\n\nWith that installed and on our `bin` folder, now we can use it.\n\n## Usage\n\nFor a detailed example of using this, check out the article [Continuous Integration Environment Variables in iOS projects using Swift](https://medium.com/@lucianoalmeida1/continuous-integration-environment-variables-in-ios-projects-using-swift-f72e50176a91) on [Medium](https://medium.com).\n\n**Note**\nIf you having issues with XCode 11 use the version 0.3.3 of the tool.\n\nYou should have a `class` or `struct` with your environment variables declaration following the $(VAR_NAME) pattern.\nExample:\n\n```swift\n   struct CI {\n      static var serviceAPIKey: String = \"$(SERVICE_PROD_KEY)\"\n      static var otherAPIKey: String = \"$(OTHER_PROD_KEY)\"\n   }\n```\n\nWith the environments static declarations matching the pattern\n\n```sh\nvariable-injector --file ${SRCROOT}/Environment/CI.swift\n\n```\n\nIf environment variables with those names, as in the example you have the `SERVICE_PROD_KEY` and `OTHER_PROD_KEY` are defined on the build machine for this pipeline the injector you replace the string literal with the environment variable value.\n\nExample of the file after the substitution.\n\n```swift\n   struct CI {\n      static var serviceAPIKey: String = \"h344hjk2h4j3h24jk32h43j2k4h32jk4hkj324h\"\n      static var otherAPIKey: String = \"dsa76d7adas7d6as87d6as78d6aklre423s7d6as8d7s6\"\n   }\n```\n\n### Using as Run Script in Build Phases\n\nYou can add the script call for variable replacement on your build phases. We just have setup our Development keys in our local machine as environment variables and build the project.\n\n**Important:** Is very important to add this Run Script phase before the Compile Sources phase. So the variables will be replaced and then compiled :))\n\n```sh\nif which variable-injector \u003e/dev/null; then\n  variable-injector --file ${SRCROOT}/YourProject/YourGroupFolderPath/File.swift --verbose # Pass your parameters\nelse\n  echo \"Warning: Swift Variable Injector not installed, download from https://github.com/LucianoPAlmeida/variable-injector\"\nfi\n```\n\n### Options\n\nWe can ignore patterns that match $(ENV_VAR) to avoid the replace.\n\n```sh\nvariable-injector --file ${SRCROOT}/Environment/CI.swift --ignore OTHER_PROD_KEY\n\n```\n\nAnd also, to see the logs of variables, values and source output you can use `--verbose`\n\n**IMPORTANT**\nThe verbose mode you print the values of your environment variables on the logs. So you may be careful and use it only for debug proposes.\n\n```sh\nvariable-injector --file ${SRCROOT}/Environment/CI.swift --verbose\n\n```\n\nAfter that we can just proceed to the build, archive and other steps of our CI/CD pipeline.\n\n## Licence\n\nVariable Injector is released under the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucianopalmeida%2Fvariable-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucianopalmeida%2Fvariable-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucianopalmeida%2Fvariable-injector/lists"}