From bc01028766fd8f728d5438f6e4c9f24739abcd19 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 5 Feb 2021 21:00:44 +0200 Subject: [PATCH] chore(ci): deploy to `docs.angularjs.org` from within the corresponding directory Previously, in order to deploy to Firebase from `scripts/docs.angularjs.org-firebase/`, we had to copy the `firebase.json` file to the repository root and adjust the contained paths accordingly. By running the `firebase` CLI directly (instead of via `yarn`), we are able to deploy from `docs.angularjs.org-firebase/` directly. This simplifies the deployment (and local testing) process and paves the way for also deploying from `code.angularjs.org-firebase/` in a subsequent commit. --- .circleci/config.yml | 18 ++++++++++++++---- .gitignore | 1 - Gruntfile.js | 1 - lib/grunt/utils.js | 19 ++----------------- .../readme.firebase.docs.md | 9 +++++---- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 99f8be6d542e..044c66dbdc4f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -385,10 +385,20 @@ jobs: - custom_attach_workspace - init_environment - skip_unless_stable_branch - # Install dependencies for Firebase functions to prevent parsing errors during deployment - # See https://github.com/angular/angular.js/pull/16453 - - run: yarn --cwd scripts/docs.angularjs.org-firebase/functions --ignore-engines - - run: yarn firebase deploy --message "Commit:\ $CI_COMMIT" --non-interactive --only hosting --project "docs-angularjs-org-9p2" --token "$FIREBASE_TOKEN" + # Install dependencies for Firebase functions to prevent parsing errors during deployment. + # See https://github.com/angular/angular.js/pull/16453. + - run: + name: Install dependencies in `scripts/docs.angularjs.org-firebase/functions/`. + working_directory: scripts/docs.angularjs.org-firebase/functions + command: yarn install --frozen-lockfile --ignore-engines --non-interactive + - run: + name: Deploy to Firebase from `scripts/docs.angularjs.org-firebase/`. + working_directory: scripts/docs.angularjs.org-firebase + command: | + # Do not use `yarn firebase` as that causes the Firebase CLI to look for `firebase.json` + # in the root directory, even if run from inside `scripts/docs.angularjs.org-firebase/`. + firebase=$(yarn bin)/firebase + $firebase deploy --message "Commit:\ $CI_COMMIT" --non-interactive --only hosting --project "docs-angularjs-org-9p2" --token "$FIREBASE_TOKEN" workflows: version: 2 diff --git a/.gitignore b/.gitignore index 860bb1e57f7f..9641ed4fd609 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,3 @@ npm-debug.log scripts/code.angularjs.org-firebase/deploy scripts/docs.angularjs.org-firebase/deploy scripts/docs.angularjs.org-firebase/functions/content -/firebase.json diff --git a/Gruntfile.js b/Gruntfile.js index 286a89c85274..4b647bb8f438 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -518,7 +518,6 @@ module.exports = function(grunt) { ]); grunt.registerTask('prepareDeploy', [ 'copy:deployFirebaseCode', - 'firebaseDocsJsonForCI', 'copy:deployFirebaseDocs' ]); grunt.registerTask('default', ['package']); diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 53ec1829d271..b854ea7b3ba4 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -7,14 +7,11 @@ var spawn = require('npm-run').spawn; var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n'; -const codeScriptFolder = 'scripts/code.angularjs.org-firebase'; -const docsScriptFolder = 'scripts/docs.angularjs.org-firebase'; - module.exports = { - codeScriptFolder, + codeScriptFolder: 'scripts/code.angularjs.org-firebase', - docsScriptFolder, + docsScriptFolder: 'scripts/docs.angularjs.org-firebase', startKarma: function(config, singleRun, done) { var browsers = grunt.option('browsers'); @@ -306,18 +303,6 @@ module.exports = { } next(); }; - }, - - // Our Firebase projects are in subfolders, but the firebase tool expects them in the root, - // so we need to modify the upload folder path and copy the file into the root - firebaseDocsJsonForCI: function() { - var fileName = docsScriptFolder + '/firebase.json'; - var json = grunt.file.readJSON(fileName); - - (json.hosting || (json.hosting = {})).public = docsScriptFolder + '/deploy'; - (json.functions || (json.functions = {})).source = docsScriptFolder + '/functions'; - - grunt.file.write('firebase.json', JSON.stringify(json)); } }; diff --git a/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md b/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md index 63a7761fb6f3..dbf086fec32d 100644 --- a/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md +++ b/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md @@ -7,19 +7,20 @@ See `/scripts/code.angularjs.org-firebase/readme.firebase.code.md` for the Fireb # Continuous integration -The docs are deployed to Google Firebase hosting via a CI deployment config, which expects `firebase.json` to be in the repository root, which is done by a Grunt task (`firebaseDocsJsonForCI` which is included in `prepareDeploy`). -The `firebaseDocsJsonForCI` task modifies the paths in the `firebase.json` and copies it to the repository root. +The docs are deployed to Google Firebase hosting and functions automatically via CI. See `.circleci/config.yml` for the complete deployment config and build steps. # Serving locally: +- Run `cd scripts/docs.angularjs.org-firebase`. + This changes the current working directory. + - Run `yarn grunt package`. This builds the files that will be deployed. - Run `yarn grunt prepareDeploy`. This copies docs content files into `./deploy` and the partials for Search Engine AJAX Crawling into `./functions/content`. - It also moves the `firebase.json` file to the root folder, where the firebase-cli expects it. -- Run `firebase serve --only functions,hosting` +- Run `$(yarn bin)/firebase emulators:start` (or `..\..\node_modules\.bin\firebase emulators:start` on Windows). Creates a server at http://localhost:5000 that serves from `./deploy` and uses the local function.