diff --git a/.travis.yml b/.travis.yml index 7fda603158a..2f9210e483e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,6 +52,9 @@ before_script: script: - ./scripts/ci/build-and-test.sh +after_success: + - ./scripts/ci/after-success.sh + cache: directories: - node_modules diff --git a/package.json b/package.json index 867cfda9795..90810722c8e 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "strip-ansi": "^3.0.0", "stylelint": "^7.5.0", "symlink-or-copy": "^1.0.1", + "travis-after-modes": "0.0.5", "ts-node": "^0.7.3", "tslint": "^3.13.0", "typedoc": "^0.5.1", diff --git a/scripts/ci/after-success.sh b/scripts/ci/after-success.sh new file mode 100755 index 00000000000..e1691eeff4d --- /dev/null +++ b/scripts/ci/after-success.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Script which always runs when the current Travis mode succeeds. +# Used to run the travis-after-modes script, which checks if all other modes finished. + +# Go to the project root directory +cd $(dirname $0)/../.. + +npmBin=$(npm bin) +ciResult=$($npmBin/travis-after-modes) + +if [ "$ciResult" = "PASSED" ] && [ -z "$TRAVIS_PULL_REQUEST" ]; then + echo "All travis modes passed. Publishing the build artifacts..." + ./scripts/release/publish-build-artifacts.sh +fi \ No newline at end of file diff --git a/scripts/release/publish-build-artifacts.sh b/scripts/release/publish-build-artifacts.sh new file mode 100755 index 00000000000..c9351defa99 --- /dev/null +++ b/scripts/release/publish-build-artifacts.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Script to publish the build artifacts to a GitHub repository. +# Builds will be automatically published once new changes are made to the repository. + +# Go to the project root directory +cd $(dirname $0)/../.. + +buildDir="dist/@angular/material" +buildVersion=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) + +commitSha=$(git rev-parse --short HEAD) +commitAuthor=$(git --no-pager show -s --format='%an <%ae>' HEAD) +commitMessage=$(git log --oneline | head -n1) + +repoName="material-builds" +repoUrl="http://github.com/DevVersion/material-builds.git" +repoDir="tmp/$repoName" + +# Create a release of the current repository. +$(npm bin)/gulp build:release + +# Prepare cloning the builds repository +rm -rf $repoDir +mkdir -p $repoDir + +# Clone the repository +git clone $repoUrl $repoDir + +# Copy the build files to the repository +rm -rf $repoDir/* +cp -r $buildDir/* $repoDir + +# Create the build commit and push the changes to the repository. +cd $repoDir && + +# Setup the git repository authentication. +git config credential.helper "store --file=.git/credentials" && +echo "$MATERIAL2_BUILDS_TOKEN" > .git/credentials + +git add -A && +git commit -m "$commitMessage" --author "$commitAuthor" && +git tag "$buildVersion-$commitSha" && +git push origin master --tags + +echo "Finished publishing build artifacts"