Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
CI build using choco on Windows
Browse files Browse the repository at this point in the history
Signed-off-by: GuessWhoSamFoo <sfoohei@gmail.com>
  • Loading branch information
GuessWhoSamFoo committed Dec 5, 2018
1 parent fe70e8a commit 6585d3c
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.js text eol=lf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.dll
*.so
*.dylib
*.nupkg
*.bak

rice-box.go

Expand Down
35 changes: 25 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ language: go
go:
- "1.11"

os:
- linux
- osx

before_install:
- npm i -g npm@6.4.1
# Secure environment variables causes choco install to hang indefinitely: https://travis-ci.community/t/choco-install-hangs-forever/307
matrix:
include:
- os: linux
before_install:
- npm i -g npm@6.4.1
env:
secure: v8YTSShRorXHasSYxgMGqZ1WfmeRmnu87Ls7GGf7eFheV9AM2LBchWZ2U1S3/0gVtcRgUAadlvc0BUQkFczscnA8sUW1nX8A+Mosl4VLFh7QmXAvjjE31ubCS/MJz6w40EdYWYMzUfQ1S1K7jH55nAM2Z7IaKbzHagtpClu2hr+mCIRquZUYjE4/3mwxgpEMUa0QbHq8AE3KSevMQsksxJVzxv59i2EpwAjrSLlPMe28k8FX9mj0Q/k7qpy6AHveduXarcnTecNp+jbZx8D5cJQ94dFVnVOhjue4FTfmjmdTmvBWVWz+qjd5tLMZ1/KEhjji7349aSgnbL53FNTMmtKjJNF5YDCIXqfCN+jr+62VhA1pSjrgdYt+YDD1OXg6Tat/eF9Z6u6A8X7qWXqEnDFXFj02jdCvpd2isvW+l5zZXdQnf8vSfQ8ndRmeQwxx4Ntr89TBlPNJq44oMAMThRxfz1J6cPYgjS5gY5i8mqOUoYCEwSnFc+IO5/7Uxpb2DaPY4SLLAW4/wnbeEH3dN/m1Nknn8qF74LxBK4UwDX/Ucd5rY0rE9aRv17ph4vKBCOg4wCfw81n3ZgnlUTsinB4CR28/Z+90unxleQ45K9921rJMpyHTB7ywiENbGCQppJHJ84gOK5d6dtLK6F96vcaHiv6+q5pudwbu8X1YPvA=
- os: osx
before_install:
- npm i -g npm@6.4.1
- os: windows
before_install:
- choco install nodejs-lts -y
- choco install make -y
- export PATH=$PATH:"/c/Program Files/nodejs"
- node --version
- npm --version
fast_finish: true
allow_failures:
- os: windows

addons:
apt:
Expand All @@ -27,7 +42,10 @@ before_script:
- go install $TRAVIS_BUILD_DIR/vendor/github.com/GeertJohan/go.rice
- go install $TRAVIS_BUILD_DIR/vendor/github.com/GeertJohan/go.rice/rice

script: make ci
script:
- make ci
# choco install scripts points to private GH repo but windows cannot have secure env
# - if [[ $TRAVIS_OS_NAME == 'windows' ]]; then ./ci/travis-choco.sh; fi

deploy:
- provider: script
Expand All @@ -36,6 +54,3 @@ deploy:
on:
tags: true
condition: $TRAVIS_OS_NAME = linux
env:
global:
secure: v8YTSShRorXHasSYxgMGqZ1WfmeRmnu87Ls7GGf7eFheV9AM2LBchWZ2U1S3/0gVtcRgUAadlvc0BUQkFczscnA8sUW1nX8A+Mosl4VLFh7QmXAvjjE31ubCS/MJz6w40EdYWYMzUfQ1S1K7jH55nAM2Z7IaKbzHagtpClu2hr+mCIRquZUYjE4/3mwxgpEMUa0QbHq8AE3KSevMQsksxJVzxv59i2EpwAjrSLlPMe28k8FX9mj0Q/k7qpy6AHveduXarcnTecNp+jbZx8D5cJQ94dFVnVOhjue4FTfmjmdTmvBWVWz+qjd5tLMZ1/KEhjji7349aSgnbL53FNTMmtKjJNF5YDCIXqfCN+jr+62VhA1pSjrgdYt+YDD1OXg6Tat/eF9Z6u6A8X7qWXqEnDFXFj02jdCvpd2isvW+l5zZXdQnf8vSfQ8ndRmeQwxx4Ntr89TBlPNJq44oMAMThRxfz1J6cPYgjS5gY5i8mqOUoYCEwSnFc+IO5/7Uxpb2DaPY4SLLAW4/wnbeEH3dN/m1Nknn8qF74LxBK4UwDX/Ucd5rY0rE9aRv17ph4vKBCOg4wCfw81n3ZgnlUTsinB4CR28/Z+90unxleQ45K9921rJMpyHTB7ywiENbGCQppJHJ84gOK5d6dtLK6F96vcaHiv6+q5pudwbu8X1YPvA=
53 changes: 53 additions & 0 deletions choco/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Chocolatey Packages

This directory contains chocolatey packages that can be pushed to the public registry in the future. CI steps will build a NuGet package from the an existing `*.nuspec` file then install locally using chocolatey for testing.

