Skip to content

Commit

Permalink
Merge pull request #16 from lowply/remove-branch-restriction
Browse files Browse the repository at this point in the history
Remove branch restriction
  • Loading branch information
lowply authored Jul 8, 2021
2 parents 9aa934b + ac25115 commit 2d5ea96
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
49 changes: 33 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
# Deploy to Firebase

A GitHub Action to deploy to Firebase Hosting
A GitHub Action to deploy to Firebase Hosting.

- You can choose a specific branch to allow deployment by using the `TARGET_BRANCH` env var (`master` if not specified).
- Make sure you have the `firebase.json` file in the repository
- Get the Firebase token by running `firebase login:ci` and [store it](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) as the `FIREBASE_TOKEN` secret
- Set the project name in the `FIREBASE_PROJECT` env var
- Make sure that you checkout the repository using the [actions/checkout](https://github.com/actions/checkout) action
- Make sure that you have the `firebase.json` file in the repository
- To obtain the Firebase token, run `firebase login:ci` on your local computer and [store the token](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository) as the `FIREBASE_TOKEN` secret
- Specify the Firebase project name in the `FIREBASE_PROJECT` env var

Example workflow
## Workflow examples

Deploy the `main` branch when a commit is pushed to it:

```
name: Build and Deploy
name: Deploy the main branch
on:
push:
branches:
- main
- main
jobs:
main:
name: Deploy to Firebase
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: lowply/deploy-firebase@v0.0.5
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
FIREBASE_PROJECT: name-of-the-project
```

Deploy only when a tag starts with `v` is pushed:

```
name: Deploy a tag
on:
push:
tags:
- v*
jobs:
main:
name: Build and Deploy
name: Deploy to Firebase
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
- name: Build Hugo
uses: lowply/build-hugo@v0.68.3
- name: Deploy to Firebase
uses: lowply/deploy-firebase@v0.0.3
- uses: actions/checkout@v2
- uses: lowply/deploy-firebase@v0.0.5
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
FIREBASE_PROJECT: name-of-the-project
TARGET_BRANCH: main
```
14 changes: 2 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

if [ -z "${FIREBASE_TOKEN}" ]; then
echo "FIREBASE_TOKEN is missing"
Expand All @@ -10,17 +10,7 @@ if [ -z "${FIREBASE_PROJECT}" ]; then
exit 1
fi

if [ -z "${TARGET_BRANCH}" ]; then
TARGET_BRANCH="master"
fi

if [ "${GITHUB_REF}" != "refs/heads/${TARGET_BRANCH}" ]; then
echo "Current branch: ${GITHUB_REF}"
echo "Aborting deployment"
exit 1
fi

firebase deploy \
-m "${GITHUB_SHA}" \
-m "${GITHUB_REF} (${GITHUB_SHA})" \
--project ${FIREBASE_PROJECT} \
--only hosting

0 comments on commit 2d5ea96

Please sign in to comment.