GithubHelp home page GithubHelp logo

cschleiden / replace-tokens Goto Github PK

View Code? Open in Web Editor NEW
56.0 3.0 24.0 419 KB

Simple GitHub Action to replace tokens in files

Home Page: https://github.com/marketplace/actions/replace-tokens

License: MIT License

TypeScript 93.99% JavaScript 6.01%

replace-tokens's Introduction

Replace tokens

Simple GitHub Action to replace tokens in files.

Inputs

  • files - Glob expression, file name or array of glob/file name
  • tokenPrefix - Prefix to use when matching tokens, defaults to #{
  • tokenSuffix - Suffix to use when matching tokens, defaults to }#

Example

If you want to replace #{CDN}# and #{CALLBACK}# in all of your JS files, add the action to your workflow like this:

- uses: cschleiden/replace-tokens@v1
  with:
    files: '["**/*.js"]'
  env:
    CDN: https://somecdn.com/...
    CALLBACK: some_value

If you want to use a different token format, you can specify a custom token prefix/suffix. For example, to replace just tokens like {CDN} you could add:

- uses: cschleiden/replace-tokens@v1
  with:
    tokenPrefix: '{'
    tokenSuffix: '}'
    files: '["**/*.js"]'
  env:
    CDN: https://somecdn.com/...

Acknowledgements

replace-tokens's People

Contributors

cschleiden avatar dependabot[bot] avatar jonas-lomholdt avatar anamarijapapic avatar n3wt0n avatar

Stargazers

Shiro Tian avatar Dylson Valente Neto avatar  avatar Md. Tanjil Bhuiyan avatar Alex Henderson avatar  avatar Fredrik Magnusson avatar Tomislav O avatar Seth Ryder avatar Tăng Thanh tâm avatar Lance Hampton avatar Jordan Frey avatar Bheem avatar Zach Trocinski avatar Jannie Theunissen avatar  avatar Milorad Ranitovic avatar  avatar Josh Johanning avatar  avatar James Griffin avatar Lucas Ruy avatar Joe Fecht avatar Admire Khulumo avatar Quentin Dutot avatar Ryan Laurie avatar Jesus Vidal avatar Diego Aquino avatar Julian Joseph avatar CNine avatar Brian Harwell avatar Sirinat Paphatsirinatthi avatar Rahul avatar Sonja Goerlich avatar Saed SayedAhmed avatar Jorge avatar Philip Gai avatar  avatar  avatar Sam Williams avatar Adam avatar Peterson Zeferino avatar Derek Hartley avatar Adam Banko avatar André Morais avatar Robert Ștefan Stănescu avatar Tom Kerkhove avatar Fabian Wohlschläger avatar Nathan Reynolds avatar Shawn Charles avatar Bogdan Covrig avatar Joseph Garrone avatar Michael Szul avatar Jeremy Udit avatar Matthew Manela avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

replace-tokens's Issues

GitHub Actions is not replacing the token in file

Hey, I'm newbie at GitHub Actions. When I push the changes, GitHub actions is started where I am using the cschleiden/replace-tokens to replace the image tag in deployment.yaml. The build was success but not updating the changes in K8s manifest file.

image

My repo is connected with ArgoCD. when i push the changes, it automatically detect the changes and deploy the app and what i am getting error on ArgoCD Ui:
image

In Detail:
image

Repository:

https://github.com/1DevOps2/docker-gs-ping

ci.yml

name: Go Docker Image CI

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      DOCKER_REPOSITORY: ${{ secrets.DOCKER_USERNAME }} # name of Docker Hub ID
      IMAGE_NAME: docker-gs-ping
      IMAGE_TAG: ${{ github.run_number }} # $GITHUB_RUN_NUMBER

    steps:
    - uses: actions/checkout@v2
    
    - name: Log in to Docker Hub
      uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}
      
    - name: Build the Docker image
      run: docker build . --file Dockerfile --tag $DOCKER_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG

    - name: Docker Push
      run: docker push $DOCKER_REPOSITORY/$IMAGE_NAME:$IMAGE_TAG
      
    - name: Replace tokens
      uses: cschleiden/[email protected]
      with:
        files: '["*.yaml"]'
        tokenPrefix: '__' # optional, default is #{
        tokenSuffix: '__' # optional, default is }#
      env:
        DOCKER_REPOSITORY: ${{ env.DOCKER_REPOSITORY }}
        IMAGE_NAME: ${{ env.IMAGE_NAME }}
        IMAGE_TAG: ${{ env.IMAGE_TAG }}

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: go-app
spec:
  selector:
    matchLabels:
      app: go
  replicas: 1
  template:
    metadata:
      labels:
        app: go
    spec:
      containers:
      - name: go-app
        image: __DOCKER_REPOSITORY__/__IMAGE_NAME__:__IMAGE_TAG__
        ports:
        - containerPort: 8082