Eventually this should be move to a separate repository to track multiple chocolately packages.

## Requirements

chocolatey0.10.11

## 1. Scaffold a new package

This generates a new directory containing a `*.nuspec` file and PowerShell scripts for install/uninstall.

```
choco new <package-name>
```

Refer to the documentation for flags to prefill metadata.

## 2. Edit package metadata

The `*.nuspec` file contains information about the package maintainers, project website, licenses, etc. Instructions are commented out within the file and remove them as fields are completed.

Inside the tools directory, there is a PowerShell installer script. Edit the URL to the location of the `*.exe` or `*.zip`.

## 3. Build the package

Generate a NuGet package with the `*.nupkg` extension from the `*.nuspec` file.

```
choco pack <name>.nuspec
```

## 4. Push the package to a chocolatey server

Adding a package to `chocolatey` will require an account with an API key. Chocolatey will also undergo an additional review of the package before it is publically available.

```
choco push <name>.nupkg --apikey="<key>" --source="http://localhost/chocolatey"
```

## (Optional) Add a chocolatey server

```
choco source add --name=<name> --source="http://localhost/chocolatey"
```

## Resources

[Setting up a testing environment with Vagrant](https://github.com/chocolatey/chocolatey-test-environment)
[Workshop and exercises](https://github.com/ferventcoder/chocolatey-workshop)
[Automatic package updates](https://github.com/majkinetor/au)
16 changes: 16 additions & 0 deletions choco/hcli.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>hcli</id>
<version>0.1.1</version>
<owners>Heptio</owners>
<title>hcli</title>
<authors>Sam Foo</authors>
<projectUrl>https://github.com/heptio/developer-dash</projectUrl>
<licenseUrl>https://github.com/heptio/developer-dash/blob/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<tags>hcli kubernetes chocolatey kubectl heptio dashboard</tags>
<summary>Kubernetes dashboard for viewing workloads</summary>
<description>A Kubernetes dashboard for developers | Install with chocolatey (https://nuget.org/List/Packages/chocolatey).</description>
</metadata>
</package>
21 changes: 21 additions & 0 deletions choco/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

$ErrorActionPreference = 'Stop';
$packageName = 'hcli'
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$url64 = 'https://github.com/heptio/developer-dash/releases/download/v0.1.1/hcli_0.1.1_Windows-64bit.zip'
$checksum64 = '9150f16fe49834ebd3ad065ac5a77acd506cd6ec5232fbe3b2fa191588670a47'
$checksumType64= 'sha256'

$packageArgs = @{
packageName = $packageName
unzipLocation = $toolsDir
url64bit = $url64

softwareName = 'hcli*'

checksum64 = $checksum64
checksumType64= 'sha256'
}

Install-ChocolateyZipPackage @packageArgs

37 changes: 37 additions & 0 deletions choco/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e

# This script requires a Github token with repo scope
# It is used to update the chocolately package version

BASE_URL="https://api.github.com/repos/heptio/developer-dash/releases"
GITHUB_URL="https://github.com/heptio/developer-dash/releases"

semver=$(make version)
version=$(echo $semver | cut -c2-)

echo "Latest version is ${semver}" >&2

# Downloading release archives from private GH repo requires an asset ID
# Get asset IDs from archive
name="hcli_${version}_Windows-64bit.zip"
response="$BASE_URL/tags/${semver}?access_token=$GITHUB_TOKEN"
eval $(curl -L $response | grep -C3 "name.:.\+$name" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')
[ "$id" ] || { echo "Error: Failed to get asset id, response: $response" | awk 'length($0)<100' >&2; exit 1; }

download="$BASE_URL/assets/$id?access_token=$GITHUB_TOKEN"
checksum64=$(curl --fail -L -H 'Accept: application/octet-stream' "${download}" | shasum -a 256 - | cut -f 1 -d " ")

url64="$GITHUB_URL/download/${semver}/$name"

# If public, use this instead
#url64="https://github.com/heptio/developer-dash/releases/download/$(make version)/hcli_$(make version | cut -c2-)_Windows-64bit.zip"
#
#checksum64=$(curl --fail -L "${url64}" | shasum -a 256 - | cut -f 1 -d " ")

echo "Updating choco metadata..." >&2
sed -i.bak "s/<version>.*<\/version>/<version>${version}<\/version>/" ./choco/hcli.nuspec
sed -i.bak "s!^\$url64 = '.*'!\$url64 = '${url64}'!" ./choco/tools/chocolateyinstall.ps1
sed -i.bak "s/^\$checksum64 = '.*'/\$checksum64 = '${checksum64}'/" ./choco/tools/chocolateyinstall.ps1

15 changes: 15 additions & 0 deletions ci/travis-choco.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -euxo pipefail

if [ -z "$TRAVIS" ]; then
echo "this script is intended to be run only on travis" >&2;
exit 1
fi

if [[ $TRAVIS_OS_NAME == 'windows' ]]; then
choco pack $TRAVIS_BUILD_DIR/choco/hcli.nuspec
choco install $TRAVIS_BUILD_DIR/hcli.$(make version | cut -c2- ).nupkg
hcli version
fi

0 comments on commit 6585d3c

Please sign in to comment.