Getting TravisCI to commit and click a modified file using tags (releases)

Sir Athos helped me (thank you very much) today today on a separate issue that helped me a lot.

I am now stuck at the point where I want to change a simple text file and include it in my push. So basically I want to add the changed text file to the commit and push it as a commit with this tag the build number as release. Hope I feel here.

My code to do this so far,

#!/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% if it exists, if the tag exists, and then either clicking if it does not exist or not clicking it, it exists.

I was just stuck and now Travis has included a simple build.txt file that I pass to $ TRAVIS_BUILD_DIR with the addition.

, travis.yml :

file: - build.txt

Travis build.txt , . , - , , .

:

bash script , if. build.txt . Travis untagged-cc6ebe6dbcbb13bc599c, , , . , , , .

    #!/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

, travis.yml before_deploy, . , , -. , .

+4
2

- , , - . , , , .

before_deploy: travis.yml, , TravisCI , untagged-randomnumbers

, script: Travis.yml

, , , script, changefile.sh, :

#!/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 script, deploy.sh, :

#!/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

travis.yml ( ) :

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

, 100%, , TravisCI .

, , TravisCI (-, ), , Travis V2. , , master.

, , - , , TravisCI . " , " , " ",

enter image description here

+4

git, :

msg="Tag...
echo "$msg" >> $TRAVIS_BUILD_DIR/build.txt
git add $TRAVIS_BUILD_DIR/build.txt
git commit -m "Update build version file"
if git tag ...

, script, if git tag, (unpushed) :

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"
    git push ...
else ...

(, , git, if, if, , if ).

+3

Source: https://habr.com/ru/post/1669842/


All Articles