Skip to content

Commit

Permalink
Update release script
Browse files Browse the repository at this point in the history
  • Loading branch information
hzalaz committed Dec 5, 2016
1 parent ef5830d commit 1769e1a
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 2 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Change Log

## [1.0.0](https://github.com/auth0/lock/tree/1.0.0) (2016-10-25)
[Full Changelog](https://github.com/auth0/lock/tree/1.0.0)

Java library with focus on Android that provides Json Web Token (JWT) decoding.

## Install
The library is be available both in Maven Central and JCenter. To start using it add this line to your `build.gradle` dependencies file:

```groovy
compile 'com.auth0.android:jwtdecode:1.0.0'
```

## Usage

Decode a JWT token

```java
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ";
JWT jwt = new JWT(token);
```

A `DecodeException` will raise with a detailed message if the token has:
* An invalid part count.
* A part not encoded as Base64 + UTF-8.
* A Header or Payload without a valid JSON format.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ allprojects {

task clean(type: Delete) {
delete rootProject.buildDir
delete 'CHANGELOG.md.release'
}
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.library'
apply from: '../scripts/jacoco.gradle'
apply from: '../scripts/release.gradle'

def semver = defineVersion()
version = semver.stringVersion
logger.lifecycle("Using version ${version} for ${name}")

android {
compileSdkVersion 24
Expand Down
10 changes: 10 additions & 0 deletions scripts/maven.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ install {
}
}
developers {
developer {
id 'auth0'
name 'Auth0'
email '[email protected]'
}
developer {
id 'lbalmaceda'
name 'Luciano Balmaceda'
email '[email protected]'
}
developer {
id 'hzalaz'
name 'Hernan Zalazar'
Expand Down
172 changes: 172 additions & 0 deletions scripts/release.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import java.text.SimpleDateFormat

apply plugin: ReleasePlugin

class Semver {
String version
def snapshot

def getStringVersion() {
return snapshot ? "$version-SNAPSHOT" : version
}

def nextPatch() {
def parts = version.split("\\.")
def patch = Integer.parseInt(parts[2]) + 1
return "${parts[0]}.${parts[1]}.${patch}"
}

def nextMinor() {
def parts = version.split("\\.")
def minor = Integer.parseInt(parts[1]) + 1
return "${parts[0]}.${minor}.0"
}

}

class ChangeLogTask extends DefaultTask {

def current
def next

@TaskAction
def update() {
def repository = project.oss.library
def file = new File('CHANGELOG.md')
def output = new File('CHANGELOG.md.release')
output.newWriter().withWriter { writer ->

file.eachLine { line, number ->
if (number == 0 && !line.startsWith('# Change Log')) {
throw new GradleException('Change Log file is not properly formatted')
}

writer.println(line)

if (number == 0 || number > 1) {
return
}

def formatter = new SimpleDateFormat('yyyy-MM-dd')
writer.println()
writer.println("## [${next}](https://github.com/auth0/${repository}/tree/${next}) (${formatter.format(new Date())})")
writer.println("[Full Changelog](https://github.com/auth0/${repository}/compare/${current}...${next})")
def command = ["curl", "https://webtask.it.auth0.com/api/run/wt-hernan-auth0_com-0/oss-changelog.js?webtask_no_cache=1&repo=${repository}&milestone=${next}", "-f", "-s", "-H", "Accept: text/markdown"]
def content = command.execute()
content.consumeProcessOutputStream(writer)
if (content.waitFor() != 0) {
throw new GradleException("Failed to request changelog for version ${next}")
}
}
}
file.delete()
output.renameTo('CHANGELOG.md')
}
}

class ReleaseTask extends DefaultTask {

def tagName

@TaskAction
def perform() {
def path = project.getRootProject().getProjectDir().path
project.exec {
commandLine 'git', 'add', 'README.md'
workingDir path
}
project.exec {
commandLine 'git', 'add', 'CHANGELOG.md'
workingDir path
}
project.exec {
commandLine 'git', 'commit', '-m', "Release ${tagName}"
workingDir path
}
project.exec {
commandLine 'git', 'tag', "${tagName}"
workingDir path
}
}
}

class ReadmeTask extends DefaultTask {

def current
def next

final filename = 'README.md'

@TaskAction
def update() {
def file = new File(filename)
def updated = "compile '${project.group}:${project.name}:${next}'"
def oldSingleQuote = "compile '${project.group}:${project.name}:${current}'"
def oldDoubleQuote = "compile \"${project.group}:${project.name}:${current}\""
def contents = file.getText('UTF-8')
contents = contents.replace(oldSingleQuote, updated).replace(oldDoubleQuote, updated)
file.write(contents, 'UTF-8')
}
}

class Auth0ReleasePluginExtension {
String library
}

class ReleasePlugin implements Plugin<Project> {
void apply(Project target) {
def semver = current()
target.extensions.create('oss', Auth0ReleasePluginExtension)
target.version = semver.stringVersion
def version = semver.version
def nextMinor = semver.nextMinor()
def nextPatch = semver.nextPatch()
target.task('changelogMinor', type: ChangeLogTask) {
current = version
next = nextMinor
}
target.task('changelogPatch', type: ChangeLogTask) {
current = version
next = nextPatch
}
target.task('readmeMinor', type: ReadmeTask, dependsOn: 'changelogMinor') {
current = version
next = nextMinor
}
target.task('readmePatch', type: ReadmeTask, dependsOn: 'changelogPatch') {
current = version
next = nextPatch
}
target.task('releaseMinor', type: ReleaseTask, dependsOn: 'readmeMinor') {
tagName = nextMinor
}
target.task('releasePatch', type: ReleaseTask, dependsOn: 'readmePatch') {
tagName = nextPatch
}
}

static def current() {
def current = describeGit(false)
def snapshot = current == null
if (snapshot) {
current = describeGit(snapshot, '0.0.1')
}
return new Semver(snapshot: snapshot, version: current)
}

static def describeGit(boolean snapshot, String defaultValue = null) {
def command = ['git', 'describe', '--tags', (snapshot ? '--abbrev=0' : '--exact-match')].execute()
def stdout = new ByteArrayOutputStream()
def errout = new ByteArrayOutputStream()
command.consumeProcessOutput(stdout, errout)
if (command.waitFor() != 0) {
Logging.getLogger(ReleasePlugin.class).debug(errout.toString())
return defaultValue
}
if (stdout.toByteArray().length > 0) {
return stdout.toString().replace('\n', "")
}

return defaultValue
}
}

0 comments on commit 1769e1a

Please sign in to comment.