Commits

Patrick Mézard committed 582821a

csharp: add script to publish on nuget

Comments (0)

Files changed (3)

csharp/PhoneNumbers/PhoneNumbers.nuspec

+<?xml version="1.0" encoding="UTF-8"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+  <metadata>
+    <id>libphonenumber-csharp</id>
+    <version>$version$</version>
+    <authors>Patrick Mézard, Google, libphonenumber contributors</authors>
+    <owners>Patrick Mézard</owners>
+    <licenseUrl>http://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
+    <projectUrl>https://bitbucket.org/pmezard/libphonenumber-csharp/wiki/Home</projectUrl>
+    <requireLicenseAcceptance>true</requireLicenseAcceptance>
+    <description>
+		C# port of Google's common Java, C++ and Javascript library for parsing, formatting, storing and validating international phone numbers.
+		For usage samples: http://code.google.com/p/libphonenumber/
+    </description>
+    <tags>phonenumber phone</tags>
+  </metadata>
+</package>

Binary file added.

csharp/lib/publish.py

+import os, subprocess, shutil
+
+class Ui:
+    def __init__(self):
+        rootdir = os.path.join(os.path.dirname(__file__), '../..')
+        rootdir = os.path.abspath(rootdir)
+        self.rootdir = rootdir
+
+    def nuget(self, args):
+        nuget = os.path.join(ui.rootdir, 'csharp/lib/nuget.exe')
+        r = subprocess.call([nuget] + args)
+        return r
+
+def haschanges(ui):
+    p = subprocess.Popen(['hg', '-R', ui.rootdir, 'id', '-n'],
+                         shell=True,
+                         stdout=subprocess.PIPE)
+    stdout = p.communicate()[0]
+    return stdout.strip().endswith('+')
+
+def purge(ui):
+    subprocess.check_call(['hg', '-R', ui.rootdir, 'purge', '--all'],
+                          shell=True)
+
+def build(ui):
+    csproj = os.path.join(ui.rootdir, 'csharp/PhoneNumbers/PhoneNumbers.csproj')
+    outdir = os.path.join(ui.rootdir, 'csharp/packages')
+    if os.path.exists(outdir):
+        shutil.rmtree(outdir)
+    os.makedirs(outdir)
+    r = ui.nuget(['pack', csproj,
+                  '-Properties', 'Configuration=Release',
+                  '-OutputDirectory', outdir,
+                  '-verbose',
+                  '-symbols',
+                  '-build'])
+    if r:
+        raise Exception('nuget pack failed')
+
+def push(ui):
+    outdir = os.path.join(ui.rootdir, 'csharp/packages')
+    nupkg = [f for f in sorted(os.listdir(outdir)) if f.endswith('.nupkg')][0]
+    nupkg = os.path.join(outdir, nupkg)
+    ui.nuget(['push', nupkg])
+
+if __name__ == '__main__':
+    ui = Ui()
+    if haschanges(ui):
+        raise Exception('abort: local changes found')
+    purge(ui)
+    build(ui)
+    push(ui)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.