Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(ci): several fixes/improvements to Firebase deployments #17114

Closed
wants to merge 9 commits into from
Closed
38 changes: 32 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ jobs:
- custom_attach_workspace
- init_environment
- skip_unless_tag_or_master_or_stable_branch
- run: ls deploy/code
- run: ls scripts/code.angularjs.org-firebase/deploy
- run:
name: Authenticate and configure Docker
command: |
Expand All @@ -369,7 +369,22 @@ jobs:
- run:
name: Sync files to code.angularjs.org
command: |
gsutil -m rsync -r deploy/code gs://code-angularjs-org-338b8.appspot.com
gsutil -m rsync -r scripts/code.angularjs.org-firebase/deploy gs://code-angularjs-org-338b8.appspot.com
# 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/code.angularjs.org-firebase/functions/`.
working_directory: scripts/code.angularjs.org-firebase/functions
command: yarn install --frozen-lockfile --ignore-engines --non-interactive
- run:
name: Deploy to Firebase from `scripts/code.angularjs.org-firebase/`.
working_directory: scripts/code.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/code.angularjs.org-firebase/`.
firebase=$(yarn bin)/firebase
$firebase use
$firebase deploy --message "Commit:\ $CI_COMMIT" --non-interactive --token "$FIREBASE_TOKEN"

# The `deploy-docs` job should only run when all of these conditions are true for the build:
# - It is for the `angular/angular.js` repository (not a fork).
Expand All @@ -385,10 +400,21 @@ 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 use
$firebase deploy --message "Commit:\ $CI_COMMIT" --non-interactive --token "$FIREBASE_TOKEN"

workflows:
version: 2
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/build/
/deploy/
/benchpress-build/
.DS_Store
gen_docs.disable
Expand All @@ -23,5 +22,6 @@ npm-debug.log
.vscode
*.log
*.stackdump
scripts/code.angularjs.org-firebase/deploy
scripts/docs.angularjs.org-firebase/deploy
scripts/docs.angularjs.org-firebase/functions/content
/firebase.json
18 changes: 9 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var semver = require('semver');
var exec = require('shelljs').exec;
var pkg = require(__dirname + '/package.json');

var codeScriptFolder = util.codeScriptFolder;
var docsScriptFolder = util.docsScriptFolder;

// Node.js version checks
Expand Down Expand Up @@ -166,9 +167,9 @@ module.exports = function(grunt) {
build: ['build'],
tmp: ['tmp'],
deploy: [
'deploy/docs',
'deploy/code',
docsScriptFolder + '/functions/html'
codeScriptFolder + '/deploy',
docsScriptFolder + '/deploy',
docsScriptFolder + '/functions/content'
]
},

Expand Down Expand Up @@ -372,7 +373,7 @@ module.exports = function(grunt) {
{
cwd: 'build',
src: '**',
dest: 'deploy/code/' + deployVersion + '/',
dest: codeScriptFolder + '/deploy/' + deployVersion + '/',
expand: true
}
]
Expand All @@ -382,19 +383,19 @@ module.exports = function(grunt) {
// The source files are needed by the embedded examples in the docs app.
{
src: ['build/angular*.{js,js.map,min.js}', 'build/sitemap.xml'],
dest: 'deploy/docs/',
dest: docsScriptFolder + '/deploy/',
expand: true,
flatten: true
},
{
cwd: 'build/docs',
src: ['**', '!ptore2e/**', '!index*.html'],
dest: 'deploy/docs/',
dest: docsScriptFolder + '/deploy/',
expand: true
},
{
src: 'build/docs/index-production.html',
dest: 'deploy/docs/index.html'
dest: docsScriptFolder + '/deploy/index.html'
},
{
src: 'build/docs/index-production.html',
Expand All @@ -403,7 +404,7 @@ module.exports = function(grunt) {
{
cwd: 'build/docs',
src: 'partials/**',
dest: docsScriptFolder + '/functions/content',
dest: docsScriptFolder + '/functions/content/',
expand: true
}
]
Expand Down Expand Up @@ -517,7 +518,6 @@ module.exports = function(grunt) {
]);
grunt.registerTask('prepareDeploy', [
'copy:deployFirebaseCode',
'firebaseDocsJsonForCI',
'copy:deployFirebaseDocs'
]);
grunt.registerTask('default', ['package']);
Expand Down
21 changes: 5 additions & 16 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ 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 docsScriptFolder = 'scripts/docs.angularjs.org-firebase';

module.exports = {

codeScriptFolder: 'scripts/code.angularjs.org-firebase',

docsScriptFolder: 'scripts/docs.angularjs.org-firebase',

startKarma: function(config, singleRun, done) {
var browsers = grunt.option('browsers');
var reporters = grunt.option('reporters');
Expand Down Expand Up @@ -301,19 +303,6 @@ module.exports = {
}
next();
};
},

docsScriptFolder,

// 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 = 'deploy/docs';
(json.functions || (json.functions = {})).source = docsScriptFolder + '/functions';

grunt.file.write('firebase.json', JSON.stringify(json));
}

};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dgeni-packages": "^0.26.5",
"eslint-plugin-promise": "^3.6.0",
"event-stream": "~3.1.0",
"firebase-tools": "^8.3.0",
"firebase-tools": "^9.3.0",
"glob": "^6.0.1",
"google-code-prettify": "1.0.1",
"grunt": "^1.0.1",
Expand Down
5 changes: 2 additions & 3 deletions scripts/code.angularjs.org-firebase/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const functions = require('firebase-functions');
const {Storage} = require('@google-cloud/storage');
const path = require('path');

const storage = new Storage();
const gcsBucketId = `${process.env.GCLOUD_PROJECT}.appspot.com`;
Expand Down Expand Up @@ -41,13 +40,13 @@ function sendStoredFile(request, response) {
return getDirectoryListing('/').catch(sendErrorResponse);
}

downloadSource = path.join.apply(null, filePathSegments);
downloadSource = filePathSegments.join('/');

downloadAndSend(downloadSource).catch(error => {
if (isDocsPath && error.code === 404) {
fileName = 'index.html';
filePathSegments = [version, 'docs', fileName];
downloadSource = path.join.apply(null, filePathSegments);
downloadSource = filePathSegments.join('/');

return downloadAndSend(downloadSource);
}
Expand Down
Loading