Permalink
Browse files

doc: Nicer sample, preparation for Jenkins

  • Loading branch information...
MikeMitterer committed Jun 27, 2018
1 parent 76f1ca6 commit fb9fe14fb40ca2d7a1ce900db2f059036f92f631
@@ -18,7 +18,9 @@ Then, run `pub get` to download and link in the package.

## Sample

Check out the sample on [GitHub](https://github.com/MikeMitterer/m4d_router/tree/route_version/example/browser)
Live: [samples.m4d.router.mikemitterer.at](http://samples.m4d.router.mikemitterer.at.s3-website-eu-west-1.amazonaws.com/)
http://samples.mikemitterer.at.s3-website-eu-west-1.amazonaws.com/m4d_router/
Source - check it out on [GitHub](https://github.com/MikeMitterer/m4d_router/tree/route_version/example/browser)

```dart
void main() {
@@ -10,6 +10,7 @@ pipeline {
sh 'pub update'
}
}

}
}
stage('Analyze') {
@@ -30,6 +31,14 @@ pipeline {
}
}
}

stage('Deploy samples') {
steps {
ansiColor('xterm') {
sh 'deploy-samples -p --force'
}
}
}
}
}

@@ -0,0 +1,149 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Deploys sample to Amazon S3
#
# S3 bucket name must be defined in a .s3-file for each sample
# -----------------------------------------------------------------------------

# Vars die in .bashrc gesetzt werden. ~ (DEV_DOCKER, DEV_SEC, DEV_LOCAL) ~~~~~~
# [] müssen entfernt werden (IJ Bug https://goo.gl/WJQGMa)
if [ -z ${DEV_DOCKER+set} ]; then echo "Var 'DEV_DOCKER' nicht gesetzt!"; exit 1; fi
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# Abbruch bei Problemen (https://goo.gl/hEEJCj)
#
# Wenn ein Fehler nicht automatisch zu einem exit führen soll dann
# kann 'command || true' verwendet werden
#
# Für die $1, $2 Abfragen kann 'CMDLINE=${1:-}' verwendet werden
#
# -e Any subsequent(*) commands which fail will cause the shell script to exit immediately
# -o pipefail sets the exit code of a pipeline to that of the rightmost command
# -u treat unset variables as an error and exit
# -x print each command before executing it
set -eou pipefail

APPNAME="`basename $0`"

SCRIPT=`realpath $0`
SCRIPTPATH=`dirname ${SCRIPT}`

#------------------------------------------------------------------------------
# BASIS

LOGFILE="${APPNAME}_`date +"%Y%m%d"`.log"

declare -a SAMPLES=(
"example/browser"
)

DOW=$(date +"%u")
PUBLISH_ONLY_ON_DAY=1

#------------------------------------------------------------------------------
# Functions
#

sampleFunction() {
MESSAGE=${1?sampleFunction muss mind. einen Param haben}
OPTIONAL=${2-default value}
#OPTIONAL=${2}

# Test if Var exists (the right way) https://goo.gl/jaUpJ8
if [ -n "${2+set}" ]
then
echo "${MESSAGE} - ${OPTIONAL}"
else
echo "${MESSAGE}"
fi
}

#
# Usage: listSamples "${SAMPLES[@]}"
#
listSamples() {
local SAMPLES=("${@}")

echo $OPTION

# Loop Through ARRAY
for SAMPLE in "${SAMPLES[@]}"
do
local S3BUCKET=$(cat "${SAMPLE}/.s3" | sed -e "s/^#.*$//g" -e "/^$/d" | head -n 1)
echo "${SAMPLE} / S3-Bucket: ${S3BUCKET}..."
done
}

#
# Usage: publishSamples "${SAMPLES[@]}"
#
publishSamples() {
local SAMPLES=("${@}")

#
# Strings: if [ "$x" == "valid" ]; then
# if [ "$x" != "valid" ]; then
# Numbers: if [ (("$x" == 99)) ]; then
# if [ (("$x" != 99)) ]; then
#
if [[ "${OPTION}" == "" && (("${DOW}" != "${PUBLISH_ONLY_ON_DAY}")) ]]; then
echo "Sorry - today is not a publishing day. "
echo "To force publishing use '--force'"
exit 0
fi


# Loop Through ARRAY
for SAMPLE in "${SAMPLES[@]}"
do
local S3BUCKET=$(cat "${SAMPLE}/.s3" | sed -e "s/^#.*$//g" -e "/^$/d" | head -n 1)

cd ${SAMPLE}
pub update

# Set current date in index.html
sed -i -e "s#\<span class=\"pubdate\"\>[^<]*\</span\>#<span class=\"pubdate\">$(date +"%Y-%m-%d / %H:%M")</span>#g" web/index.html

# Dart build
pub run build_runner build --output web:deploy

# Sync to Amazon (root dir: browser)
aws s3 sync --delete deploy/ s3://${S3BUCKET}

done
}

#------------------------------------------------------------------------------
# Options
#

usage() {
echo
echo "Usage: ${APPNAME} [ options ]"
echo -e "\t-l | --list Shows all samples"
echo -e "\t-p | --publish [--force] Publish samples to AWS/S3 (only on day ${PUBLISH_ONLY_ON_DAY})"
echo -e "\t use --force to ignore Monday as publishing day"
}


CMDLINE=${1:-}
OPTION=${2:-}
case "${CMDLINE}" in
-l|list|-list|--list)
listSamples "${SAMPLES[@]}"
;;

-p|publish|-publish|--publish)
publishSamples "${SAMPLES[@]}"
;;

-h|-help|--help|*)
usage
;;

esac

#------------------------------------------------------------------------------
# Alles OK...

exit 0
@@ -0,0 +1,2 @@
# Bucket on S3
samples.m4d.router.mikemitterer.at
Oops, something went wrong.

0 comments on commit fb9fe14

Please sign in to comment.