Support of replacing arrays

I'm having a terrible time finding a replace token on github that supports arrays. I can easily replace Blah.Account, but all the others cant be replaced as they are in an array. Does this currently support array replacement or do you have some idea/willingness to get it added into this extension? Thank you!

{
"Blah": {
"Account": 173,
"Events": [ 239, 281, 292 ]
},
"Cors": {
"AllowOrigins": [
"http://blah",
"http://blah",
"http://blah"
]
}
}

Become a verified creator

We use this action in our org for plenty of things, unfortunately due to certain restrictions we need to allow-list it because it's not published as a verified creator. That means for each version change we would need to go through a new approval process.

I couldn't find allot of documentation around becoming verified creator, maybe someone knows if this is feasible?

Thanks!

Retrieve values from GitHub Variables or Secrets

With the addition of GitHub Variables and the already existing secrets. Is there any limitation to accessing the API and retrieving the values for these parameters automatically without defining the parameters that need replaced? Similar to how the replace tokens extension works with variable groups in ADO?

Thanks!

Is it time for a new tag?

Hello guys,

I could see that you have upgraded to Node v16 yesterday and was thinking whether this is a good candidate for a tag bump up.

Secrets

Is there a syntax to replace a token from a secret instead of environment variable?

set-output deprecation warning

Any plan to update this action?

The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Removing content when not replace

Hello,

When I use this action on a file that has the same pattern in a parameter that I don't want to replace - and therefore not sending it, the task will replace it with empty string.

for example:

File a.txt:

a=#{param}#
b=#{nana}#

task:

      - name: Replace tokens
        uses: cschleiden/[email protected]
        with:
          files: '["a.txt"]'
        env:
          param: lala

at the end the file will be:

a=lala
b=

but I would like it to be:

a=lala
b=#{nana}#

I think it should replace the parameter only if I gave it.

Odd behavior on a windows agent

My workflow contains a stage that uses replace-tokens to pre-render a nuget.config file.

- uses: cschleiden/replace-tokens@v1
      name: replace-tokens nuget.config
      with:
        files: '["${{ github.workspace }}/.github/tools/nuget.config"]'
      env:
        NUGET_FEED: "${{ secrets.NUGET_FEED }}"
        NUGET_USERNAME: "${{ secrets.NUGET_USERNAME }}"
        NUGET_PASSWORD: "${{ secrets.NUGET_PASSWORD }}"

Interestingly, it works fine on ubuntu and macos, however it does not seem to behave the same way on windows
https://github.com/cloud-tek/ion/runs/2470314125?check_suite_focus=true giving me the following error message:

 Unexpected token a in JSON at position 5

The workflow is a matrix build across 3 different OSes so the build is the same.

Any thoughts?

Workflow fails after upgrade to node20

After updating to node20 using this workflow fails in "not updated runners". For those runners I have no possibility to update them myself, but every workflow fails with:

Download action repository 'synchronized-actions/cschleiden-replace-tokens@v1' (SHA:4d5a042c84c3568b3858b7af9394923d2d5195c9)
Error: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter ''using: node20' is not supported, use 'docker', 'node12' or 'node16' instead.')
at GitHub.Runner.Worker.ActionManifestManager.ConvertRuns(IExecutionContext executionContext, TemplateContext templateContext, TemplateToken inputsToken, String fileRelativePath, MappingToken outputs)
at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile)
Error: Fail to load synchronized-actions/cschleiden-replace-tokens/v1/action.yml

This change to node20 should be a major release (v2) as it's a breaking change.

The same thing has happened to multiple other github actions, for example google-github-actions/auth#347

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.