Skip to content

Replace Action-Z

Actions
Replaces substrings in files. Useful to enrich configs with previous steps artifacts
V2.0.16
Latest
Star (0)

replace-action

This lightweight action replaces substrings in files. It is useful for CI process when you needto update your configs depending on the previous steps results.

Usage

See action.yml

uses: datamonsters/replace-action
with:
  files: 'path1/file1,path2/file2'
  replacements: 'foo=bar,$FOO=Bar_Value'

Example

Consider you need to apply k8s deployment with container you've built on the previous step of you workflow. You have a app-deployment.yaml file like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: default
  name: simple-app
spec:
  selector:
    matchLabels:
      simple-app: ""
  template:
    metadata:
      labels:
        simple-app: ""
    spec:
      containers:
      - name: simple-app
        image: $IMAGE
        env:
        - name: HELLO_MSG
          value: stranger

Your workflow in this case will be like this:

name: Deploy app
on: [push]
jobs:
  deploy:
  runs-on: ubuntu-latest
    steps:

      - name: Build and push docker
        id: build_step
        run: |
          docker build . -t ${{ secrets.AWS_ACC_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/demo:${{ github.sha }}
          docker push ${{ secrets.AWS_ACC_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/demo:${{ github.sha }}

      - name: Replace image in config
      uses: ./.github/actions/replace
      with:
        files: app-deployment.yaml
        replacements: '$IMAGE=${{ secrets.AWS_ACC_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/demo:${{ github.sha }}'
    
    - name: Apply centraldashboard config
      uses: steebchen/kubectl@master
      env:
        KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
        KUBECTL_VERSION: "1.14"
      with:
        args: apply -f app-deployment.yaml

License

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

This is a fork from https://github.com/datamonsters/replace-action. I created this action becasue the the old repository doesn't get updated for 3 years.

Update Version

$ npm install @actions/core $ npm install @actions/github $ ncc build index.js --license licenses.txt $ npm i --package-lock-only

Replace Action-Z is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Replaces substrings in files. Useful to enrich configs with previous steps artifacts
V2.0.16
Latest

Replace Action-Z is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.