Travis-CI Auto-Tag Build for GitHub Release

喜欢而已 提交于 2019-11-28 17:56:59

There was nothing wrong with the concept, just the files being deployed.

The files that were meant to be deployed were not listed properly in the .travis.yml, and the gradle build task was not generating the proper .zip files.

Here is the updated .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]

Note, the way this build is setup, Travis will run twice for every commit, but only deploy the 1st time. Such may be worth further investigation in how to avoid.

Also, beware when improperly implemented, that is deploy.on:tags = true, an infinite Travis-CI build loop is created. Such a result is not easy to clean up, and most noticeable in Travis due to the inability to delete build history.

Edit: The solution to the duplicated builds lies in the way Travis-CI treats tag pushes as commits. The trick to avoid this was found by @o11c on GitHub for Travis-CI issue #1532. Basically, what one needs to do is exclude branches with the tag antecedent.

In .travis.yml this amounts to adding the following:

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

For posterity the final .travis.yml amounts to:

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]
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!