To deploy your React project to Firebase automatically, you can use GitHub actions:
Go to github.com > Your repository > Actions > Set up a workflow yourself
At this point, you'll be able to edit the main.yml
file:
yml# This is a basic workflow to deploy functions to Firebase name: deployToFirebase # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: push: branches: [ master ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v2 - uses: actions/setup-node@v2.1.2 with: node-version: '12' # Install npm - name: Installing npm run: npm install && cd functions && npm install # Build the project - name: Build project run: npm run build # Firebase deploy - name: Firebase deploy run: npm install -g firebase-tools && firebase deploy --token ${{ secrets.FIREBASE_TOKEN }}
We'll use a token instead of login in the console using name and password. You can get the token typing in your Terminal locally:
terminalfirebase login:ci
Create a new field called FIREBASE_TOKEN
in:
Settings > Secrets > New repository secret
Paste the token.
That's it. As you can see, on a new push in the master branch, GitHub will perform the same actions as we would do manually on the Terminal.
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.