Skip to content

mh4647/replace-action-z

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%