Skip to content

Commit

Permalink
fix travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Seemann committed Jun 9, 2019
1 parent 132901e commit 9570c57
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ after_success:
# run e2e test
# - npm run e2e
# create a build - should test the tooling to create dist build
- npm run build:dist
- npm run build core
# create a build (demo site)
- npm run build
- npm run build demo

after_script:
File renamed without changes
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
{
"name": "angular-mdl",
"version": "0.0.0",
"description": "Angular 2-6 components, directives and styles based on material design lite https://getmdl.io.",
"keywords": [],
"homepage": "http://mseemann.io/angular2-mdl/",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/mseemann/angular2-mdl.git"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test core --watch=false --code-coverage",
"lint": "ng lint",
"e2e": "ng e2e",
"build-core": "ng-packagr -p projects/core/ng-package.json && cp -r ./projects/core/src/scss ./dist/@angular-mdl/core/scss"
"build-core": "ng-packagr -p projects/core/ng-package.json && cp -r ./projects/core/src/scss ./dist/@angular-mdl/core/scss",
"codeclimate": "CODECLIMATE_REPO_TOKEN=160aba8aa0baa5d0cab1d2162f50027cef9cda032fbc4eebefd54167ddce4c89 codeclimate-test-reporter < coverage/lcov.info",
"generate-scss-from-mdl-scss": "rimraf projects/core/src/scss/mdl && node ./scripts/generate-scss-from-mdl-scss.js",
"deploy-gh-pages": "npm run build demo && scripts/deploy.sh --message \\\\\\\"Deploy gh-pages from commit $(git rev-parse HEAD) [ci skip]\\\\\\\" -n"
},
"private": true,
"dependencies": {
Expand Down Expand Up @@ -42,6 +53,8 @@
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"material-design-lite": "1.3.0",
"ncp": "2.0.0",
"ng-packagr": "^5.1.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
Expand Down
220 changes: 220 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
#!/bin/bash
set -o errexit #abort if any command fails
me=$(basename "$0")

help_message="\
Usage: $me [-c FILE] [<options>]
Deploy generated files to a git branch.
Options:
-h, --help Show this help information.
-v, --verbose Increase verbosity. Useful for debugging.
-e, --allow-empty Allow deployment of an empty directory.
-m, --message MESSAGE Specify the message used when committing on the
deploy branch.
-n, --no-hash Don't append the source commit's hash to the deploy
commit's message.
-c, --config-file PATH Override default & environment variables' values
with those in set in the file at 'PATH'. Must be the
first option specified.
Variables:
GIT_DEPLOY_DIR Folder path containing the files to deploy.
GIT_DEPLOY_BRANCH Commit deployable files to this branch.
GIT_DEPLOY_REPO Push the deploy branch to this repository.
These variables have default values defined in the script. The defaults can be
overridden by environment variables. Any environment variables are overridden
by values set in a '.env' file (if it exists), and in turn by those set in a
file specified by the '--config-file' option."

parse_args() {
# Set args from a local environment file.
if [ -e ".env" ]; then
source .env
fi

# Set args from file specified on the command-line.
if [[ $1 = "-c" || $1 = "--config-file" ]]; then
source "$2"
shift 2
fi

# Parse arg flags
# If something is exposed as an environment variable, set/overwrite it
# here. Otherwise, set/overwrite the internal variable instead.
while : ; do
if [[ $1 = "-h" || $1 = "--help" ]]; then
echo "$help_message"
return 0
elif [[ $1 = "-v" || $1 = "--verbose" ]]; then
verbose=true
shift
elif [[ $1 = "-e" || $1 = "--allow-empty" ]]; then
allow_empty=true
shift
elif [[ ( $1 = "-m" || $1 = "--message" ) && -n $2 ]]; then
commit_message=$2
shift 2
elif [[ $1 = "-n" || $1 = "--no-hash" ]]; then
GIT_DEPLOY_APPEND_HASH=false
shift
else
break
fi
done

# Set internal option vars from the environment and arg flags. All internal
# vars should be declared here, with sane defaults if applicable.

# Source directory & target branch.
deploy_directory=${GIT_DEPLOY_DIR:-dist/demo}
deploy_branch=${GIT_DEPLOY_BRANCH:-gh-pages}

#if no user identity is already set in the current git environment, use this:
default_username=${GIT_DEPLOY_USERNAME:-deploy.sh}
default_email=${GIT_DEPLOY_EMAIL:-}

#repository to deploy to. must be readable and writable.
repo=${GIT_DEPLOY_REPO:-origin}

#append commit hash to the end of message by default
append_hash=${GIT_DEPLOY_APPEND_HASH:-true}
}

main() {
parse_args "$@"

enable_expanded_output

if ! git diff --exit-code --quiet --cached; then
echo Aborting due to uncommitted changes in the index >&2
return 1
fi

commit_title=`git log -n 1 --format="%s" HEAD`
commit_hash=` git log -n 1 --format="%H" HEAD`

#default commit message uses last title if a custom one is not supplied
if [[ -z $commit_message ]]; then
commit_message="publish: $commit_title"
fi

#append hash to commit message unless no hash flag was found
if [ $append_hash = true ]; then
commit_message="$commit_message"$'\n\n'"generated from commit $commit_hash"
fi

previous_branch=`git rev-parse --abbrev-ref HEAD`

if [ ! -d "$deploy_directory" ]; then
echo "Deploy directory '$deploy_directory' does not exist. Aborting." >&2
return 1
fi

# must use short form of flag in ls for compatibility with OS X and BSD
if [[ -z `ls -A "$deploy_directory" 2> /dev/null` && -z $allow_empty ]]; then
echo "Deploy directory '$deploy_directory' is empty. Aborting. If you're sure you want to deploy an empty tree, use the --allow-empty / -e flag." >&2
return 1
fi

if git ls-remote --exit-code $repo "refs/heads/$deploy_branch" ; then
# deploy_branch exists in $repo; make sure we have the latest version

disable_expanded_output
git fetch --force $repo $deploy_branch:$deploy_branch
enable_expanded_output
fi

# check if deploy_branch exists locally
if git show-ref --verify --quiet "refs/heads/$deploy_branch"
then incremental_deploy
else initial_deploy
fi

restore_head
}

initial_deploy() {
git --work-tree "$deploy_directory" checkout --orphan $deploy_branch
git --work-tree "$deploy_directory" add --all
commit+push
}

incremental_deploy() {
#make deploy_branch the current branch
git symbolic-ref HEAD refs/heads/$deploy_branch
#put the previously committed contents of deploy_branch into the index
git --work-tree "$deploy_directory" reset --mixed --quiet
git --work-tree "$deploy_directory" add --all

set +o errexit
diff=$(git --work-tree "$deploy_directory" diff --exit-code --quiet HEAD --)$?
set -o errexit
case $diff in
0) echo No changes to files in $deploy_directory. Skipping commit.;;
1) commit+push;;
*)
echo git diff exited with code $diff. Aborting. Staying on branch $deploy_branch so you can debug. To switch back to master, use: git symbolic-ref HEAD refs/heads/master && git reset --mixed >&2
return $diff
;;
esac
}

