Skip to content

Commit

Permalink
Github Actions with minor fixes (#11)
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
mcred authored and Eric Schrock committed Sep 23, 2019
1 parent f7c6f23 commit 27891cd
Show file tree
Hide file tree
Showing 21 changed files with 217 additions and 49 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish

on: create

jobs:
build:
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, macOS-10.14]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '8.0.212'
- name: Setup Env
run: ./scripts/setup.sh ${{ matrix.os }}
- name: Build Jar
run: ./scripts/compile-maven.sh
- name: Compile Binary
if: startsWith(github.ref, 'refs/tags/')
run: ./scripts/build.sh ${{ matrix.os }}
- name: Upload ${{ matrix.os }} Binary
if: matrix.os == 'macOS-10.14'
uses: actions/upload-artifact@master
with:
name: titan-cli-0.3.0-darwin_amd64.zip
path: releases
- name: Upload ${{ matrix.os }} Binary
if: matrix.os == 'ubuntu-18.04'
uses: actions/upload-artifact@master
with:
name: titan-cli-0.3.0-linux_amd64.zip
path: releases
release:
name: Draft Release
runs-on: ubuntu-18.04
needs: build
steps:
- uses: actions/checkout@v1
- uses: actions/download-artifact@master
with:
name: titan-cli-0.3.0-darwin_amd64.zip
path: releases
- uses: actions/download-artifact@master
with:
name: titan-cli-0.3.0-linux_amd64.zip
path: releases
- name: Draft Release
if: startsWith(github.ref, 'refs/tags/')
run: ./scripts/draft-release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Pull Request

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
test:
name: Test on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, windows-2019, macOS-10.14]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '8.0.212'
- name: Run Maven Tests
run: uname -a
4 changes: 2 additions & 2 deletions scripts/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ ${entry} native-image -cp /cli/target/titan-$version-jar-with-dependencies.jar\
--enable-http\
--enable-https

${entry} mkdir -p /cli/releases/${version}
${entry} tar -cvf /cli/releases/${version}/titan-cli-$version-linux_amd64.zip titan
${entry} mkdir -p /cli/releases/
${entry} tar -cvf /cli/releases/titan-cli-$version-linux_amd64.zip titan
4 changes: 2 additions & 2 deletions scripts/build-osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ native-image -cp ${PWD}/target/titan-$version-jar-with-dependencies.jar\
--enable-http\
--enable-https

mkdir -p ${PWD}/releases/${version}
zip ${PWD}/releases/${version}/titan-cli-$version-darwin_amd64.zip titan
mkdir -p ${PWD}/releases/
zip ${PWD}/releases/titan-cli-$version-darwin_amd64.zip titan
15 changes: 15 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

os=$1

#Setup Linux
if [ $os = "ubuntu-18.04" ]; then
${PWD}/scripts/build-linux.sh
fi

#Setup OSX
if [ $os = "macOS-10.14" ]; then
export PATH=${PWD}/graalvm-ce-19.0.0/Contents/Home/bin:$PATH
export JAVA_HOME=${PWD}/graalvm-ce-19.0.0/Contents/Home/jre
${PWD}/scripts/build-osx.sh
fi
32 changes: 32 additions & 0 deletions scripts/draft-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e
set -o pipefail

if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

RELEASE=${GITHUB_REF##*/}
body='{
"tag_name": "'${RELEASE}'",
"target_commitish": "master",
"name": "'${RELEASE}'",
"body": "Draft release for '${RELEASE}'",
"draft": true,
"prerelease": false
}'

#Draft Release
RAW_URL=$(curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
--data "$body" "https://api.github.com/repos/$GITHUB_REPOSITORY/releases" |
jq -r '.upload_url')

#Prepare Upload
UPLOAD_URL="${RAW_URL%/*}"

