web-dev-qa-db-ja.com

GitHubリリース用のTravis-CI自動タグ作成

[master]にコミットがプッシュされるたびに、Travis-CIがビルド製品をGitHubリリースに自動的に投稿するように試みています。

残念ながら、GitHubリリースにはリリースに使用するタグが必要です。解決策として、Travisが自動的にタグを生成してコミットに適用するようにしました。ただし、Travisがリポジトリを更新するたびに、リリースが失敗します。

このように、現在のセットアップで何が問題になっているのか、または|説明したことを行う方法があります。

私のtravis.yml:

language: Java
before_install: chmod +x gradlew
install: true
matrix:
  include:
  - jdk: oraclejdk8
script: ./gradlew build
before_deploy:
  - git config --global user.email "[email protected]"
  - git config --global user.name "Travis CI"
  - export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
  - git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
  - git Push -q https://[email protected]/RlonRyan/JBasicX --tags
deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: [redacted]
  file:
    - "build/libs"
    - "build/classes/test/output"
  on:
    tags: false
    all_branches: true
env:
  global:
    secure: [redacted]

Travis-CIログの例:

Using worker: worker-linux-e7a62211-1.bb.travis-ci.org:travis-linux-1

system_info

Build system information

Build language: Java

Build image provisioning date and time

Sun Dec 7 05:49:51 UTC 2014

lsb_release -a

Distributor ID: Ubuntu

Description: Ubuntu 12.04 LTS

Release: 12.04

Codename: precise

Cookbooks Version

5736160 https://github.com/travis-ci/travis-cookbooks/tree/5736160

GCC version

gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

Copyright (C) 2011 Free Software Foundation, Inc.

This is free software; see the source for copying conditions. There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

LLVM version

clang version 3.4 (tags/RELEASE_34/final)

Target: x86_64-unknown-linux-gnu

Thread model: posix

Pre-installed Ruby versions

Ruby-1.9.3-p551

Pre-installed Node.js versions

v0.10.33

Pre-installed Go versions

go1.3.3

Redis version

redis-server 2.8.18

riak version

1.4.12

MongoDB version

MongoDB 2.4.12

CouchDB version

couchdb 1.6.1

Neo4j version

1.9.4

Cassandra version

2.0.9

RabbitMQ Version

3.4.2

ElasticSearch version

1.4.0

Installed Sphinx versions

2.0.10

2.1.9

2.2.4

Default Sphinx version

2.1.9

Installed Firefox version

firefox 31.0esr

PhantomJS version

1.9.8

ant -version

Apache Ant(TM) version 1.8.2 compiled on December 3 2011

mvn -version

Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T20:58:10+00:00)

Maven home: /usr/local/maven

Java version: 1.7.0_72, vendor: Oracle Corporation

Java home: /usr/lib/jvm/Java-7-Oracle/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "2.6.32-042stab090.5", Arch: "AMD64", family: "unix"

gradle -version

------------------------------------------------------------

Gradle 2.0

------------------------------------------------------------

Build time: 2014-07-01 07:45:34 UTC

Build number: none

Revision: b6ead6fa452dfdadec484059191eb641d817226c

Groovy: 2.3.3

Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013

JVM: 1.7.0_72 (Oracle Corporation 24.72-b04)

OS: Linux 2.6.32-042stab090.5 AMD64

lein1 version

Using JLine for console I/O; install rlwrap for optimum experience.

Leiningen 1.7.1 on Java 1.7.0_72 Java HotSpot(TM) 64-Bit Server VM

lein2 version

Leiningen 2.5.0 on Java 1.7.0_72 Java HotSpot(TM) 64-Bit Server VM

lein version

Leiningen 2.5.0 on Java 1.7.0_72 Java HotSpot(TM) 64-Bit Server VM

git.checkout

0.26s$ git clone --depth=50 --branch=master git://github.com/RlonRyan/JBasicX.git RlonRyan/JBasicX

Cloning into 'RlonRyan/JBasicX'...

remote: Counting objects: 752, done.

remote: Compressing objects: 100% (348/348), done.

remote: Total 752 (delta 376), reused 688 (delta 335)

