Capistrano Deploy not fetching latest commit from GitHub - ruby-on-rails

When I run 'cap production deploy' is am not getting my latest master on the server. Here are so lines from the deploy log:
DEBUG[208486a4] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/----/git-ssh.sh /usr/bin/env git ls-remote git#github.com:------.git )
DEBUG[208486a4] 3983b992ede90e5957dc9ddb953c4df488354d7d HEAD
DEBUG[208486a4] 3983b992ede90e5957dc9ddb953c4df488354d7d refs/heads/master
DEBUG[208486a4] Finished in 0.832 seconds with exit status 0 (successful).
Then later on in the log:
INFO[38bea0b3] Running /usr/bin/env echo "Branch master (at 18306db) deployed as release 20140626124746 by dean; " >> /home/deploy/royalty/revisions.log on 96.126.121.168
DEBUG[38bea0b3] Command: echo "Branch master (at 18306db) deployed as release 20140626124746 by dean; " >> /home/deploy/royalty/revisions.log
INFO[38bea0b3] Finished in 0.116 seconds with exit status 0 (successful).
I have recently switched from using a repo at assembla to github. The commit: 18306db was the last commit that I pushed up to assembla. But all the new commits after that show up when I view the repo on github.
I changed the origin url with set-url and then pushed the up to github.
What am I missing here?? Thanks

Finally found a question that was related here: Capistrano error tar: This does not look like a tar archive
And followed the advice in the second answer which worked for me.
Logged into server and deleted the app_name/repo folder (rm -rf /app_name/repo )

Related

Automatic merge based on commit message

I am using Xcode Cloud with my iOS project. There are a few workflows based on branches and tags. Commonly one of them is finishing with app publication on the Test Flight.
My goal is to make an automation that will be run on develop branch every time when I will make some push. This automation will arise when script will find #promote tag inside commit message.
My first approach was to use post build script in Xcode Cloud as shown below:
#!/bin/sh
# ci_post_xcodebuild.sh
# BeforeDaily
#
# Created by Piotrek on 28/08/2022.
#
cd "$CI_WORKSPACE"
MESSAGE=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ "$MESSAGE" == *"#promote"* ]]; then
echo "Merging develop into stage"
git fetch --all
git checkout --track -b stage origin/stage
git merge develop
git push origin stage
git checkout develop
echo "Done"
else
echo "There is nothing to do here..."
fi
This approach was promising but Xcode Cloud does not have write permissions on the Github project and it is not possible to change it. The result of the script is here:
2022-08-28T21:37:40.713643324Z Merging develop into stage
2022-08-28T21:37:42.747978838Z From http://github.com/<username>/<project_name>
2022-08-28T21:37:42.748494378Z * [new branch] develop -> origin/develop
2022-08-28T21:37:42.749001513Z * [new branch] main -> origin/main
2022-08-28T21:37:42.749224260Z * [new branch] stage -> origin/stage
2022-08-28T21:37:42.749514956Z Switched to a new branch 'stage'
2022-08-28T21:37:42.749752757Z branch 'stage' set up to track 'origin/stage'.
2022-08-28T21:37:42.750006530Z fatal: refusing to merge unrelated histories
2022-08-28T21:37:42.852059197Z remote: Write access to repository not granted.
2022-08-28T21:37:42.852480361Z fatal: unable to access 'http://github.com/piotrekjeremicz/beforedaily-swiftui-app.git/': The requested URL returned error: 403
2022-08-28T21:37:42.852854256Z Switched to branch 'develop'
2022-08-28T21:37:42.853020173Z Done
So the question is:
Is there any method that could provide me automatic merge based on commit message content?
I could not find any other solution than make a clean clone and work on fresh git repository. Everything is done in Xcode Cloud Workflow Here is a final ci_post_xcbuild.sh that makes a merge to stage if some message on develop contains #promote string.
#!/bin/sh
cd "$CI_WORKSPACE"
MESSAGE=$(git log -1 --oneline --format=%s | sed 's/^.*: //')
if [[ "$CI_BRANCH" == develop && "$MESSAGE" == *"#promote"* ]]; then
echo "Automerge develop branch into stage"
mkdir tempclone
cd tempclone
git clone https://x-access-token:$GITHUB_TOKEN#github.com/github_account/github_repo_name.git
cd beforedaily-swiftui-app
git config --global user.email "xcodecloud#jeremicz.com"
git config --global user.name "Xcode Cloud"
git checkout --track -b stage origin/stage
git merge origin/develop
git push origin stage
cd ../../
rm -r tempclone
else
echo "There is nothing to do here..."
fi
This script works with Github Token as an environment value that could be setup in Workflow settings.

