Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a folder in github workflow?

I'm trying to copy contents of a folder into another one during a github workflow. I know the workflow can create new folders and files because calling build on a react project creates the build that isn't present in the project, but it throws an error in a subsequent run command that uses mkdir.

Error: mkdir: cannot create directory ‘myNewFolder’: No such file or directory

My question is how to achieve either

> mkdir myNewFolder && cp -R myOldFolder myNewFolder

OR

> cp -R myOldFolder myNewFolder

to work when myNewFolder doesn't exist in the repo/workflow working directory?

EDIT (requested workflow file)

name: Test Server Build and Deploy (CD)

on:
  push:
    branches:
        - cd_branch

jobs:
  deploy:
    runs-on: ubuntu-latest
    env: 
        MY_APP_ENV_VARIABLE:  ${{ secrets.ENV_VARIABLE}}

steps:
        - uses: actions/checkout@v2
        - uses: actions/setup-node@v2
          with:
              node-version: '14.15.4'
        - run: npm cache clean --force
        - run: npm run copy-script

Where my copy-script is:

mkdir existingFolder/newFolder1/newFolder2 && \
    cp -R oldfolder/sub existingFolder/newFolder1/newFolder2
like image 479
Mr.Drew Avatar asked May 20 '26 23:05

Mr.Drew


1 Answers

When creating a new folder nested within another, add -p (parants) option after mkdir to tell Linux to make all directories listed in the path.

I tried with this and it works for me:

name: SO-023 Create folder

on:
  push:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Create folder
        run: |
          mkdir -p myNewFolder/myNewSubFolder && cp -R dist myNewFolder/myNewSubFolder
          ls myNewFolder/MyNewSubFolder
          
like image 144
Krzysztof Madej Avatar answered May 22 '26 13:05

Krzysztof Madej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!