6
name: deploy-me
on: [push]
jobs:
  deploys-me:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - run: npm install
      - run: npm run dev

     //Next  I want to copy some file from this repo and commit to a different repo and push it

This is my workflow.yaml file,

After npm run dev, I want to be able to copy a file to another directory, commit and push to that another repo

Ali
  • 289
  • 4
  • 10
  • You'll need some sort of "copy file" command, probably another "git clone" to make a repository into which you do this copying, a "git add" after you do the copying, a "git commit", and a "git push". Try writing the appropriate commands. If you then have specific questions about specific problems, *then* consider asking here on StackOverflow. As it is you've posted a question of the form "do my job for me". – torek Dec 04 '21 at 23:01
  • Hi, thanks for answering :) You are right i may not have been specific, I sort of thought of that copying and cloning again , but didnt knew if it was possible , i will try it, if possible please send link to resources where someone used git commands within workflow – Ali Dec 05 '21 at 08:09

1 Answers1

4
name: deploy-me
'on':
    - push
jobs:
    deploy-me:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v2
            - uses: actions/setup-node@v2
              with:
                  node-version: '14'
              env:
                  ACCESS_TOKEN: '${{ secrets.ACCESS_TOKEN }}'
            - run: npm install
            - run: npm run build
            - run: |
                  cd lib
                  git config --global user.email "hi@aliasifkhan.com"
                  git config --global user.name "aliasifk"
                  git config --global credential.helper cache
                  git clone https://${{secrets.ACCESS_TOKEN}}@github.com/aliasifk/xxxxxx
                  cp index.js clonedFolder/ -f
                  cd clonedFolder
                  git add .
                  git commit -m "$(date)"
                  git push

This is how I fixed my problem,

  1. I created a Personal Access Token from my developer settings and copied it for later step.

  2. I added ACCESS_TOKEN environment variable by navigating to my repository settings and adding a secret. Here I pasted the previously created access token.

  3. Then simply that code and using secrets context to access that token, note that name is similar to the one we created before

In left menu of repo settings

  1. Now just push the code to repo and everything will work like charm :).

Happy Hacking!

Ali
  • 289
  • 4
  • 10