This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 5 files changed +71
-22
lines changed
code.angularjs.org-firebase
5 files changed +71
-22
lines changed Original file line number Diff line number Diff line change @@ -54,20 +54,32 @@ notifications:
54
54
jobs :
55
55
include :
56
56
- 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
57
61
env :
58
62
- JOB=deploy
59
63
before_script : skip
60
64
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
62
69
# 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)
63
71
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
71
83
deploy :
72
84
- provider : firebase
73
85
# the upload folder for firebase is configured in /firebase.json
77
89
on :
78
90
repo : angular/angular.js
79
91
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"
82
93
- provider : gcs
83
94
skip_cleanup : true
84
95
access_key_id : GOOGLDB7W2J3LFHICF3R
90
101
on :
91
102
repo : angular/angular.js
92
103
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"
95
105
Original file line number Diff line number Diff line change @@ -63,7 +63,11 @@ module.exports = function(grunt) {
63
63
NG_VERSION . cdn = versionInfo . cdnVersion ;
64
64
var dist = 'angular-' + NG_VERSION . full ;
65
65
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
+ }
67
71
68
72
if ( versionInfo . cdnVersion == null ) {
69
73
throw new Error ( 'Unable to read CDN version, are you offline or has the CDN not been properly pushed?\n' +
Original file line number Diff line number Diff line change @@ -169,6 +169,13 @@ function sendStoredFile(request, response) {
169
169
}
170
170
}
171
171
172
+ const snapshotRegex = / ^ s n a p s h o t ( - s t a b l e ) ? \/ / ;
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
+ */
172
179
function deleteOldSnapshotZip ( event ) {
173
180
const object = event . data ;
174
181
@@ -179,15 +186,17 @@ function deleteOldSnapshotZip(event) {
179
186
180
187
const bucket = gcs . bucket ( bucketId ) ;
181
188
182
- if ( contentType !== 'application/zip' ||
183
- ! filePath . startsWith ( 'snapshot/' ) ||
189
+ const snapshotFolderMatch = filePath . match ( snapshotRegex ) ;
190
+
191
+ if ( ! snapshotFolderMatch ||
192
+ contentType !== 'application/zip' ||
184
193
resourceState === 'not_exists' // Deletion event
185
194
) {
186
195
return ;
187
196
}
188
197
189
198
bucket . getFiles ( {
190
- prefix : 'snapshot/' ,
199
+ prefix : snapshotFolderMatch [ 0 ] ,
191
200
delimiter : '/' ,
192
201
autoPaginate : false
193
202
} ) . then ( function ( data ) {
@@ -197,6 +206,8 @@ function deleteOldSnapshotZip(event) {
197
206
return file . metadata . name !== filePath && file . metadata . contentType === 'application/zip' ;
198
207
} ) ;
199
208
209
+ console . info ( `found ${ oldZipFiles . length } old zip files to delete` ) ;
210
+
200
211
oldZipFiles . forEach ( function ( file ) {
201
212
file . delete ( ) ;
202
213
} ) ;
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ This folder contains the Google Firebase scripts for the code.angularjs.org setu
6
6
firebase.json contains the rewrite rules that route every subdirectory request to the cloud function
7
7
in functions/index.js that serves the docs from the Firebase Google Cloud Storage bucket.
8
8
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
+
9
12
The deployment to the Google Cloud Storage bucket happens automatically via Travis. See the travis.yml
10
13
file in the repository root.
11
14
Original file line number Diff line number Diff line change @@ -46,21 +46,42 @@ case "$JOB" in
46
46
export USE_JQUERY=1
47
47
fi
48
48
49
- export TARGET_SPECS=" build/docs/ptore2e/**/default_test.js"
50
-
51
49
if [[ " $TEST_TARGET " == jquery* ]]; then
52
50
TARGET_SPECS=" build/docs/ptore2e/**/jquery_test.js"
51
+ else
52
+ TARGET_SPECS=" build/docs/ptore2e/**/default_test.js"
53
53
fi
54
54
55
- export TARGET_SPECS=" test/e2e/tests/**/*.js,$TARGET_SPECS "
55
+ TARGET_SPECS=" test/e2e/tests/**/*.js,$TARGET_SPECS "
56
56
grunt test:travis-protractor --specs=" $TARGET_SPECS "
57
57
;;
58
58
" 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
61
82
grunt prepareFirebaseDeploy
62
83
else
63
- echo " Skipping build because Travis has been triggered by Pull Request "
84
+ echo " Skipping deployment build because conditions have not been met. "
64
85
fi
65
86
;;
66
87
* )
You can’t perform that action at this time.
0 commit comments