WBoe
WBoe

Reputation: 46

Problem with deploying react app using GitHub actions

I am trying to build a GitHub workflow that deploys my react website and PHP backend to a server (using FTP). The FTP part works.

The problem that i am now facing is, that i need to automatically but my builded react frontend into the file structure with my backend.

Locally i am using Windows and in my project.json i move the builded frontend by using :

"build-webapp:win":  "react-scripts build && RMDIR /S /Q webapp\\html\\static && move build\\static webapp\\html",

That also works.

Since the GitHub workflow is running on ubuntu-latest i implemented the equivalent

"build-webapp:ci":  "react-scripts build && rm -rf /webapp/html/static && mv /build/static /webapp/html"

When i run this on GitHub actions it gives me the following error :

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build-webapp:ci: `react-scripts build  && rm -rf webapp/html/static && mv build/static webapp/html`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] build-webapp:ci script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2021-11-05T12_18_53_579Z-debug.log
Error: Process completed with exit code 1.

I also get the same error when i use the windows command on "windows-latest" in GitHub actions.

The complete Workflow looks like that :

name: Deploy to development
on:
  push:
    branches:
      - devel
jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Build, Test and Deploy
    steps:
      - name: Checkout 
        uses: actions/checkout@v2
        with:
          persist-credentials: false
      - name: Install
        run: npm install
      - name: Build Webapp
        run:  npm run build-webapp:ci
      - name: List /build
        run: ls ./build
      - name: List /webapp
        run: ls ./webapp
      - name: Deploy webapp
        uses: milanmk/actions-file-deployer@master
        with:
          remote-protocol: "sftp"
          remote-host:  ${{ secrets.FTP_SERVER }}
          remote-user: ${{ secrets.FTP_USER }}
          remote-password:  ${{ secrets.FTP_PASSWORD }}
          remote-path: "/development"
          sync: "full"
          local-path: "webapp/"

I am pretty new to the GitHub actions topic, so i hope someone can help me with that.

Thanks

Upvotes: 0

Views: 887

Answers (1)

WBoe
WBoe

Reputation: 46

Okay i solved it by myself, maybe this is helpful for others :

The problem wasn't the rm and mv but that npm warning will be treated as errors here. to disable that add CI=false to the command :

"build-webapp:ci": "CI=false && react-scripts build && rm -rf webapp/html/static && mv build/static webapp/html"

Upvotes: 1

Related Questions