LoginSignup
35

More than 5 years have passed since last update.

githubにgoのライブラリを公開する手順メモ

Last updated at Posted at 2017-12-07

概要

ffprobeコマンドのgolangバインドをライブラリとして公開してみる

動画であれば対象ファイルの動画ストリーム情報や
オーディオストリーム情報を表示してくれるffprobeコマンドを
golangの構造体にバインドしてみる。

リポジトリはライブラリとして公開したいので下記を表示するようにしたい。

  • buildに成功する
  • カバレッジ
  • godocへのリンク
  • ライセンス

公開先はgithubを前提に書いています

結果

こんな感じになりました

スクリーンショット 2017-11-09 23.19.56.png

リポジトリはこちら
https://github.com/smith-30/go-ffprobe

手順

リポジトリを作る

LICENSEもこのタイミングで作ってしまいましょう。

スクリーンショット 2017-11-11 01.12.22.png

travisに登録

CIはtravisを使っていきます

無料

https://travis-ci.org より
ダッシュボードから作成リポジトリをOnにする

coverallsに登録

無料

https://coveralls.io より
ダッシュボードから作成リポジトリをOnにする

.travis.ymlの設定

.travis.yml
language: go
sudo: false
go:
  - 1.8
  - 1.9
  - tip

matrix:
  allow_failures:
    - go: tip

install:
  - go get golang.org/x/tools/cmd/cover
  - go get github.com/modocache/gover
  - go get github.com/mattn/goveralls
  - go get honnef.co/go/tools/cmd/gosimple
  - go get honnef.co/go/tools/cmd/unused
  - go get honnef.co/go/tools/cmd/staticcheck
  - go get -v -t ./...

script:
  - go vet $(go list ./... | grep -v /vendor/)
  - unused $(go list ./... | grep -v /vendor/)
  - gosimple $(go list ./... | grep -v /vendor/)
  - staticcheck $(go list ./... | grep -v /vendor/)
  - go test -cover -coverpkg github.com/smith-30/go-ffprobe -coverprofile go-ffprobe.coverprofile

after_script:
  - gover
  - goveralls -coverprofile=gover.coverprofile -repotoken $COVERALLS_TOKEN

一応、ソースコードの品質も担保したいのでテスト以外に

  • vet
  • gosimple
  • unused
  • staticcheck

を使って静的解析しています。

coverallのtoken設定

.travis.yml$COVERALLS_TOKENの記述がありますがこの設定をしていきます

$ sudo gem install travis

# プロジェクトルートで打つこと、そうするとtravis設定ファイルに書き込まれる
$ travis encrypt COVERALLS_TOKEN=<your-token> --add

<your-token> はcoverallsで有効にしているリポジトリのページから取ってきてください。

travisを回してみる

CI連携ができるか下記ファイルをリモートリポジトリにpush

ffprobe.go
package go_ffprobe

func GetFileInfo(fileName string) string {
    return fileName
}
ffprobe_test.go
package go_ffprobe_test

import (
    "testing"

    ffprobe "github.com/smith-30/go-ffprobe"
)

func TestGetFileInfo(t *testing.T) {
    exp := "test"
    act := ffprobe.GetFileInfo(exp)

    if exp != act {
        t.Errorf("failed.")
    }
}

travisが動けば成功

カバレッジやbuild成功のバッチを出す

README.mdの先頭を編集してpush

[![Build Status](https://secure.travis-ci.org/smith-30/go-ffprobe.png?branch=master)](http://travis-ci.org/smith-30/go-ffprobe)
[![Coverage Status](https://coveralls.io/repos/smith-30/go-ffprobe/badge.svg?branch=master)](https://coveralls.io/r/smith-30/go-ffprobe?branch=master)
[![GoDoc](https://godoc.org/github.com/smith-30/go-ffprobe?status.svg)](https://godoc.org/github.com/smith-30/go-ffprobe)
[![license](https://img.shields.io/badge/license-MIT-4183c4.svg)](https://github.com/smith-30/go-ffprobe/blob/master/LICENSE)

smith-30/go-ffprobe は適宜変えてください

カバレッジやバッチが出てれば成功です。

まとめ

サクッとバッチ付きのライブラリ公開できるので
まだやったことがない方は試してみてはいかがでしょうか。

リポジトリのCI連携をやったことがない人にもオススメです。
pushしたら勝手にテスト回ったり静的解析やってくれるのは幸せですね。しかも無料。ありがたい。

goverallsやgoの静的解析ツール作られた方にはただただ感謝です。
json <-> go structはこのサービス使いました。
jsonから、goのstructを表示してくれます
https://mholt.github.io/json-to-go/

今年も残りわずかですが引き続きよいgo lifeを楽しんでいきましょう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35