Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds capability for specifying firebase-tools version #246

Merged
merged 7 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/deploy-preview-with-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Deploy Preview with version

on: pull_request

jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Deploy to Firebase Hosting preview channel
id: firebase_hosting_preview
uses: ./
with:
repoToken: "${{ secrets.GITHUB_TOKEN }}"
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}"
expires: 14d
projectId: action-hosting-deploy-demo
entryPoint: "./demo"
firebaseToolsVersion: v11.12.0
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ for more information about deploy targets.
The directory containing your [`firebase.json`](https://firebase.google.com/docs/cli#the_firebasejson_file)
file relative to the root of your repository. Defaults to `.` (the root of your repo).

### `firebaseToolsVersion` _{string}_

The version of `firebase-tools` to use. If not specified, defaults to `latest`.

## Outputs

Values emitted by this action that can be consumed by other actions later in your workflow
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ branding:
icon: "globe"
color: "blue"
runs:
using: "node12"
using: "node16"
main: "bin/action.min.js"
inputs:
repoToken:
Expand Down Expand Up @@ -54,6 +54,11 @@ inputs:
directory"
default: "."
required: false
firebaseToolsVersion:
description: >-
The version of firebase-tools to use. Defaults to `latest`.
default: latest
required: false
outputs:
urls:
description: The url(s) deployed to
Expand Down
34 changes: 24 additions & 10 deletions bin/action.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -11189,11 +11189,13 @@ function interpretChannelDeployResult(deployResult) {
};
}

async function execWithCredentials(args, projectId, gacFilename, debug = false) {
async function execWithCredentials(args, projectId, gacFilename, opts) {
let deployOutputBuf = [];
const debug = opts.debug || false;
const firebaseToolsVersion = opts.firebaseToolsVersion || "latest";

try {
await exec_2("npx firebase-tools", [...args, ...(projectId ? ["--project", projectId] : []), debug ? "--debug" // gives a more thorough error message
await exec_2(`npx firebase-tools@${firebaseToolsVersion}`, [...args, ...(projectId ? ["--project", projectId] : []), debug ? "--debug" // gives a more thorough error message
: "--json"], {
listeners: {
stdout(data) {
Expand All @@ -11210,9 +11212,12 @@ async function execWithCredentials(args, projectId, gacFilename, debug = false)
console.log(Buffer.concat(deployOutputBuf).toString("utf-8"));
console.log(e.message);

if (debug === false) {
if (!debug) {
console.log("Retrying deploy with the --debug flag for better error output");
await execWithCredentials(args, projectId, gacFilename, true);
await execWithCredentials(args, projectId, gacFilename, {
debug: true,
firebaseToolsVersion
});
} else {
throw e;
}
Expand All @@ -11226,18 +11231,24 @@ async function deployPreview(gacFilename, deployConfig) {
projectId,
channelId,
target,
expires
expires,
firebaseToolsVersion
} = deployConfig;
const deploymentText = await execWithCredentials(["hosting:channel:deploy", channelId, ...(target ? ["--only", target] : []), ...(expires ? ["--expires", expires] : [])], projectId, gacFilename);
const deploymentText = await execWithCredentials(["hosting:channel:deploy", channelId, ...(target ? ["--only", target] : []), ...(expires ? ["--expires", expires] : [])], projectId, gacFilename, {
firebaseToolsVersion
});
const deploymentResult = JSON.parse(deploymentText.trim());
return deploymentResult;
}
async function deployProductionSite(gacFilename, productionDeployConfig) {
const {
projectId,
target
target,
firebaseToolsVersion
} = productionDeployConfig;
const deploymentText = await execWithCredentials(["deploy", "--only", `hosting${target ? ":" + target : ""}`], projectId, gacFilename);
const deploymentText = await execWithCredentials(["deploy", "--only", `hosting${target ? ":" + target : ""}`], projectId, gacFilename, {
firebaseToolsVersion
});
const deploymentResult = JSON.parse(deploymentText);
return deploymentResult;
}
Expand Down Expand Up @@ -11413,6 +11424,7 @@ const token = process.env.GITHUB_TOKEN || core.getInput("repoToken");
const octokit = token ? github.getOctokit(token) : undefined;
const entryPoint = core.getInput("entryPoint");
const target = core.getInput("target");
const firebaseToolsVersion = core.getInput("firebaseToolsVersion");

async function run() {
const isPullRequest = !!github.context.payload.pull_request;
Expand Down Expand Up @@ -11452,7 +11464,8 @@ async function run() {
core.startGroup("Deploying to production site");
const deployment = await deployProductionSite(gacFilename, {
projectId,
target
target,
firebaseToolsVersion
});

if (deployment.status === "error") {
Expand All @@ -11479,7 +11492,8 @@ async function run() {
projectId,
expires,
channelId,
target
target,
firebaseToolsVersion
});

if (deployment.status === "error") {
Expand Down
Loading