【问题标题】:Travis-CI Auto-Tag Build for GitHub ReleaseGitHub 发布的 Travis-CI 自动标记构建
【发布时间】:2015-01-29 14:49:28
【问题描述】:

我一直在尝试让 Travis-CI 自动在 GitHub Releases 上发布其构建产品,只要将提交推送到 [master]。

不幸的是,GitHub Releases 需要一个标签才能发布。作为解决方案,我尝试让 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 "builds@travis-ci.com"
  - 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://$TAGPERM@github.com/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 "builds@travis-ci.com"
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://$TAGPERM@github.com/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

【问题讨论】:

    标签: github travis-ci


    【解决方案1】:

    这个概念没有错,只是正在部署的文件。

    .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 "builds@travis-ci.com"
      - 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://$TAGPERM@github.com/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 将为每次提交运行两次,但仅部署第一次。这可能值得进一步研究如何避免。

    另外,当不正确的实现时要小心,即deploy.on:tags = true,会创建一个无限的 Travis-CI 构建循环。这样的结果不容易清理,并且由于无法删除构建历史记录,在 Travis 中最为明显。

    编辑: 重复构建的解决方案在于 Travis-CI 将标签推送视为提交的方式。 @o11c 在 GitHub 上为 Travis-CI 问题 #1532 找到了避免这种情况的技巧。基本上,需要做的就是排除带有前因标签的分支。

    在.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 "builds@travis-ci.com"
      - 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://$TAGPERM@github.com/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]
    

    【讨论】:

    • 不错的解决方案。不过有几个问题。只在主分支上执行这个不是更好吗?这样标签只会在合并到 master 时创建。我的另一个问题是,您如何管理发布新版本?你必须修改这个 .travis.yml 文件以增加 0.1 到 0.2 等等,每次?
    • 这如何工作?除非您在遵循此处描述的这个毫无意义的拜占庭程序之后将 Github 部署密钥作为 SSH 密钥注入:github.com/alrra/travis-scripts/blob/master/doc/…
    • @sscarduzio 它是一个 HTTPS 存储库,因此您可以使用个人访问令牌 github.com/blog/…
    • 根据github.com/travis-ci/travis-ci/issues/…,您现在可以使用if: tag IS blank 来不构建标签。有人对此感到高兴吗?
    • @RlonRyan - $TAGPERM 的设置是什么?你是如何创建的?
    猜你喜欢
    • 1970-01-01
    • 2018-10-09
    • 1970-01-01
    • 2021-11-29
    • 2019-05-21
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多