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

Commit 3ef612a

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 cc8486f commit 3ef612a

File tree

5 files changed

+71
-22
lines changed

5 files changed

+71
-22
lines changed

.travis.yml

+22-12
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,32 @@ notifications:
5454
jobs:
5555
include:
5656
- stage: deploy
57+
# Don't deploy from PRs.
58+
# This is a Travis-specific boolean language: https://docs.travis-ci.com/user/conditional-builds-stages-jobs#Specifying-conditions
59+
# The deployment logic for pushed branches is further defined in scripts\travis\build.sh
60+
if: type != pull_request
5761
env:
5862
- JOB=deploy
5963
before_script: skip
6064
script:
61-
- "./scripts/travis/build.sh"
65+
# Export the variables into the current process
66+
- . ./scripts/travis/build.sh
67+
- "echo DEPLOY_DOCS: $DEPLOY_DOCS, DEPLOY_CODE: $DEPLOY_CODE"
68+
after_script: skip
6269
# Work around the 10min Travis timeout so the code.angularjs firebase+gcs code deploy can complete
70+
# Only run the keep_alive once (before_deploy is run for each provider)
6371
before_deploy: |
64-
function keep_alive() {
65-
while true; do
66-
echo -en "\a"
67-
sleep 5
68-
done
69-
}
70-
keep_alive &
72+
if ! [ "$BEFORE_DEPLOY_RUN" ]; then
73+
export BEFORE_DEPLOY_RUN=1;
74+
75+
function keep_alive() {
76+
while true; do
77+
echo -en "\a"
78+
sleep 10
79+
done
80+
}
81+
keep_alive &
82+
fi
7183
deploy:
7284
- provider: firebase
7385
# the upload folder for firebase is configured in /firebase.json
@@ -77,8 +89,7 @@ jobs:
7789
on:
7890
repo: angular/angular.js
7991
all_branches: true
80-
# deploy a new docs version when the commit is tagged on the "latest" npm version
81-
condition: $TRAVIS_TAG != '' && $( jq ".distTag" "package.json" | tr -d "\"[:space:]" ) = latest
92+
condition: "$DEPLOY_DOCS == true"
8293
- provider: gcs
8394
skip_cleanup: true
8495
access_key_id: GOOGLDB7W2J3LFHICF3R
@@ -90,6 +101,5 @@ jobs:
90101
on:
91102
repo: angular/angular.js
92103
all_branches: true
93-
# upload the build when the commit is tagged or the branch is "master"
94-
condition: $TRAVIS_TAG != '' || ($TRAVIS_PULL_REQUEST = false && $TRAVIS_BRANCH = master)
104+
condition: "$DEPLOY_CODE == true"
95105

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

+27-6
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,42 @@ case "$JOB" in
4646
export USE_JQUERY=1
4747
fi
4848

49-
export TARGET_SPECS="build/docs/ptore2e/**/default_test.js"
50-
5149
if [[ "$TEST_TARGET" == jquery* ]]; then
5250
TARGET_SPECS="build/docs/ptore2e/**/jquery_test.js"
51+
else
52+
TARGET_SPECS="build/docs/ptore2e/**/default_test.js"
5353
fi
5454

55-
export TARGET_SPECS="test/e2e/tests/**/*.js,$TARGET_SPECS"
55+
TARGET_SPECS="test/e2e/tests/**/*.js,$TARGET_SPECS"
5656
grunt test:travis-protractor --specs="$TARGET_SPECS"
5757
;;
5858
"deploy")
59-
# we never deploy on Pull requests, so it's safe to skip the build here
60-
if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
59+
export DEPLOY_DOCS
60+
export DEPLOY_CODE
61+
62+
DIST_TAG=$( jq ".distTag" "package.json" | tr -d "\"[:space:]" )
63+
64+
# upload docs if the branch distTag from package.json is "latest" (i.e. stable branch)
65+
if [[ "$DIST_TAG" == latest ]]; then
66+
DEPLOY_DOCS=true
67+
else
68+
DEPLOY_DOCS=false
69+
fi
70+
71+
# upload the build (code + docs) if ...
72+
# the commit is tagged
73+
# - or the branch is "master"
74+
# - or the branch distTag from package.json is "latest" (i.e. stable branch)
75+
if [[ "$TRAVIS_TAG" != '' || "$TRAVIS_BRANCH" == master || "$DIST_TAG" == latest ]]; then
76+
DEPLOY_CODE=true
77+
else
78+
DEPLOY_CODE=false
79+
fi
80+
81+
if [[ "$DEPLOY_DOCS" == true || "$DEPLOY_CODE" == true ]]; then
6182
grunt prepareFirebaseDeploy
6283
else
63-
echo "Skipping build because Travis has been triggered by Pull Request"
84+
echo "Skipping deployment build because conditions have not been met."
6485
fi
6586
;;
6687
*)

0 commit comments

Comments
 (0)