echo $UPLOAD_URL
for file in ${PWD}/releases/*.zip; do
${PWD}/scripts/upload_asset.sh "$UPLOAD_URL/assets?name=$(basename $file)" $file
done
9 changes: 0 additions & 9 deletions scripts/release-prepare.sh

This file was deleted.

18 changes: 18 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

os=$1

#Setup Linux
if [ $os = "ubuntu-18.04" ]; then
echo $os
fi

#Setup OSX
if [ $os = "macOS-10.14" ]; then
echo $os
curl -L https://github.com/oracle/graal/releases/download/vm-19.0.0/graalvm-ce-darwin-amd64-19.0.0.tar.gz --output graal.tar.gz
gunzip -c graal.tar.gz | tar xopf -
export PATH=${PWD}/graalvm-ce-19.0.0/Contents/Home/bin:$PATH
export JAVA_HOME=${PWD}/graalvm-ce-19.0.0/Contents/Home/jre
gu install native-image
fi
16 changes: 16 additions & 0 deletions scripts/upload_asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e
set -o pipefail

UPLOAD_URL=$1
FILE=$2
SIZE=$(wc -c $FILE | awk '{print $1}')


#Upload Asset
curl \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Length: $SIZE"\
-H "Content-Type: application/zip" \
--data-binary @$FILE "$UPLOAD_URL"
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ private const val DEFAULT_COLOR = "\u001B[0m"


class PrintStreamProgressTracker(
private val successMessage: String,
private val failureMessage: String = "Failed",
private val tasksPrefix: String = "",
private val printStream: PrintStream = System.out,
private val animation: Array<Char> = arrayOf('-', '\\', '|', '/', '-', '\\', '|', '/'),
private val refreshRateInMillis: Long = 250L): ProgressTracker {

private val successMessage: String,
private val failureMessage: String = "Failed",
private val tasksPrefix: String = "",
private val printStream: PrintStream = System.out,
private val animation: Array<Char> = arrayOf('-', '\\', '|', '/', '-', '\\', '|', '/'),
private val refreshRateInMillis: Long = 250L): ProgressTracker
{
private val tasks: MutableList<String> = ArrayList(2)
private var clearTasks: Boolean = false
private var isMonitorStarted: Boolean = false
private val monitor: Thread = createMonitor()
private var failedTask: String = ""
private var hasFailed = false

private val n = System.lineSeparator()

override fun pushTask(taskName: String) {
tasks.add(taskName)
startMonitorIfNeeded()
Expand Down Expand Up @@ -82,9 +84,9 @@ class PrintStreamProgressTracker(
private fun printDone(taskName: String) {
val taskIsSuccess = failedTask != taskName
if (taskIsSuccess)
printStream.print("\r$tasksPrefix$DARK_GREEN$taskName$DEFAULT_COLOR\r\n")
printStream.print("$tasksPrefix$DARK_GREEN$taskName$DEFAULT_COLOR${n}")
else
printStream.print("\r$tasksPrefix${DARK_RED}X $taskName$DEFAULT_COLOR\r\n")
printStream.print("$tasksPrefix${DARK_RED}X $taskName$DEFAULT_COLOR${n}")
}

private fun waitMillis(millis: Long): Boolean {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/titandata/titan/commands/Migrate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import org.kodein.di.generic.bind
import org.kodein.di.generic.inSet
import org.kodein.di.generic.provider

private val n = System.lineSeparator()

class Migrate : CliktCommand(
help = "Migrate an existing docker database container to titan repository",
epilog = "Container becomes the new name of the docker container.\n\nExample: `titan migrate -s oldPostgres titanPostgres`"
epilog = "Container becomes the new name of the docker container.${n}${n}Example: `titan migrate -s oldPostgres titanPostgres`"
) {
private val dependencies: Dependencies by requireObject()
private val repository by argument()
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/titandata/titan/commands/Run.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ import org.kodein.di.generic.bind
import org.kodein.di.generic.inSet
import org.kodein.di.generic.provider

private val n = System.lineSeparator()

class Run : CliktCommand(
help = "Create repository and start container",
epilog = "Containers that contain a repository are launched using docker run arguments and passed verbatim using `--` as the flag.\n\nExample: `titan run -- --name newRepo -d -p 5432:5432 postgres:10`"
epilog = "Containers that contain a repository are launched using docker run arguments and passed verbatim using `--` as the flag.${n}${n}Example: `titan run -- --name newRepo -d -p 5432:5432 postgres:10`"
) {
private val dependencies: Dependencies by requireObject()
private val arguments by argument().multiple()
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/io/titandata/titan/providers/Local.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Local: Provider {
private val docker = Docker(commandExecutor)
private val repositoriesApi = RepositoriesApi()

private val n = System.lineSeparator()

private fun exit(message:String, code: Int = 1) {
println(message)
exitProcess(code)
Expand Down Expand Up @@ -123,9 +125,9 @@ class Local: Provider {
}

override fun list() {
System.out.printf("%-20s %s\n", "CONTAINER", "STATUS")
System.out.printf("%-20s %s${n}", "CONTAINER", "STATUS")
for (container in getContainersStatus()) {
System.out.printf("%-20s %s\n", container.name, container.status)
System.out.printf("%-20s %s${n}", container.name, container.status)
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/titandata/titan/providers/local/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import io.titandata.client.apis.CommitsApi
class Log (
private val commitsApi: CommitsApi = CommitsApi()
) {
private val n = System.lineSeparator()

fun log(container: String) {
var first = true
for (commit in commitsApi.listCommits(container)) {
Expand All @@ -30,7 +32,7 @@ class Log (
}
println("Date: ${metadata["timestamp"]}")
if (metadata["message"] != "") {
println("\n${metadata["message"]}")
println("${n}${metadata["message"]}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class Migrate (
val arguments = mutableListOf("-d","--label","io.titandata.titan")
val repo = Repository(name, emptyMap())
repositoriesApi.createRepository(repo)
var i = 0
for (path in volumes.keys()) {
val volumeName = "$name/v1"
val volumeName = "$name/v$i"
println("Creating docker volume $volumeName with path $path")
docker.createVolume(volumeName, path)
val localSrc = getLocalSrcFromPath(path, containerInfo as JSONObject)
Expand All @@ -71,6 +72,7 @@ class Migrate (
}
arguments.add("--mount")
arguments.add("type=volume,src=$volumeName,dst=$path,volume-driver=titan")
i++
}

val ports = containerInfo.getJSONObject("HostConfig").optJSONObject("PortBindings")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import io.titandata.client.apis.RemotesApi
class RemoteList (
private val remotesApi: RemotesApi = RemotesApi()
) {
private val n = System.lineSeparator()

fun list(container: String) {
val remotes = remotesApi.listRemotes(container)
System.out.printf("%-20s %s\n", "REMOTE", "PROVIDER")
System.out.printf("%-20s %s${n}", "REMOTE", "PROVIDER")
for (remote in remotes) {
System.out.printf("%-20s %s\n", remote.name, remote.provider)
System.out.printf("%-20s %s${n}", remote.name, remote.provider)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class RemoteLog (
private val remotesApi: RemotesApi = RemotesApi(),
private val remoteUtil: RemoteUtil = RemoteUtil()
) {

private val n = System.lineSeparator()

private fun getRemotes(container: String, remoteName: String?): Array<Remote> {
return try {
when (remoteName.isNullOrBlank()) {
Expand Down Expand Up @@ -59,7 +60,7 @@ class RemoteLog (
}
println("Date: ${commit.properties["timestamp"]}")
if (commit.properties["message"] != "") {
println("\n${commit.properties["message"]}")
println("${n}${commit.properties["message"]}")
}
}
} catch (e: ClientException) {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/io/titandata/titan/providers/local/Run.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Run (
exit("Container name cannot contain a slash",1)
}
val image = arguments.last()
docker.pull(image)
val imageInfo = docker.inspectImage(image)
if (imageInfo == null) {
exit("Image information is not available",1)
Expand Down
Loading

0 comments on commit 27891cd

Please sign in to comment.