Receiving objects: 100% (752/752), 1.52 MiB | 0 bytes/s, done.

Resolving deltas: 100% (376/376), done.

Checking connectivity... done.

$ cd RlonRyan/JBasicX

$ git checkout -qf c89668db02576494a8678f8b8a782d87760f769a

Setting environment variables from .travis.yml

$ export TAGPERM=[secure]

$ jdk_switcher use oraclejdk8

Switching to Oracle JDK8 (Java-8-Oracle), Java_HOME will be set to /usr/lib/jvm/Java-8-Oracle

$ export TERM=dumb

$ Java -version

Java version "1.8.0_25"

Java(TM) SE Runtime Environment (build 1.8.0_25-b17)

Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

$ javac -version

javac 1.8.0_25
before_install

0.01s$ chmod +x gradlew
install

0.01s$ true

67.24s$ ./gradlew build

Downloading https://services.gradle.org/distributions/gradle-2.2.1-bin.Zip

..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Unzipping /home/travis/.gradle/wrapper/dists/gradle-2.2.1-bin/88n1whbyjvxg3s40jzz5ur27/gradle-2.2.1-bin.Zip to /home/travis/.gradle/wrapper/dists/gradle-2.2.1-bin/88n1whbyjvxg3s40jzz5ur27

Set executable permissions for: /home/travis/.gradle/wrapper/dists/gradle-2.2.1-bin/88n1whbyjvxg3s40jzz5ur27/gradle-2.2.1/bin/gradle

Download https://repo1.maven.org/maven2/junit/junit/4.11/junit-4.11.pom

Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.pom

Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-parent/1.3/hamcrest-parent-1.3.pom

Download https://repo1.maven.org/maven2/junit/junit/4.11/junit-4.11.jar

Download https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar

:compileJavaNote: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

:processResources

:classes

:jar

:assemble

:compileTestJavaNote: Some input files use unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

:processTestResources

:testClasses

:test

JTestsX.JTestsX > testCreateMenu STARTED

JTestsX.JTestsX > testCreateMenu PASSED

JTestsX.JTestsX > testCreateDrawing STARTED

JTestsX.JTestsX > testCreateDrawing PASSED

:check

:build

BUILD SUCCESSFUL

Total time: 1 mins 6.792 secs

The command "./gradlew build" exited with 0.
before_deploy.1

0.01s$ git config --global user.email "[email protected]"
before_deploy.2

0.01s$ git config --global user.name "Travis CI"
before_deploy.3

0.01s$ export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
before_deploy.4

0.01s$ git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
before_deploy.5

0.79s$ git Push -q https://[email protected]/RlonRyan/JBasicX --tags
dpl.0

Fetching: dpl-1.7.9.gem (100%)

Successfully installed dpl-1.7.9

1 gem installed

dpl.1

Installing deploy dependencies

Fetching: addressable-2.3.6.gem (100%)

Successfully installed addressable-2.3.6

Fetching: multipart-post-2.0.0.gem (100%)

Successfully installed multipart-post-2.0.0

Fetching: faraday-0.9.1.gem (100%)

Successfully installed faraday-0.9.1

Fetching: sawyer-0.6.0.gem (100%)

Successfully installed sawyer-0.6.0

Fetching: octokit-3.7.0.gem (100%)

Successfully installed octokit-3.7.0

5 gems installed

Fetching: mime-types-2.4.3.gem (100%)

Successfully installed mime-types-2.4.3

1 gem installed

dpl.2

Preparing deploy

Logged in as RlonRyan

Deploying to repo: RlonRyan/JBasicX

remote: Counting objects: 23, done.

remote: Compressing objects: 100% (20/20), done.

remote: Total 23 (delta 16), reused 10 (delta 3)

Unpacking objects: 100% (23/23), done.

From git://github.com/RlonRyan/JBasicX

* [new tag] master-0.1.23-2015-01-29 -> master-0.1.23-2015-01-29

* [new tag] master-0.1.26-2015-01-29 -> master-0.1.26-2015-01-29

* [new tag] master-0.1.29-2015-01-29 -> master-0.1.29-2015-01-29

