Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
chore(ci): deploy to docs.angularjs.org from within the correspondi…
…ng 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.
  • Loading branch information
gkalpak committed Feb 6, 2021
1 parent b481a16 commit 667ff87
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
18 changes: 14 additions & 4 deletions .circleci/config.yml
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -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
1 change: 0 additions & 1 deletion Gruntfile.js
Expand Up @@ -518,7 +518,6 @@ module.exports = function(grunt) {
]);
grunt.registerTask('prepareDeploy', [
'copy:deployFirebaseCode',
'firebaseDocsJsonForCI',
'copy:deployFirebaseDocs'
]);
grunt.registerTask('default', ['package']);
Expand Down
19 changes: 2 additions & 17 deletions lib/grunt/utils.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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));
}

};
9 changes: 5 additions & 4 deletions scripts/docs.angularjs.org-firebase/readme.firebase.docs.md
Expand Up @@ -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.

0 comments on commit 667ff87

Please sign in to comment.