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

Commit 8761ddc

Browse files
tboschIgorMinar
authored andcommitted
chore(release): be able to release any commit
The version information is now stored only in the tags. By this we are able to release commits in the past, which have already been tested, so we don't need a code freeze or run tests any more. This is also the first step for letting Travis do the releases in the future. The package.json now contains the new property 'branchVersion' that defines which tags are valid on this branch. Closes #6116
1 parent 058842a commit 8761ddc

File tree

7 files changed

+150
-118
lines changed

7 files changed

+150
-118
lines changed

lib/grunt/utils.js

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var fs = require('fs');
22
var shell = require('shelljs');
33
var grunt = require('grunt');
44
var spawn = require('child_process').spawn;
5+
var semver = require('semver');
56
var version;
67
var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n';
78

@@ -32,31 +33,82 @@ module.exports = {
3233

3334
getVersion: function(){
3435
if (version) return version;
35-
3636
var package = JSON.parse(fs.readFileSync('package.json', 'UTF-8'));
37-
var match = package.version.match(/^([^\-]*)(?:\-(.+))?$/);
38-
var semver = match[1].split('.');
37+
try {
38+
39+
var gitTag = getTagOfCurrentCommit();
40+
var semVerVersion, codeName, fullVersion;
41+
if (gitTag) {
42+
// tagged release
43+
fullVersion = semVerVersion = semver.valid(gitTag);
44+
codeName = getTaggedReleaseCodeName(gitTag);
45+
} else {
46+
// snapshot release
47+
semVerVersion = getSnapshotVersion();
48+
fullVersion = semVerVersion + '-' + getSnapshotSuffix();
49+
codeName = 'snapshot'
50+
}
51+
52+
var versionParts = semVerVersion.match(/(\d+)\.(\d+)\.(\d+)/);
53+
54+
version = {
55+
full: fullVersion,
56+
major: versionParts[1],
57+
minor: versionParts[2],
58+
dot: versionParts[3],
59+
codename: codeName,
60+
cdn: package.cdnVersion
61+
};
3962

40-
var fullVersion = match[1];
63+
return version;
4164

42-
if (match[2]) {
43-
fullVersion += '-';
44-
fullVersion += (match[2] == 'snapshot') ? getSnapshotSuffix() : match[2];
65+
} catch (e) {
66+
grunt.fail.warn(e);
4567
}
4668

47-
version = {
48-
full: fullVersion,
49-
major: semver[0],
50-
minor: semver[1],
51-
dot: semver[2].replace(/rc\d+/, ''),
52-
codename: package.codename,
53-
cdn: package.cdnVersion
54-
};
69+
function getTagOfCurrentCommit() {
70+
var gitTagResult = shell.exec('git describe --exact-match', {silent:true});
71+
var gitTagOutput = gitTagResult.output.trim();
72+
var branchVersionPattern = new RegExp(package.branchVersion.replace('.', '\\.').replace('*', '\\d+'));
73+
if (gitTagResult.code === 0 && gitTagOutput.match(branchVersionPattern)) {
74+
return gitTagOutput;
75+
} else {
76+
return null;
77+
}
78+
}
5579

56-
return version;
80+
function getTaggedReleaseCodeName(tagName) {
81+
var tagMessage = shell.exec('git cat-file -p '+ tagName +' | grep "codename"', {silent:true}).output;
82+
var codeName = tagMessage && tagMessage.match(/codename\((.*)\)/)[1];
83+
if (!codeName) {
84+
throw new Error("Could not extract release code name. The message of tag "+tagName+
85+
" must match '*codename(some release name)*'");
86+
}
87+
return codeName;
88+
}
89+
90+
function getSnapshotVersion() {
91+
var oldTags = shell.exec('git tag -l v'+package.branchVersion, {silent:true}).output.trim().split('\n');
92+
// ignore non semver versions.
93+
oldTags = oldTags.filter(function(version) {
94+
return version && semver.valid(version);
95+
});
96+
if (oldTags.length) {
97+
oldTags.sort(semver.compare);
98+
semVerVersion = oldTags[oldTags.length-1];
99+
if (semVerVersion.indexOf('-') !== -1) {
100+
semVerVersion = semver.inc(semVerVersion, 'prerelease');
101+
} else {
102+
semVerVersion = semver.inc(semVerVersion, 'patch');
103+
}
104+
} else {
105+
semVerVersion = semver.valid(package.branchVersion.replace(/\*/g, '0'));
106+
}
107+
return semVerVersion;
108+
}
57109

58110
function getSnapshotSuffix() {
59-
var jenkinsBuild = process.env.BUILD_NUMBER || 'local';
111+
var jenkinsBuild = process.env.TRAVIS_BUILD_NUMBER || process.env.BUILD_NUMBER || 'local';
60112
var hash = shell.exec('git rev-parse --short HEAD', {silent: true}).output.replace('\n', '');
61113
return 'build.'+jenkinsBuild+'+sha.'+hash;
62114
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"name": "angularjs",
3-
"version": "1.2.12-snapshot",
3+
"branchVersion": "1.2.*",
44
"cdnVersion": "1.2.11",
5-
"codename": "cauliflower-eradication",
65
"repository": {
76
"type": "git",
87
"url": "https://github.com/angular/angular.js.git"

scripts/angular.js/finalize-version.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

scripts/angular.js/initialize-new-version.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

scripts/angular.js/publish.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

scripts/angular.js/tag-release.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Tags a release
4+
# so that travis can do the actual release.
5+
6+
echo "#################################"
7+
echo "## Tag angular.js for a release #"
8+
echo "#################################"
9+
10+
ARG_DEFS=(
11+
"--action=(prepare|publish)"
12+
"--commit-sha=(.*)"
13+
# the version number of the release.
14+
# e.g. 1.2.12 or 1.2.12-rc.1
15+
"--version-number=([0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?)"
16+
"--version-name=(.+)"
17+
)
18+
19+
function checkVersionNumber() {
20+
BRANCH_PATTERN=$(readJsonProp "package.json" "branchVersion")
21+
if [[ $VERSION_NUMBER != $BRANCH_PATTERN ]]; then
22+
echo "version-number needs to match $BRANCH_PATTERN on this branch"
23+
usage
24+
fi
25+
}
26+
27+
function init {
28+
cd ../..
29+
checkVersionNumber
30+
TAG_NAME="v$VERSION_NUMBER"
31+
}
32+
33+
function prepare() {
34+
git tag "$TAG_NAME" -m "chore(release): $TAG_NAME codename($VERSION_NAME)" "$COMMIT_SHA"
35+
}
36+
37+
function publish() {
38+
# push the tag to github
39+
git push origin $TAG_NAME
40+
}
41+
42+
source $(dirname $0)/../utils.inc

scripts/jenkins/release.sh

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,63 @@
11
#!/bin/bash
22

3+
# tags the current commit as a release and publishes all artifacts to
4+
# the different repositories.
5+
# Note: This will also works if the commit is in the past!
6+
37
echo "#################################"
4-
echo "#### Cut release ################"
8+
echo "#### cut release ############"
59
echo "#################################"
610

711
ARG_DEFS=(
8-
"--next-version-type=(patch|minor|major)"
9-
"--next-version-name=(.+)"
1012
# require the git dryrun flag so the script can't be run without
1113
# thinking about this!
1214
"--git-push-dryrun=(true|false)"
13-
"[--no-test=(true|false)]"
15+
# The sha to release. Needs to be the same as HEAD.
16+
# given as parameter to double check.
17+
"--commit-sha=(.*)"
18+
# the version number of the release.
19+
# e.g. 1.2.12 or 1.2.12-rc.1
20+
"--version-number=([0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?)"
21+
# the codename of the release
22+
"--version-name=(.+)"
1423
)
1524

1625
function init {
17-
NG_ARGS=("$@")
26+
if [[ $(git rev-parse --short HEAD) != $COMMIT_SHA ]]; then
27+
echo "HEAD is not at $COMMIT_SHA"
28+
usage
29+
fi
30+
1831
if [[ ! $VERBOSE ]]; then
1932
VERBOSE=false
2033
fi
21-
if [[ ! $NO_TEST ]]; then
22-
NO_TEST=false
23-
fi
2434
VERBOSE_ARG="--verbose=$VERBOSE"
25-
NO_TEST_ARG="--no_test=$NO_TEST"
35+
}
36+
37+
function build {
38+
cd ../..
39+
40+
npm install --color false
41+
grunt ci-checks package --no-color
42+
43+
cd $SCRIPT_DIR
2644
}
2745

2846
function phase {
2947
ACTION_ARG="--action=$1"
30-
../angular.js/publish.sh $ACTION_ARG $VERBOSE_ARG $NO_TEST_ARG \
31-
--next-version-type=$NEXT_VERSION_TYPE --next-version-name=$NEXT_VERSION_NAME
48+
../angular.js/tag-release.sh $ACTION_ARG $VERBOSE_ARG\
49+
--version-number=$VERSION_NUMBER --version-name=$VERSION_NAME\
50+
--commit-sha=$COMMIT_SHA
51+
52+
if [[ $1 == "prepare" ]]; then
53+
# The build requires the tag to be set already!
54+
build
55+
fi
56+
3257
../code.angularjs.org/publish.sh $ACTION_ARG $VERBOSE_ARG
3358
../bower/publish.sh $ACTION_ARG $VERBOSE_ARG
34-
../angular-seed/publish.sh $ACTION_ARG $VERBOSE_ARG $NO_TEST_ARG
35-
../angular-phonecat/publish.sh $ACTION_ARG $VERBOSE_ARG $NO_TEST_ARG
59+
../angular-seed/publish.sh $ACTION_ARG $VERBOSE_ARG --no-test=true
60+
../angular-phonecat/publish.sh $ACTION_ARG $VERBOSE_ARG --no-test=true
3661
}
3762

3863
function run {

0 commit comments

Comments
 (0)