Skip to content

Commit

Permalink
ci(travis): implement initial release deployment (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
haltcase authored Oct 31, 2018
1 parent fb904e5 commit 6a37e19
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 22 deletions.
52 changes: 52 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
os:
- linux
- osx
- windows

language: c

cache:
directories:
- "$HOME/.nimble"
- "$HOME/.choosenim"
- "$HOME/nim"

branches:
except:
- gh-pages

install:
- |
if [ $TRAVIS_OS_NAME != windows ]; then
export CHOOSENIM_CHOOSE_VERSION=stable
curl https://nim-lang.org/choosenim/init.sh -sSf | sh
fi
- |
if [ $TRAVIS_OS_NAME == windows ]; then
if [ ! -d directory ]; then
curl -sS https://nim-lang.org/download/nim-0.19.0_x64.zip > nim.zip
7z x nim.zip
mv nim-0.19.0 nim
mv nim $HOME/
fi
export PATH=$HOME/nim/bin:$PATH
fi
- export PATH=$HOME/.nimble/bin:$PATH
- nimble refresh -y

script:
- nimble install -y
- nimble build_current

after_script:
- fugitive --version

deploy:
- provider: script
script: bash .travis_release
on:
tags: true

notifications:
email: false
25 changes: 25 additions & 0 deletions .travis_release
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#! /bin/bash

set -u # error on undefined variables
set -e # exit on first error

echo_run () {
printf "\n$*\n"
"$@"
}

asset=$(find dist/fugitive_v*)
notesFile=dist/notes.md

# create a file with only this tag's release notes
echo_run fugitive changelog $notesFile \
-t:$TRAVIS_TAG \
--no-anchor --no-title --no-divider \
-o

# upload the release asset to GitHub
echo_run fugitive release $TRAVIS_TAG \
-r:"$TRAVIS_REPO_SLUG" \
-f:"$asset" \
-D:"$notesFile" \
-p -N
66 changes: 44 additions & 22 deletions fugitive.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ srcDir = "src"
requires "nim >= 0.19.0 & < 0.20.0"
requires "tempfile >= 0.1.5"

import ospaths, strutils
import ospaths, strformat, strutils

const
flags_win_64 = "--os:windows --cpu:amd64"
Expand All @@ -21,31 +21,52 @@ const
("linux", "amd64", "x64"),
("macos", "amd64", "x64")
]
distFiles = @["license", "readme.md", "changelog.md"]
build =
"nim --cpu:$1 --os:$2 -d:release -d:fugitiveVersion=v$3 " &
"-o:$4 --verbosity:0 --hints:off c src/fugitive"

proc getZipName (os, arch: string): string =
let ext = if os == "windows": ".zip" else: ".tar.gz"
result = "fugitive_v" & version & "_" & os & "_" & arch & ext
result = &"fugitive_v{version}_{os}_{arch}{ext}"

task build_current, "Build fugitive for the current OS":
let
exeExt = when defined(windows): ".exe" else: ""
outFile = binDir / "fugitive" & exeExt
task build_current, "Build fugitive for the current OS (release)":
mkDir binDir

exec "nim -d:release -d:fugitiveVersion=v" & version &
" -o:" & outFile & " --verbosity:0 --hints:off c src/fugitive"
let outFile = "fugitive." & ExeExt
let outPath = binDir / outFile

task build_win_x64, "Build fugitive for Windows (x64)":
exec "nimble build " & flags_win_64
exec "nim c -o:" & outPath & " --verbosity:0 --hints:off -d:release " &
"-d:fugitiveVersion=v" & version & " " & srcDir / bin[0]

task build_linux_x64, "Build fugitive for Linux (x64)":
exec "nimble build " & flags_linux_64
let zipName = getZipName(buildOS, buildCPU).multiReplace(
("_amd64", "_x64"),
("macosx", "macos")
)
let params = join(@[zipName, outFile] & distFiles, " ")
rmFile zipName
for distFile in distFiles:
cpFile(distFile, binDir / distFile)

task build_macos_x64, "Build fugitive for macOS (x64)":
# exec "nimble build " & flags_macos_64
echo "macOS compilation is not supported on other platforms yet"
withDir binDir:
if buildOS == "windows":
exec "7z a -tzip " & params
else:
exec "tar -czf " & params

echo zipName

task build_win_x64, "Build fugitive for Windows (development)":
exec &"nimble build {flags_win_64}"

task build_linux_x64, "Build fugitive for Linux (development)":
exec &"nimble build {flags_linux_64}"

task build_macos_x64, "Build fugitive for macOS (development)":
if buildOS == "macosx":
exec &"nimble build"
else:
echo "macOS compilation is not supported on other platforms"

task build_releases, "Build all release versions of fugitive":
rmDir binDir
Expand All @@ -57,20 +78,21 @@ task build_releases, "Build all release versions of fugitive":
let
folder = name & "-" & type
outDir = binDir / folder
exeExt = if name == "windows": ".exe" else: ""
outFile = outDir / "fugitive" & exeExt
outFile = outDir / "fugitive." & ExeExt

mkDir outDir
for distFile in distFiles:
cpFile(distFile, outDir / distFile)
exec build % [arch, name, version, outFile]

let zipName = getZipName(name, type)
let params = zipName & " " & folder
let params = join(@[zipName, folder] & distFiles, " ")

withDir "dist":
withDir binDir:
if name == "windows":
exec "zip -9rq " & params
exec "7z a " & params
else:
exec "tar cfz " & params
exec "tar -czf " & params

echo "dist" / zipName
echo binDir / zipName
echo ""

0 comments on commit 6a37e19

Please sign in to comment.