让TravisCI使用标签(发布版)提交并推送修改后的文件 [英] Getting TravisCI to commit and push a modified file with Tags (releases)

查看:134
本文介绍了让TravisCI使用标签(发布版)提交并推送修改后的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天早些时候,我得到了阿索斯爵士(非常感谢你)的帮助,这个问题对我很有帮助。

我现在停留在想要修改简单文本文件并将其包含在我的推送中的一点。所以基本上我想将修改后的文本文件添加到提交中,并将其作为提交并将其作为内部版本号标记作为发布进行推送。希望我在这里有所帮助。



到目前为止,我的代码尝试做到这一点:

 #!/ bin / bash 
YEAR = $(date +%Y)
MONTH = $(date +%m)
git config - -global user.email$ {GIT_EMAIL}
git config --global user.name$ {GIT_NAME}
git config --global push.default简单
导出GIT_TAG = v2 。$年 - $月。$ TRAVIS_BUILD_NUMBER
git fetch --tags
msg =从TravisCI for build $ TRAVIS_BUILD_NUMBER生成的标签
echo$ msg>> $ TRAVIS_BUILD_DIR / build.txt
git add -A
if git tag $ GIT_TAG -a -m$ msg2> / dev / null;然后
git tag $ GIT_TAG -a -m从TravisCI生成的标记以生成$ TRAVIS_BUILD_NUMBER
git push https:// $ {GH_TOKEN} @ github.com / $ {TRAVIS_REPO_SLUG} HEAD:master& amp; amp; ;&安培; git push https:// $ {GH_TOKEN} @ github.com / $ {TRAVIS_REPO_SLUG} --tags HEAD:master
ls -aR
else echo标记已经存在! fi

阿索斯先生给我的if ... else ...代码早期有100%如果标签存在,然后推送,如果它不存在或不推动它它确实存在。



我只是坚持现在让特拉维斯到包括一个简单的build.txt文件,其中附有$ TRAVIS_BUILD_DIR。



有趣的是,如果我添加到我的travis.yml部署选项,如下所示:



file:
- build.txt



Travis推送build.txt文件,但没有提交该文件。我知道我在做,并且错过了一些非常愚蠢的事情,但是很容易我是Travis的新手。



更新:



现在我已经修改了我的bash脚本,如下所示,删除在if语句中添加额外的标记。这现在可以工作,并将修改后的build.txt文件推送到回购站。但是一旦完整的Travis开始使用 untagged-cc6ebe6dbcbb13bc599c 构建其他的构建版本,现在它将Travis引入循环,继续构建和构建。我认为特拉维斯会让我发疯,但我知道我有一些逻辑错误。

 #!/ bin / bash 
YEAR = $(date +%Y)
MONTH = $(date +%m)
git config --global user.email$ {GIT_EMAIL}
git config --global user.name$ {GIT_NAME}
git config --global push.default simple $ b $ export GIT_TAG = v2。$ YEAR- $ MONTH。$ TRAVIS_BUILD_NUMBER
git fetch --tags
msg =从TravisCI生成的代码生成$ TRAVIS_BUILD_NUMBER
if git tag $ GIT_TAG -a -m$ msg2> / dev / null;然后
回显$ msg>> $ TRAVIS_BUILD_DIR / build.txt
git add $ TRAVIS_BUILD_DIR / build.txt
git commit -m使用$ TRAVIS_BUILD_NUMBER更新版本文件
$ TRAVIS_BUILD_NUMBER
git push https: //${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} HEAD:master&&git push https:// $ {GH_TOKEN} @ github.com / $ {TRAVIS_REPO_SLUG} --tags HEAD:master
ls -aR
else echo标记已存在!; fi

我想我必须重新 - 在早上看看我的travis.yml,并且在做before_deploy之前做一些事情,然后用deploy来做最后的推动。想想我为什么导致Travis不停地循环,因此今晚已经禁用了它特拉维斯并没有整夜思考。

解决方案

我终于弄明白了自己的逻辑错误,并在希望中解释它这将有助于未来的人。非常感谢Athos先生带领我在所有这一切的正确方向,大谢谢先生。



首先,我正在修改一个文件,并在travis.yml的before_deploy:部分进行提交,这会导致TravisCI旋转成连续循环,并创建所有标记为<$的新构建c $ c> untagged-randomnumbers