Git remove push issue with post-receive

I've setup my vps with this tutorial
but when I push from my local repository to the remote i get this error:
... sending is complete but...
remote: Resolving deltas: 100% (1316/1316), done.
remote: /bin/sh: 0: Can't open git —work-tree=/var/www/my_website.com/html --git-dir=/var/repo/my_website.git checkout -f
To ssh://xxx.xxx.xxx.xxx/var/repo/my_website.git
* [new branch] master -> master
I've set: chmod -R 777 /var/repo/my_website.git
along with chmod +x post-receive
Is there an issue with the permissions of the /var/www/my_website.com/html ?
How do i solve this? Im trying to push a rails 6 project
git push -f origin master
I hope this will forcefully push all the changes from the local repository to the GitHub repository.

Capistrano v3 deploy failed on git rev-parse --short HEAD

Hi this is the error that is appearing when I'm deploying using Capistrano 3 with a Rails 4 app to a Webfaction server.
The deploy has failed with an error: #<SSHKit::Command::Failed: cd
/home/username/webapps/app/repo && git rev-parse --short HEAD stdout: Nothing written
cd /home/username/webapps/app/repo && git rev-parse --short HEAD stderr: Nothing written>
My git repository is inside webfaction, I created it as --bare repository, don't know if that changes things. I set it up the URL like this in my capistrano file:
set :repo_url, '/home/username/webapps/git_app/repos/myrepo.git'
Any additional info that you may need, please ask
Thanks.
I just worked around this issue with this procedure, I don't believe it's the correct one but it helped me through:
I copied all the files (the git config files) from my repo: /home/username/webapps/git_app/repos/my_git.git/
to the mirror repo that Capistrano builds in Webfaction: /home/username/webapps/git_app/repo
Like this:
cp -a /home/username/webapps/git_app/repos/my_git.git/. /home/username/webapps/git_app/repo

Git: forcing tests before pushing to local or remote master

Is there a way so that git refuses to commit to local or push to remote master if tests (rspec) are failing ? Thank you.
Use a git pre commit hook which executes rake spec (taken from Tips for using a git pre-commit hook).
git stash -q --keep-index
`rake rspec`
RESULT=$?
git stash pop -q
[ $RESULT -ne 0 ] && exit 1
exit 0

failed to push some refs

Im trying to push to github
I follow the steps:
(before these lines Im located on my app directory)
$ mkdir estaciones
$ cd estaciones
$ git init
>>Initialized empty Git repository in /Users/armandodejesussantoyareales/Documents/project_newbie/Estaciones/estaciones/.git/
$ touch README
$ git add README
$ git commit -m "phase 3 estaciones"
>>[master (root-commit) 4462be3] phase 3 estaciones
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100755 README
(I don't know if that message is an error)
$ git remote add origin git#github.com:asantoya/estaciones.git
$ git push -u origin master
but always I have the same problem,late that I type that i got the next error
To git#github.com:asantoya/estaciones.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:asantoya/estaciones.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
This means that the remote repository already has a master branch and it has stuff in that branch that has been added since you made commits to your local copy. This is referring to the code visible at https://github.com/asantoya/estaciones
Start by cloning the repo from github, then adding your changes to it, then pushing:
git clone https://github.com/asantoya/estaciones.git
git checkout -b nameofyourbranch master
Add some files etc.
git commit -a -m "Your commit message"
git push origin nameofyourbranch

Resources