commit+push() {
set_user_id
git --work-tree "$deploy_directory" commit -m "$commit_message"

disable_expanded_output
#--quiet is important here to avoid outputting the repo URL, which may contain a secret token
git push --quiet $repo $deploy_branch
enable_expanded_output
}

#echo expanded commands as they are executed (for debugging)
enable_expanded_output() {
if [ $verbose ]; then
set -o xtrace
set +o verbose
fi
}

#this is used to avoid outputting the repo URL, which may contain a secret token
disable_expanded_output() {
if [ $verbose ]; then
set +o xtrace
set -o verbose
fi
}

set_user_id() {
if [[ -z `git config user.name` ]]; then
git config user.name "$default_username"
fi
if [[ -z `git config user.email` ]]; then
git config user.email "$default_email"
fi
}

restore_head() {
if [[ $previous_branch = "HEAD" ]]; then
#we weren't on any branch before, so just set HEAD back to the commit it was on
git update-ref --no-deref HEAD $commit_hash $deploy_branch
else
git symbolic-ref HEAD refs/heads/$previous_branch
fi

git reset --mixed
}

filter() {
sed -e "s|$repo|\$repo|g"
}

sanitize() {
"$@" 2> >(filter 1>&2) | filter
}

[[ $1 = --source-only ]] || main "$@"
34 changes: 34 additions & 0 deletions scripts/generate-scss-from-mdl-scss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node
'use strict';

// extract scss files and put them into scss/mdl folder. Run: npm run generate-scss-from-mdl-scss

const fs = require('fs');
const path = require('path');
const glob = require('glob');
const ncp = require('ncp').ncp;

const destPath = 'projects/core/src/scss/mdl';
var basePath = process.cwd();
var source = path.resolve(basePath, 'node_modules/material-design-lite/src');
var dest = path.resolve(basePath, destPath);


fs.mkdirSync(destPath);

ncp(source, dest, {
filter: function (fileName) {
if (fileName.endsWith('snippets')) {
return false;
}
if (fs.statSync(fileName).isDirectory()) {
return true;
}
return fileName.endsWith('.scss');
}
}, function (err) {
if (err) {
return console.error(err);
}
console.log('done!');
});
5 changes: 5 additions & 0 deletions scripts/setup-github-access.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
echo "machine github.com" >> ~/.netrc
echo " login seemann@mseemann.de" >> ~/.netrc
echo " password $github_token" >> ~/.netrc
2 changes: 1 addition & 1 deletion to-be-removed/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular2-mdl",
"version": "0.0.0",
"description": "Angular 2-6 components, directives and styles based on material design lite https://getmdl.io.",
"description": "Angular 2-8 components, directives and styles based on material design lite https://getmdl.io.",
"keywords": [],
"homepage": "http://mseemann.io/angular2-mdl/",
"license": "MIT",
Expand Down
Empty file removed to-be-removed/public/.npmignore
Empty file.

0 comments on commit 9570c57

Please sign in to comment.