Skip to content

Enable GitHub developers to parameterize the values in their config files from a GitHub Action workflow

License

Notifications You must be signed in to change notification settings

im-open/variable-substitution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

variable-substitution

This Action is a copy of the deprecated microsoft/variable-substitution which has been updated to run on Node 16.

GitHub Action for substituting variables in parameterized files

With the variable-substitution Action for GitHub, you can apply variable substitution to XML, JSON and YAML based configuration and parameter files.

  • Tokens defined in the target configuration files are updated and then replaced with variable values.
  • Variable substitution is applied for only the JSON keys predefined in the object hierarchy. It does not create new keys.
  • Only variables defined explicitly as Environment variables as part of the workflow or system variables that are already available for workflow context can be used in substitution.
  • Variable substitution takes effect only on the applicationSettings, appSettings, connectionStrings and configSections elements of configuration files. Please refer this for more information.

The definition of this Github Action is in action.yml.

Inputs

Parameter Is Required Description
files true Comma separated list of XML/JSON/YAML files in which tokens are to be substituted. 

Files names must be specified relative to the folder-path.

Outputs

This action does not have outputs.

Usage Example

See Use variable substitution with GitHub Actions for additional examples of how to use variable substitution.

Configuration file before substitution

{
  "IsProduction": false,
  "ClientId": 123456,
  "ConnectionStrings": {
    "MyApp": "Server=localhost;Database=MyDB;Trusted_Connection=True"
  }
}

Workflow that uses the action

on: [pull_request]
name: CI Build

jobs:
  run-integration-tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Update sql connection string in test project
      uses: im-open/[email protected] #v2 or v2.1 can also be used
      with:
        files: './src/MyApp.Tests/appsettings.json'
      env:
        # Substitutions are case sensitive and must match what is present
        # in the file with substitutions (in this case appsettings.json)
        ClientId: 098765
        ConnectionStrings.MyApp: 'Server=localhost;Database=MyDB;Trusted_Connection=False;User ID=SA;Password=Abc123!'

    - name: run integration tests
      run: dotnet test --no-restore --configuration Release

Configuration file after substitution

{
  "IsProduction": false,
  "ClientId": 098765,
  "ConnectionStrings": {
    "MyApp": "Server=localhost;Database=MyDB;Trusted_Connection=False;User ID=SA;Password=Abc123!"
  }
}

Code of Conduct

This project has adopted the im-open's Code of Conduct.

License

Copyright © 2023, Extend Health, LLC. Code released under the MIT license.

About

Enable GitHub developers to parameterize the values in their config files from a GitHub Action workflow

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks