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

Commit dfcb5ac

Browse files
committed
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.
1 parent 10b4809 commit dfcb5ac

File tree

5 files changed

+48
-12
lines changed

5 files changed

+48
-12
lines changed

.travis.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ notifications:
5252
jobs:
5353
include:
5454
- stage: deploy
55+
# Don't deploy from PRs.
56+
# The deployment logic for pushed branches is defined in scripts\travis\build.sh
57+
if: type != pull_request
5558
env:
5659
- JOB=deploy
5760
before_script: skip
@@ -75,8 +78,7 @@ jobs:
7578
on:
7679
repo: angular/angular.js
7780
all_branches: true
78-
# deploy a new docs version when the commit is tagged on the "latest" npm version
79-
condition: $TRAVIS_TAG != '' && $( jq ".distTag" "package.json" | tr -d "\"[:space:]" ) = latest
81+
condition: $DEPLOY_DOCS
8082
- provider: gcs
8183
skip_cleanup: true
8284
access_key_id: GOOGLDB7W2J3LFHICF3R
@@ -88,6 +90,5 @@ jobs:
8890
on:
8991
repo: angular/angular.js
9092
all_branches: true
91-
# upload the build when the commit is tagged or the branch is "master"
92-
condition: $TRAVIS_TAG != '' || ($TRAVIS_PULL_REQUEST = false && $TRAVIS_BRANCH = master)
93+
condition: $DEPLOY_CODE
9394

Gruntfile.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ module.exports = function(grunt) {
6363
NG_VERSION.cdn = versionInfo.cdnVersion;
6464
var dist = 'angular-' + NG_VERSION.full;
6565

66-
var deployVersion = NG_VERSION.isSnapshot ? 'snapshot' : NG_VERSION.full;
66+
var deployVersion = NG_VERSION.full;
67+
68+
if (NG_VERSION.isSnapshot) {
69+
deployVersion = NG_VERSION.distTag === 'latest' ? 'snapshot-stable' : 'snapshot';
70+
}
6771

6872
if (versionInfo.cdnVersion == null) {
6973
throw new Error('Unable to read CDN version, are you offline or has the CDN not been properly pushed?\n' +

scripts/code.angularjs.org-firebase/functions/index.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ function sendStoredFile(request, response) {
169169
}
170170
}
171171

172+
const snapshotRegex = /^snapshot(-stable)?\//;
173+
174+
/**
175+
* The build folder contains a zip file that is unique per build.
176+
* When a new zip file is uploaded into snapshot or snapshot-stable,
177+
* delete the previous zip file.
178+
*/
172179
function deleteOldSnapshotZip(event) {
173180
const object = event.data;
174181

@@ -179,15 +186,17 @@ function deleteOldSnapshotZip(event) {
179186

180187
const bucket = gcs.bucket(bucketId);
181188

182-
if (contentType !== 'application/zip' ||
183-
!filePath.startsWith('snapshot/') ||
189+
const snapshotFolderMatch = filePath.match(snapshotRegex);
190+
191+
if (!snapshotFolderMatch ||
192+
contentType !== 'application/zip' ||
184193
resourceState === 'not_exists' // Deletion event
185194
) {
186195
return;
187196
}
188197

189198
bucket.getFiles({
190-
prefix: 'snapshot/',
199+
prefix: snapshotFolderMatch[0],
191200
delimiter: '/',
192201
autoPaginate: false
193202
}).then(function(data) {
@@ -197,6 +206,8 @@ function deleteOldSnapshotZip(event) {
197206
return file.metadata.name !== filePath && file.metadata.contentType === 'application/zip';
198207
});
199208

209+
console.info(`found ${oldZipFiles.length} old zip files to delete`);
210+
200211
oldZipFiles.forEach(function(file) {
201212
file.delete();
202213
});

scripts/code.angularjs.org-firebase/readme.firebase.code.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ This folder contains the Google Firebase scripts for the code.angularjs.org setu
66
firebase.json contains the rewrite rules that route every subdirectory request to the cloud function
77
in functions/index.js that serves the docs from the Firebase Google Cloud Storage bucket.
88

9+
functions/index.js also contains a rule that deletes outdated build zip files
10+
from the snapshot and snapshot-stable folders when new zip files are uploaded.
11+
912
The deployment to the Google Cloud Storage bucket happens automatically via Travis. See the travis.yml
1013
file in the repository root.
1114

scripts/travis/build.sh

+21-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ case "$JOB" in
1818
fi
1919
;;
2020
"unit")
21-
if [ "$BROWSER_PROVIDER" == "browserstack" ]; then
21+
if [[ "$BROWSER_PROVIDER" == "browserstack" ]]; then
2222
BROWSERS="BS_Chrome,BS_Safari,BS_Firefox,BS_IE_9,BS_IE_10,BS_IE_11,BS_EDGE,BS_iOS_8,BS_iOS_9"
2323
else
2424
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
4646
grunt test:travis-protractor --specs="$TARGET_SPECS"
4747
;;
4848
"deploy")
49-
# we never deploy on Pull requests, so it's safe to skip the build here
50-
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
49+
export DEPLOY_DOCS
50+
export DEPLOY_CODE
51+
52+
DIST_TAG=$( jq ".distTag" "package.json" | tr -d "\"[:space:]" )
53+
54+
# upload docs if the branch distTag from package.json is "latest" (i.e. stable branch)
55+
if [[ "$DIST_TAG" == latest ]]; then
56+
DEPLOY_DOCS=true
57+
fi
58+
59+
# upload the build (code + docs) if ...
60+
# the commit is tagged
61+
# - or the branch is "master"
62+
# - or the branch distTag from package.json is "latest" (i.e. stable branch)
63+
if [[ "$TRAVIS_TAG" != '' || "$TRAVIS_BRANCH" == master || "$DIST_TAG" == latest ]]; then
64+
DEPLOY_CODE=true
65+
fi
66+
67+
if [[ "$DEPLOY_DOCS" || "$DEPLOY_CODE" ]]; then
5168
grunt prepareFirebaseDeploy
5269
else
53-
echo "Skipping build because Travis has been triggered by Pull Request"
70+
echo "Skipping deployment build because conditions have not been met."
5471
fi
5572
;;
5673
*)

0 commit comments

Comments
 (0)