现在我通过对Travis.yml的脚本中的文件进行任何修改来解决这个问题:因此,考虑到这只是一个测试容器,我有一个名为 changefile.sh 的脚本,如下所示:

b

 #!/ bin / bash 
YEAR = $(date +%Y)
MONTH = $(date +% m)
git config --global user.email$ {GIT_EMAIL}
git config --global user.name$ {GIT_NAME}
git config --global push。默认简单的
导出GIT_TAG = V2。$年 - $月。$ TRAVIS_BUILD_NUMBER
msg = $ TRAVIS_BUILD_DIR / build.txt
git add $ TRAVIS_BUILD_DIR / build.txt
git commit -m使用$ TRAVIS_BUILD_NUMBER更新版本文件

接下来,我有一个名为 deploy.sh 的脚本,如下所示:

<$ p $ b $ #!/ bin / bash
YEAR = $(date +%Y)
MONTH = $(date +%m)
git config --global user.email$ {GIT_EMAIL}
git config --global user.name$ {GIT_NAME}
git config --global push.default简单
git远程添加源https:// $ {GH_TOKEN} @ github.com / $ {TRAVIS_REPO_SLUG} .git
导出GIT_TAG = V2。$ YEAR- $ MONTH。$ TRAVIS_BUILD_NUMBER
git fetch --tags
msg =从TravisCI生成的标记以生成$ TRAVIS_BUILD_NUMBER
如果git标记$ GIT_TAG -a -m$ msg2> / dev / null;然后
git tag $ GIT_TAG -a -m从TravisCI生成的标签生成$ TRAVIS_BUILD_NUMBER
git push origin master&& git push origin master --tags
ls -aR
else echo标记已经存在! fi

我的 travis.yml (缩短版本)现在看起来像这样:

 语言:php 
sudo:必需
dist:可信
env:
global:
- secure:lotsofrandomnumbers
- GIT_NAME:Travis CI
- GIT_EMAIL:builds@travis-ci.org
- TRAVIS_REPO_SLUG:mygitusername / myreposlug
- GIT_BRANCH:master
matrix:
fast_finish:true
php:
- '5.6'
cache:
- apt
install:
#在这里做一些事
脚本:
#在这里做更多的事
- ./changefile.sh
before_deploy:
- ./deploy.sh
部署:
提供者:释放
api_key:
secure:$ {GH_TOKEN}
文件:
#将文件添加到发行版 - 分别指定它们而不是一个git add。或git add -A
- test.txt
skip_cleanup:true
on:
repo:mygitusername / myreposlug
标签:false
all_branches:真正的
通知:
电子邮件:false

现在可以达到我想要的100 %,并不会导致TravisCI旋转成一个循环。

Travis现在首先在我的主分支上进行构建,将标签和修改后的文件推出发行版,然后TravisCI将执行后续构建(显然非常正常的Travis行为),在我的情况下,在特拉维斯标记为V2.whatever任意版本号,但涉及与在master上构建相同的提交编号。

这样做是运行第二次构建测试,但实际上并没有推送任何标记,提交或更改,因此不再让TravisCI进入连续循环。您将看到第二个构建结束消息跳过使用发布提供程序的部署,因为这不是标记提交,而您的第一个构建将退出并显示消息部署应用程序




I was helped by Sir Athos (thank you greatly) earlier today on a separate question which helped me greatly.

I am now stuck at a point where I want to modify a simple text file and include it in my push. So basically I want to add the modified text file to a commit and push it as a commit with it's build number tag as a release. Hope I am making sense here.

My code to do try and do this so far is

#!/bin/bash
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
git config --global user.email "${GIT_EMAIL}"
git config --global user.name "${GIT_NAME}"
git config --global push.default simple
export GIT_TAG=v2.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
git fetch --tags
msg="Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
git add -A
if git tag $GIT_TAG -a -m "$msg" 2>/dev/null; then
git tag $GIT_TAG -a -m "Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
git push https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} HEAD:master && git push https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} --tags HEAD:master
ls -aR
else echo Tag already exists!; fi

The if ... else ... code given to me by Sir Athos earlier works 100% with it picking up if the tag exists and then either pushing if it does not exist or not pushing it it does exist.

I'm just stuck with now getting Travis to include the simple build.txt file which I echo $TRAVIS_BUILD_DIR into with an append.

What's interesting is if I add to my travis.yml deploy option like this:

file: - build.txt

Travis pushes the build.txt file with the release but is not committing the file. I know I'm doing and missing something really stupid here but go easy I'm new to Travis.

