From 33c540e7aff97a4f1f3a00af48e24ef772d0bc5b Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Fri, 5 Feb 2021 20:45:13 +0200 Subject: [PATCH] chore(ci): copy deployment files inside the respective Firebase directories We have the `scripts/{code,docs}.angularjs.org-firebase/` directories, which contain the necessary code and config for deploying built files to the `code-angularjs-org` and `docs-angularjs-org` Firebase projects respectively. Previously, some of the files that needed to be deployed to Firebase (or Google Cloud) were placed outside these directories (e.g. in `deploy/{code,docs}/`). Since these files are only used for deploying to Firebase/Google Cloud, this commit changes the deployment process to instead copy the files inside the directories. In a subsequent commit, this will allow simplifying the deployment process, by running it from inside each directory instead of having to copy the `firebase.json` files to the repository root (and adjust the paths). These are the destination directory changes: | Before | After | |--------------|---------------------------------------------| | deploy/code/ | scripts/code.angularjs.org-firebase/deploy/ | | deploy/docs/ | scripts/docs.angularjs.org-firebase/deploy/ | --- .circleci/config.yml | 4 ++-- .gitignore | 3 ++- Gruntfile.js | 17 +++++++------- lib/grunt/utils.js | 10 +++++--- .../readme.firebase.code.md | 16 ++++++------- .../docs.angularjs.org-firebase/firebase.json | 2 +- .../readme.firebase.docs.md | 23 ++++++++----------- 7 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a5730630c8db..99f8be6d542e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: | @@ -369,7 +369,7 @@ 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 # 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). diff --git a/.gitignore b/.gitignore index 8226c42f29c4..860bb1e57f7f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /build/ -/deploy/ /benchpress-build/ .DS_Store gen_docs.disable @@ -23,5 +22,7 @@ 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 diff --git a/Gruntfile.js b/Gruntfile.js index fd52c82ce11a..286a89c85274 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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 @@ -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' ] }, @@ -372,7 +373,7 @@ module.exports = function(grunt) { { cwd: 'build', src: '**', - dest: 'deploy/code/' + deployVersion + '/', + dest: codeScriptFolder + '/deploy/' + deployVersion + '/', expand: true } ] @@ -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', @@ -403,7 +404,7 @@ module.exports = function(grunt) { { cwd: 'build/docs', src: 'partials/**', - dest: docsScriptFolder + '/functions/content', + dest: docsScriptFolder + '/functions/content/', expand: true } ] diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index f94661c2ffa3..53ec1829d271 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -7,10 +7,15 @@ 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, + + docsScriptFolder, + startKarma: function(config, singleRun, done) { var browsers = grunt.option('browsers'); var reporters = grunt.option('reporters'); @@ -303,17 +308,16 @@ module.exports = { }; }, - 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.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/code.angularjs.org-firebase/readme.firebase.code.md b/scripts/code.angularjs.org-firebase/readme.firebase.code.md index c3f152998c59..5e90763f08f4 100644 --- a/scripts/code.angularjs.org-firebase/readme.firebase.code.md +++ b/scripts/code.angularjs.org-firebase/readme.firebase.code.md @@ -1,15 +1,15 @@ Firebase for code.angularjs.org =============================== -This folder contains the Google Firebase scripts for the code.angularjs.org setup. +This folder contains the Google Firebase scripts for the `code.angularjs.org` setup. -firebase.json contains the rewrite rules that route every subdirectory request to the cloud function -in functions/index.js that serves the docs from the Firebase Google Cloud Storage bucket. +`firebase.json` contains the rewrite rules that route every subdirectory request to the cloud function in `functions/index.js` that serves the docs from the Firebase Google Cloud Storage bucket. -functions/index.js also contains a rule that deletes outdated build zip files -from the snapshot and snapshot-stable folders when new zip files are uploaded. +`functions/index.js` also contains a rule that deletes outdated build zip files from the snapshot and snapshot-stable folders when new zip files are uploaded. -The deployment to the Google Cloud Storage bucket happens automatically via CI. -See the .circleci/config.yml file in the repository root. +See `/scripts/docs.angularjs.org-firebase/readme.firebase.code.md` for the Firebase deployment to `docs.angularjs.org`. -See /readme.firebase.docs.md for the firebase deployment to docs.angularjs.org \ No newline at end of file +# Continuous integration + +The code is deployed to Google Firebase hosting and functions as well as to the Google Cloud Storage bucket automatically via CI. +See `.circleci/config.yml` for the complete deployment config and build steps. diff --git a/scripts/docs.angularjs.org-firebase/firebase.json b/scripts/docs.angularjs.org-firebase/firebase.json index 5b09fef9ab64..df5e0c3169c0 100644 --- a/scripts/docs.angularjs.org-firebase/firebase.json +++ b/scripts/docs.angularjs.org-firebase/firebase.json @@ -1,6 +1,6 @@ { "hosting": { - "public": "../../deploy/docs", + "public": "deploy", "redirects": [ { "source": "/error/:namespace\\::error*", diff --git a/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md b/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md index 09e99d728915..63a7761fb6f3 100644 --- a/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md +++ b/scripts/docs.angularjs.org-firebase/readme.firebase.docs.md @@ -1,15 +1,16 @@ Firebase for docs.angularjs.org =============================== +This folder contains the Google Firebase scripts for the `docs.angularjs.org` setup. + +See `/scripts/code.angularjs.org-firebase/readme.firebase.code.md` for the Firebase deployment to `code.angularjs.org`. + # 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 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. -See .circleci/config.yml for the complete deployment config and build steps. +See `.circleci/config.yml` for the complete deployment config and build steps. # Serving locally: @@ -17,12 +18,8 @@ See .circleci/config.yml for the complete deployment config and build steps. This builds the files that will be deployed. - Run `yarn grunt prepareDeploy`. - This copies docs content files into deploy/docs 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 + 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` - Creates a server at localhost:5000 that serves from deploy/docs and uses the local function - -See /scripts/code.angularjs.org-firebase/readme.firebase.code.md for the firebase deployment to -code.angularjs.org + Creates a server at http://localhost:5000 that serves from `./deploy` and uses the local function.