* [new tag] master-0.1.34 -> master-0.1.34

* [new tag] master-0.1.36 -> master-0.1.36

* [new tag] v0.1.0 -> v0.1.0

Current tag is: master-0.1.38

dpl.3

Deploying application

/home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/octokit-3.7.0/lib/octokit/client/releases.rb:86:in `initialize': Is a directory - build/libs (Errno::EISDIR)

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/octokit-3.7.0/lib/octokit/client/releases.rb:86:in `new'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/octokit-3.7.0/lib/octokit/client/releases.rb:86:in `upload_asset'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider/releases.rb:118:in `block in Push_app'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider/releases.rb:102:in `each'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider/releases.rb:102:in `Push_app'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider.rb:132:in `block in deploy'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/cli.rb:41:in `fold'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/provider.rb:132:in `deploy'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/cli.rb:32:in `run'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/lib/dpl/cli.rb:7:in `run'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/gems/dpl-1.7.9/bin/dpl:5:in `<top (required)>'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/bin/dpl:23:in `load'

from /home/travis/.rvm/gems/Ruby-1.9.3-p551/bin/dpl:23:in `<main>'

failed to deploy
18
RlonRyan

コンセプトに問題はなく、デプロイされているファイルのみです。

デプロイする予定のファイルが.travis.ymlに適切にリストされておらず、gradleビルドタスクが適切な.Zipファイルを生成していませんでした。

更新された.travis.ymlは次のとおりです。

language: Java
install: true
matrix:
  include:
  - jdk: oraclejdk8
script:
  - gradle clean build
  - gradle dist
before_deploy:
  - git config --global user.email "[email protected]"
  - git config --global user.name "Travis CI"
  - export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
  - git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
  - git Push -q https://[email protected]/RlonRyan/JBasicX --tags
  - ls -R
deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: [redacted]
  file:
    - "README.md"
    - "dist/JBasicX-Main-0.1.0.Zip"
    - "dist/JBasicX-Test Output-0.1.0.Zip"
  on:
    tags: false
    all_branches: true
env:
  global:
    secure: [redacted]

このビルドのセットアップ方法に注意してください。Travisはコミットごとに2回実行されますが、初めてデプロイされるだけです。これを回避する方法については、さらに調査する価値があります。

また、不適切に実装された場合、つまりdeploy.on:tags = trueの場合は、無限のTravis-CIビルドループが作成されることに注意してください。このような結果はクリーンアップが容易ではなく、ビルド履歴を削除できないためTravisで最も顕著になります。

編集:複製されたビルドの解決策は、Travis-CIがタグのプッシュをコミットとして扱う方法にあります。これを回避するトリックは、Travis-CIの問題#1532のGitHubの@ o11cで発見されました。基本的には、前件タグの付いたブランチを除外する必要があります。

.travis.ymlでは、これは以下を追加することになります。

branches:
  except:
    - /^*-v[0-9]/

後世の場合、最後の.travis.ymlは次のようになります。

language: Java

install: true

matrix:
  include:
  - jdk: oraclejdk8

script:
  - gradle clean build
  - gradle dist

before_deploy:
  - git config --global user.email "[email protected]"
  - git config --global user.name "Travis CI"
  - export GIT_TAG=$TRAVIS_BRANCH-0.1.$TRAVIS_BUILD_NUMBER
  - git tag $GIT_TAG -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER"
  - git Push -q https://[email protected]/RlonRyan/JBasicX --tags
  - ls -R

deploy:
  skip_cleanup: true
  provider: releases
  api_key:
    secure: [redacted]
  file:
    - "README.md"
    - "dist/JBasicX-Main-0.1.0.Zip"
    - "dist/JBasicX-Test Output-0.1.0.Zip"
  on:
    tags: false
    all_branches: true

branches:
  except:
    - /^*-v[0-9]/

notifications:
  email:
    on_success: change
    on_failure: change
  irc:
    channels:
      - "irc.esper.net#RlonRyan"
    on_success: always
    on_failure: always

env:
  global:
    secure: [redacted]
21
RlonRyan