chore(travis): deploy to docs and code when distTag=latest

We now deploy to code.angularjs.org and docs.angularjs.org
when we are on the branch which has distTag=latest set in the
package.json, i.e. the stable branch.

Previously, we deployed to docs only when distTag=latest and
the commit was tagged, and to code only on the master branch.
This commit is contained in:
Martin Staffa
2017-10-19 14:24:19 +02:00
committed by Martin Staffa
parent 10b48094d7
commit dfcb5ac1e4
5 changed files with 48 additions and 12 deletions
+5 -4
View File
@@ -52,6 +52,9 @@ notifications:
jobs:
include:
- stage: deploy
# Don't deploy from PRs.
# The deployment logic for pushed branches is defined in scripts\travis\build.sh
if: type != pull_request
env:
- JOB=deploy
before_script: skip
@@ -75,8 +78,7 @@ jobs:
on:
repo: angular/angular.js
all_branches: true
# deploy a new docs version when the commit is tagged on the "latest" npm version
condition: $TRAVIS_TAG != '' && $( jq ".distTag" "package.json" | tr -d "\"[:space:]" ) = latest
condition: $DEPLOY_DOCS
- provider: gcs
skip_cleanup: true
access_key_id: GOOGLDB7W2J3LFHICF3R
@@ -88,6 +90,5 @@ jobs:
on:
repo: angular/angular.js
all_branches: true
# upload the build when the commit is tagged or the branch is "master"
condition: $TRAVIS_TAG != '' || ($TRAVIS_PULL_REQUEST = false && $TRAVIS_BRANCH = master)
condition: $DEPLOY_CODE
+5 -1
View File
@@ -63,7 +63,11 @@ module.exports = function(grunt) {
NG_VERSION.cdn = versionInfo.cdnVersion;
var dist = 'angular-' + NG_VERSION.full;
var deployVersion = NG_VERSION.isSnapshot ? 'snapshot' : NG_VERSION.full;
var deployVersion = NG_VERSION.full;
if (NG_VERSION.isSnapshot) {
deployVersion = NG_VERSION.distTag === 'latest' ? 'snapshot-stable' : 'snapshot';
}
if (versionInfo.cdnVersion == null) {
throw new Error('Unable to read CDN version, are you offline or has the CDN not been properly pushed?\n' +
@@ -169,6 +169,13 @@ function sendStoredFile(request, response) {
}
}
const snapshotRegex = /^snapshot(-stable)?\//;
/**
* The build folder contains a zip file that is unique per build.
* When a new zip file is uploaded into snapshot or snapshot-stable,
* delete the previous zip file.
*/
function deleteOldSnapshotZip(event) {
const object = event.data;
@@ -179,15 +186,17 @@ function deleteOldSnapshotZip(event) {
const bucket = gcs.bucket(bucketId);
if (contentType !== 'application/zip' ||
!filePath.startsWith('snapshot/') ||
const snapshotFolderMatch = filePath.match(snapshotRegex);
if (!snapshotFolderMatch ||
contentType !== 'application/zip' ||
resourceState === 'not_exists' // Deletion event
) {
return;
}
bucket.getFiles({
prefix: 'snapshot/',
prefix: snapshotFolderMatch[0],
delimiter: '/',
autoPaginate: false
}).then(function(data) {
@@ -197,6 +206,8 @@ function deleteOldSnapshotZip(event) {
return file.metadata.name !== filePath && file.metadata.contentType === 'application/zip';
});
console.info(`found ${oldZipFiles.length} old zip files to delete`);
oldZipFiles.forEach(function(file) {
file.delete();
});
@@ -6,6 +6,9 @@ This folder contains the Google Firebase scripts for the code.angularjs.org setu
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.
The deployment to the Google Cloud Storage bucket happens automatically via Travis. See the travis.yml
file in the repository root.
+21 -4
View File
@@ -18,7 +18,7 @@ case "$JOB" in
fi
;;
"unit")
if [ "$BROWSER_PROVIDER" == "browserstack" ]; then
if [[ "$BROWSER_PROVIDER" == "browserstack" ]]; then
BROWSERS="BS_Chrome,BS_Safari,BS_Firefox,BS_IE_9,BS_IE_10,BS_IE_11,BS_EDGE,BS_iOS_8,BS_iOS_9"
else
BROWSERS="SL_Chrome,SL_Chrome-1,SL_Firefox,SL_Firefox-1,SL_Safari_8,SL_Safari_9,SL_IE_9,SL_IE_10,SL_IE_11,SL_EDGE,SL_EDGE-1,SL_iOS"
@@ -46,11 +46,28 @@ case "$JOB" in
grunt test:travis-protractor --specs="$TARGET_SPECS"
;;
"deploy")
# we never deploy on Pull requests, so it's safe to skip the build here
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
export DEPLOY_DOCS
export DEPLOY_CODE
DIST_TAG=$( jq ".distTag" "package.json" | tr -d "\"[:space:]" )
# upload docs if the branch distTag from package.json is "latest" (i.e. stable branch)
if [[ "$DIST_TAG" == latest ]]; then
DEPLOY_DOCS=true
fi
# upload the build (code + docs) if ...
# the commit is tagged
# - or the branch is "master"
# - or the branch distTag from package.json is "latest" (i.e. stable branch)
if [[ "$TRAVIS_TAG" != '' || "$TRAVIS_BRANCH" == master || "$DIST_TAG" == latest ]]; then
DEPLOY_CODE=true
fi
if [[ "$DEPLOY_DOCS" || "$DEPLOY_CODE" ]]; then
grunt prepareFirebaseDeploy
else
echo "Skipping build because Travis has been triggered by Pull Request"
echo "Skipping deployment build because conditions have not been met."
fi
;;
*)