alexander-trishin / replace-token

Action for replacing tokens in files.
https://github.com/features/actions
MIT License
1 stars 0 forks source link

Replace Token v1

Run Tests Check dist/ CodeQL Coverage

This action replaces tokens in files with variable values.

The first version was intended for use mainly in internal projects. But there are plans to expand the functionality.

What's new

Please refer to the release page for the latest release notes.

Usage

- uses: alexander-trishin/replace-token@v1
  with:
    # A multiline list of files to replace tokens in.
    #
    # Each line supports glob pattern.
    # [Learn more about glob patterns](https://github.com/actions/toolkit/tree/main/packages/glob#patterns)
    #
    # Required.
    target:

    # The encoding to read and write all files.
    #
    # Accepted values:
    #   - auto: detect encoding using chardet
    #   - ascii
    #   - utf-8
    #   - utf-16le
    #
    # Optional. Default: "auto"
    encoding:

    # Indicates whether to follow symbolic links while searching for target file(s).
    #
    # Optional. Default: true
    follow-symbolic-links:

    # The token prefix for using custom token pattern.
    #
    # Optional: Default: "${{"
    token-prefix:

    # The token suffix for using custom token pattern.
    #
    # Optional. Default: "}}"
    token-suffix:

    # A YAML formatted multiline string containing variable values (keys are case-insensitive).
    #
    # May override values from `variables-json` and `variables-secret-json` if keys match.
    #
    # Example: >
    #   - VARIABLE0: VALUE0
    #   - VARIABLE1: ${{ vars.VALUE1 }}
    #
    # Optional. Default: ""
    variables:

    # A JSON formatted multiline string containing additional variable values (keys are case-insensitive).
    #
    # Values may be overwritten by `variables-secret-json` and `variables' if keys match.
    #
    # Optional. Default: ""
    variables-json:

    # A JSON formatted multiline string containing additional variable values (keys are case-insensitive, all values are masked).
    #
    # Values may override `variables-json` and be overwritten by `variables' if keys match.
    #
    # Optional. Default: ""
    variables-secret-json:

Scenarios

Single file

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./templates/example.txt
    variables: >
      - TOKEN: value

Single file with a specific encoding

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./templates/example.txt
    encoding: utf-8
    variables: >
      - TOKEN: value

Multiple files

- uses: alexander-trishin/replace-token@v1
  with:
    target: |
      ./templates/example-0.txt 
      ./templates/example-1.txt
    variables: >
      - TOKEN: value

Multiple files (glob)

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./templates/*
    variables: >
      - TOKEN: value

Multiple files (ignore symlinks)

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./templates/examples/*.txt
    follow-symbolic-links: false
    variables: >
      - TOKEN: value

With custom token pattern

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./example.txt
    token-prefix: "#"
    token-suffix: "%"
    variables: >
      - TOKEN: value

With vars context

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./example.txt
    variables-json: ${{ toJson(vars) }}

With secrets context

- uses: alexander-trishin/replace-token@v1
  with:
    target: ./example.txt
    variables-secret-json: ${{ toJson(secrets) }}

License

The scripts and documentation in this project are released under the MIT License