]> www.vanbest.org Git - tv_grab_nl_java/commitdiff
Made upload.pl a but more generic, added upload.sh script to upload the unix and...
authorJan-Pascal van Best <janpascal@vanbest.org>
Mon, 23 Apr 2012 17:49:40 +0000 (19:49 +0200)
committerJan-Pascal van Best <janpascal@vanbest.org>
Mon, 23 Apr 2012 17:49:40 +0000 (19:49 +0200)
.gitignore
upload.pl
upload.sh [new file with mode: 0755]

index b5fbc8d7a9a6c57f469abb6b8654944289e7e253..1e5b6a9f1162cf7ff08f4e31169a51468c5b5313 100644 (file)
@@ -7,3 +7,4 @@
 /tv_grab_nl_java.db.properties
 *.orig
 /github-token
+.*.swp
index f0620e8f29fd2c8ccf3816d9c9254aa174f09a0e..848218eb701c340a44990087174b323194c85038 100755 (executable)
--- a/upload.pl
+++ b/upload.pl
@@ -2,8 +2,46 @@
 use strict;
 use warnings;
 use Pithub::Repos::Downloads;
+use Getopt::Long;
+use File::Basename;
 
-my $version = shift();
+# Perl script to upload file to the github download
+# section. Called by upload.sh
+sub usage
+{
+  print "Unknown option: @_\n" if ( @_ );
+  print "usage: program --location PATH [--filename FILENAME] [--description DESC] [--content-type] [--help|-?]\n";
+  print "       location:    file to upload, e.g.  \"../tv_grab_nl_java-0.9.1.zip\"\n";
+  print "       filename:    remote filename, defaults to basename of location\n";
+  print "       description: defaults to \"tv_grab_nl_java release <version>\"\n";
+  print "       content-type: defaults to \"application/zip\"\n";
+  exit;
+}
+
+my ($version, $filename, $location, $description, $content_type, $help);
+  
+#-- prints usage if no command line parameters are passed or there is an unknown
+#   parameter or help option is passed
+usage($ARGV) if ( @ARGV < 1 or
+            ! GetOptions('help|?' => \$help, 
+            'filename=s' => \$filename, 
+            'location=s' => \$location, 
+            'description:s' => \$description, 
+            'content-type:s' => \$content_type, 
+            ) or defined $help );
+   
+die("--location is obligatory") if !defined($location);
+
+if (!defined($description)) {
+  $description = "tv_grab_nl_java release $version";
+}
+if (!defined($filename)) {
+  $filename = basename($location);
+}
+if (!defined($content_type)) {
+  $content_type = "application/zip";
+}
 
 open(TOKENFILE,'github-token');
 my $token=<TOKENFILE>;
@@ -17,19 +55,24 @@ my $download = Pithub::Repos::Downloads->new(
 
 my $result = $download->create(
     data => {
-        name         => "tv_grab_nl_java-$version.zip",
-        size         => ( stat("../tv_grab_nl_java-$version.zip") )[7],
-        description  => "tv_grab_nl_java release $version" ,
-        content_type => 'application/zip',
+        name         => $filename,
+        size         => ( stat($location) )[7],
+        description  => $description,
+        content_type => $content_type
     },
 );
 
 if ( $result->success ) {
     my $upload = $download->upload(
         result => $result,
-        file   => "../tv_grab_nl_java-$version.zip",
+        file   => $location,
     );
     if ( $upload->is_success ) {
         printf "The file has been uploaded succesfully and is now available at: %s\n", $result->content->{html_url};
+    } else {
+      printf "Error uploading file\n";
     }
+
+} else {
+  printf "Error uploading file (2)\n";
 }
diff --git a/upload.sh b/upload.sh
new file mode 100755 (executable)
index 0000000..f89a394
--- /dev/null
+++ b/upload.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+VERSION=$( xsltproc pom_version.xsl pom.xml )
+
+if [ "$1" != "--testing" ]; then
+  if ! head Changelog | grep -q "tv_grab_nl_java-$VERSION"; then
+    echo "Release $VERSION not found in changelog, please update Changelog first";
+    exit 1;
+  fi
+fi
+
+FILENAME="tv_grab_nl_java-$VERSION.zip"
+EXEFILENAME="Setup-tv_grab_nl_java-$VERSION.exe"
+ZIPFILE="$PWD/../$FILENAME"
+EXEFILE="$PWD/../$EXEFILENAME"
+
+echo "Uploading $ZIPFILE"
+perl ./upload.pl --location "$ZIPFILE" \
+  --description "tv_grab_nl_java release $VERSION" \
+  --content-type "application/zip"
+
+echo "Uploading $EXEFILE"
+perl ./upload.pl --location "$EXEFILE" \
+  --description "tv_grab_nl_java release $VERSION (Windows installer)" \
+  --content-type "application/exe"
+