Skip to content

phodal/github-action-heroku-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started with Create React App

Deploy

change heroku_api_key & heroku_app_name & heroku_email in your .github/workflows/cd.yml to the root of your project, like:

      - uses: akhileshns/heroku-deploy@v3.12.12 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "afs-react" #Must be unique in Heroku
          heroku_email: "gmszone@qq.com"

Generate Token to HEROKU_API_KEY

with Web

https://dashboard.heroku.com/account/applications/authorizations/new

or with CLI

heroku login
> note: will open the browser to auth
  • generate the Token of the heroku
heroku authorizations:create

will generate:

Creating OAuth Authorization... done
Client:      <none>
ID:          7f750130-8992-47ec-99f5-0c9c66cf68e0
Description: Long-lived user authorization
Scope:       global
Token:       xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Updated at:  Fri Aug 05 2022 10:34:53 GMT+0800 (China Standard Time) (less than a minute ago)

Custom Env variable

  1. config REACT_APP_ENV in package.json under scripts, for example:
  "scripts": {
    "serve": "serve -s build",
    "start": "react-scripts start",
-    "build": "react-scripts build",
+    "build": "REACT_APP_ENV=$NODE_ENV react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }
  1. config by NODE_ENV. Add NODE_ENV in .github/workflows/ci.yaml and .github/workflows/cd.yml, for example:
  build:
    runs-on: ubuntu-latest
+    env:
+      NODE_ENV: production
    steps:
      - uses: actions/checkout@v2
  1. then use in code process.env['REACT_APP_ENV']

About

sample for GitHub Action CI/CD with Heroku deploy with React

Resources

Stars

Watchers

Forks

Packages

No packages published