Last active
October 13, 2023 12:58
-
-
Save ZachJDev/b8d0e697335e935fe22a554af9fa393f to your computer and use it in GitHub Desktop.
Example GH action to deploy only changed functions to Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: example action | |
on: | |
push: | |
branches: [ dev ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
deploy-functions: | |
name: deploy functions | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: "2" # must be 2 to grab previous level | |
## Following step checks all directories in functions/ for any changed files -- i.e. any updated functions. | |
- name: get changed functions | |
id: changed-functions | |
uses: tj-actions/[email protected] | |
with: | |
files: | | |
functions/*/ | |
## Use node and NPM install here ## | |
## Set firebase function env variables.## | |
# 1. The "...all_changed_files" file contains a space-separated list of changed files (with absolute paths) | |
# 2. Use sed to grab the folder name, e.g. 'funcAdd' in functions/funcAdd/index.js | |
# 3. sed again to wrap that in the appropriate syntax for firebase deploys, e.g. functions:funcAdd,functions:funcSub, | |
- name: build deploy string | |
run: | | |
echo "CHANGED_OUTPUT=$(echo "${{steps.changed-functions.outputs.all_changed_files}}" | sed 's/functions\/\([[:alpha:]]\+\)\/index.js/\1/g' | sed 's/\([[:alpha:]]\+\)[[:space:]]\?/functions:\1,/g')" >> $GITHUB_ENV | |
# Prints the final deploy string, for debugging | |
- name: print deploy string | |
run: | | |
echo $CHANGED_OUTPUT | |
# passes the constructed string to the deploy argument. Will not deploy any functions if none have changed. | |
- name: deploy functions | |
uses: w9jds/firebase-action@master | |
if: steps.changed-functions.outputs.any_changed == 'true' | |
with: | |
args: deploy --only ${{env.CHANGED_OUTPUT}} | |
# etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment