3a249adaa6f9 — Duncan Ross Palmer tip 9 months ago
* ca0a29fe615f: Finished feature
  * 40643e6ee034: Don't keep the publish file
  * 33df2319f45c: hg id seems broken
  * 2917a9dbaa51: Try not to publish and make sure we update after first publish
  * 2cad75072683: Improve publishing to avoid unnecessary publishes
3 files changed, 42 insertions(+), 17 deletions(-)

M .hgignore
M Makefile
A => bin/publish.sh
M .hgignore +1 -0
@@ 2,3 2,4 @@ syntax: glob
 
 handler.zip
 cover_db
+.build/publish

          
M Makefile +2 -17
@@ 1,9 1,5 @@ 
 #!/usr/bin/env make -f
 
-FUNCTION="callsign-perl"
-REGION=eu-west-2
-PROFILE=default
-
 all : handler.zip
 
 __cleandb:

          
@@ 15,20 11,9 @@ clean: __cleandb
 handler.zip: FORCE
 	zip --recurse-paths handler.zip lib handler.pl
 
+update: publish
 publish : test all
-	aws --region ${REGION} --profile ${PROFILE} lambda create-function \
-		--function-name ${FUNCTION} \
-		--zip-file "fileb://handler.zip" \
-		--handler "handler.handle" \
-		--runtime provided \
-		--role arn:aws:iam::979393143841:role/lambda_basic_execution \
-		--layers "arn:aws:lambda:eu-west-2:445285296882:layer:perl-5-30-runtime:4" \
-			"arn:aws:lambda:eu-west-2:979393143841:layer:moose:49"
-
-update : test all
-	aws --region ${REGION} --profile ${PROFILE} lambda update-function-code \
-		--function-name ${FUNCTION} \
-		--zip-file fileb://handler.zip
+	bin/publish.sh
 
 check: test
 test: __cleandb

          
A => bin/publish.sh +39 -0
@@ 0,0 1,39 @@ 
+#!/bin/sh
+
+set -e
+
+HASHFILE=".build/publish"
+REGION=eu-west-2
+FUNCTION="callsign-perl"
+PROFILE=default
+
+hash=`hg log -r tip --template '{node}'`
+
+if [ -f "$HASHFILE" ]; then
+	oldhash=`cat $HASHFILE`
+	if [ "$oldhash" = "$hash" ]; then
+		echo "$oldhash: No changes detected, skipping publishing"
+		exit 0
+	fi
+
+	aws --region ${REGION} --profile ${PROFILE} lambda update-function-code \
+		--function-name ${FUNCTION} \
+		--zip-file fileb://handler.zip
+else
+	# We have never published before (or you'll need to put the revsion in the file
+	# in order to fix this.
+
+	aws --region ${REGION} --profile ${PROFILE} lambda create-function \
+		--function-name ${FUNCTION} \
+		--zip-file "fileb://handler.zip" \
+		--handler "handler.handle" \
+		--runtime provided \
+		--role arn:aws:iam::979393143841:role/lambda_basic_execution \
+		--layers "arn:aws:lambda:eu-west-2:445285296882:layer:perl-5-30-runtime:4" \
+			"arn:aws:lambda:eu-west-2:979393143841:layer:moose:49"
+fi
+
+echo $hash > "$HASHFILE.tmp"
+mv "$HASHFILE.tmp" "$HASHFILE"
+
+exit 0