Update:

Now I have modified my bash script as follows, removing adding the extra tag within the if statement. This now works and pushes the modified build.txt file to the repo. But once complete Travis then starts other builds with untagged-cc6ebe6dbcbb13bc599c and now it's throwing Travis into a loop just continuing to build and build and build. I think Travis will drive me mad yet, I know I have some logic wrong somwehere.

    #!/bin/bash
    YEAR=$(date +"%Y")
    MONTH=$(date +"%m")
    git config --global user.email "${GIT_EMAIL}"
    git config --global user.name "${GIT_NAME}"
    git config --global push.default simple
    export GIT_TAG=v2.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
    git fetch --tags
    msg="Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
    if git tag $GIT_TAG -a -m "$msg" 2>/dev/null; then
    echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
    git add $TRAVIS_BUILD_DIR/build.txt
    git commit -m "Update build version file with $TRAVIS_BUILD_NUMBER"
$TRAVIS_BUILD_NUMBER"
    git push https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} HEAD:master && git push https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG} --tags HEAD:master
    ls -aR
    else echo Tag already exists!; fi

I think I must re-look at this with my travis.yml in the morning and work on doing things before_deploy and then use deploy to do the final push. Think I have figured out why I am causing Travis to loop non-stop. Have disabled it for tonight so Travis doesn't go mental all night long.

解决方案

I finally figured out my logic error and will explain it here in the hopes this will help someone in future. Thanks so much to Sir Athos for leading me in the right direction on all of this, big Thank You's Sir.

First I was doing the modification to a file and a commit in the before_deploy: section of travis.yml which led to TravisCI spinning into a continuous loop and just creating new builds all marked as untagged-randomnumbers

I solved this now by doing any modifications to files in my script: section of Travis.yml

So, considering this is just a testing container, I have a script called changefile.sh which look as follows:

#!/bin/bash
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
git config --global user.email "${GIT_EMAIL}"
git config --global user.name "${GIT_NAME}"
git config --global push.default simple
export GIT_TAG=V2.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
msg="Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
git add $TRAVIS_BUILD_DIR/build.txt
git commit -m "Update build version file with $TRAVIS_BUILD_NUMBER"

next I have a script called deploy.sh which looks as follows:

#!/bin/bash
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
git config --global user.email "${GIT_EMAIL}"
git config --global user.name "${GIT_NAME}"
git config --global push.default simple
git remote add origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git
export GIT_TAG=V2.$YEAR-$MONTH.$TRAVIS_BUILD_NUMBER
git fetch --tags
msg="Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
if git tag $GIT_TAG -a -m "$msg" 2>/dev/null; then
git tag $GIT_TAG -a -m "Tag Generated from TravisCI for build $TRAVIS_BUILD_NUMBER"
git push origin master && git push origin master --tags
ls -aR
else echo Tag already exists!; fi

And my travis.yml (shortened version) now looks like this:

language: php
sudo: required
dist: trusty
env:
  global:
    - secure: lotsofrandomnumbers
    - GIT_NAME: Travis CI
    - GIT_EMAIL: builds@travis-ci.org
    - TRAVIS_REPO_SLUG: mygitusername/myreposlug
    - GIT_BRANCH: master
matrix:
  fast_finish: true
php:
  - '5.6'
cache:
  - apt
install:
  # do some stuff here
script:
  # do some more stuff here
  - ./changefile.sh
before_deploy:
  - ./deploy.sh
deploy:
  provider: releases
  api_key:
    secure: ${GH_TOKEN}
  file:
  # add files to the release - specify them individually instead of a git add . or git add -A
  - "test.txt"
  skip_cleanup: true
  on:
    repo: mygitusername/myreposlug
    tags: false
    all_branches: true
notifications:
    email: false

This now achieves what I want 100% and does not lead to TravisCI spinning into a loop.

Travis now first does a build on my master branch, pushes the release out with tags and the modified files and then TravisCI will do a subsequent build (apparently very normal Travis behavior), in my case labelled in Travis with the V2.whatever version number, but relates to the very same commit number as the build on master.

What this does is run a second build test but not actually push any tags, commits or changes out so no more getting TravisCI into a continuous loop. You will see the second build end with a message "Skipping a deployment with the releases provider because this is not a tagged commit" whereas your first build will exit with a message saying "Deploying application"

这篇关于让TravisCI使用标签(发布版)提交并推送修改后的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