I’m trying to break one job that I have in my workflow into two in Github Actions but can’t seem to do so without breaking. I’d like to have build and deploy as two separate jobs if that is possible, so breaking out ‘build_and_deploy’ and into two jobs i.e like a job1 and job2. Thank you. My code is as follows:
name: Deploy to Firebase Hosting on merge to Develop
'on':
push:
branches:
- develop
jobs:
build_and_deploy:
name: build_and_deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '15'
- run: npm ci
- name: create env file
env:
REACT_APP_API_KEY: ${{ secrets.REACT_APP_API_KEY }}
REACT_APP_FIREBASE_API_KEY: ${{ secrets.REACT_APP_FIREBASE_API_KEY }}
REACT_APP_FIREBASE_AUTHDOMAIN: ${{ secrets.REACT_APP_FIREBASE_AUTHDOMAIN }}
REACT_APP_FIREBASE_PROJECTID: ${{ secrets.REACT_APP_FIREBASE_PROJECTID }}
REACT_APP_FIREBASE_STORAGEBUCKET: ${{ secrets.REACT_APP_FIREBASE_STORAGEBUCKET }}
REACT_APP_FIREBASE_MESSAGINGSENDERID: ${{ secrets.REACT_APP_FIREBASE_MESSAGINGSENDERID }}
REACT_APP_FIREBASE_APPID: ${{ secrets.REACT_APP_FIREBASE_APPID }}
run: |
touch .env
echo REACT_APP_API_KEY="$REACT_APP_API_KEY" >> .env
echo FAST_REFRESH=false >> .env
echo REACT_APP_FIREBASE_API_KEY="$REACT_APP_FIREBASE_API_KEY" >> .env
echo REACT_APP_FIREBASE_AUTHDOMAIN="$REACT_APP_FIREBASE_AUTHDOMAIN" >> .env
echo REACT_APP_FIREBASE_PROJECTID="$REACT_APP_FIREBASE_PROJECTID" >> .env
echo REACT_APP_FIREBASE_STORAGEBUCKET="$REACT_APP_FIREBASE_STORAGEBUCKET" >> .env
echo REACT_APP_FIREBASE_MESSAGINGSENDERID="$REACT_APP_FIREBASE_MESSAGINGSENDERID" >> .env
echo REACT_APP_FIREBASE_APPID="$REACT_APP_FIREBASE_APPID" >> .env
- run: npm run build
- name: GitHub Action for Firebase
uses: w9jds/[email protected]
with:
args: deploy --only hosting
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
run_tests:
name: Run autotests
needs: build_and_deploy
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Test Run
run: |
curl -X POST https://api.github.com/repos/*****/FootballAppE2ETests/dispatches
-H 'Accept: application/vnd.github.everest-preview+json'
-u ${{ secrets.ACTIONS_KEY }}
--data '{"event_type": "Trigger Workflow", "client_payload": { "repository": "'"$GITHUB_REPOSITORY"'" }}'
- uses: actions/checkout@v3
2
Answers
Answer
I hope you have valid reasons to break your job into multiple ones. Sometimes it’s better to run your actions in one job so you don’t need to wait for another runner once you finish your job, so your current implementation is fine, you can only improve it by caching npm dependencies.
However, if you still want to, you can follow the example in w9jds/firebase-action repository, by using actions/upload-artifact to share your build (
dist
) folder between thebuild
anddeployment
jobs:Other improvements you may want to consider:
actions/setup-node@v3
actions/checkout@v3