GItHub Actions sed usage

Hello

I am trying to edit my appspec.yml file destination using sed in Github actions.
but it doesn’t seem to work.
Can anyone here let me know how can I use sed to edit the appspec.yml file in the root of my repo in Actions?

Thanks

In principle sed should work just like locally. To get help, you’ll have to share a bit more details:

  • What exactly are you doing? Best share the workflow file or relevant excerpt.
  • What do you expect to happen?
  • What happens instead?

@airtower-luna I am trying to deploy my app using code deploy which uses appspec.yml where destination location is defined.
So I have 2 branches i-e dev and master deploying to the same EC2 instance but a different location/ directory (obviously).
So I am trying that If someone deploys to the dev branch so Actions of GitHub stars and changes destination in appspec.yml file (which is in the root directory) from prod to dev and app will deploy there.

WORKFLOW.YML


name: Node.js CI
on:
  push:
    branches: [ dev ]
jobs:
  my-job:
    name: My Job
    runs-on: ubuntu-latest
    steps:
    - name: Appspec
      run: |
        sed -i -e "s|prod-dir|dev-dir|g" appspec.yml

APPSPEC.YML

version: 0.0
os: linux
files:
  - source: /
    destination: /home/prod-dir/public_html
    overwrite: true
hooks:
  BeforeInstall:
    - location: scripts/codedeploy/before-install.sh
      timeout: 300
  AfterInstall:
    - location: scripts/codedeploy/after-install.sh
      timeout: 300

and above workflow give me error appspec.yml not found

The job doesn’t retrieve the repository before trying to work with the appspec.yml file. You need to use actions/checkout first. In most cases the defaults just work:

    steps:
      - uses: actions/checkout@v2
      - # other steps go here
1 Like

@airtower-luna can you share me workflow file to use in my project?

name: My Workflow
on:
  push:
    branches: [ dev ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2 
      - run:  sed -i -e "s|dir-prod|dir-dev|g" appspec.yml

I tried above this run but still change didnt worked :confused:

That should work in principle, assuming the appspec.yml file exists on the dev branch. If it doesn’t can you share a link to a workflow run?

I don’t see any error there, sed seems to be able to access the file now.

@airtower-luna but it’s not doing what it is supposed to do :confused:
any other way around so I don’t have to change destination every time I merge my code to master from dev?

Ok so I checked and actions are doing exactly as it is supposed to be, but the issue is that AWS CodePipeline revert those changes by github commit :confused:

That sounds like the problem with sed is solved, and you’re now hitting a different problem. It’s best to create a separate thread for that. Make sure to include all relevant details to maximize the chance that someone will have an idea!

1 Like

I don’t see a commit or push. Where do you expect these changes to be seen and why?