Modifying a github public repository from a travis build - github

In the build of my first public repository https://github.com/yafred/test-push/ I try to modify my second repository https://github.com/yafred/test
1/ I am using the same personal access token with scope repo (GH_TOKEN) that I'm using to deploy releases.
2/ The commands I am executing from the .travis.yml are
language: generic
script:
- git clone https://github.com/yafred/test.git
- cd test
- echo "hello" > test.txt
- git add .
- git -c user.name='travis' -c user.email='travis' commit -m refresh
- git push -f -q https://{$GH_TOKEN}#github.com/yafred/test master
I have tried a few variations in the commands based on my searches but I keep getting an authentication error
0K$ git push -f -q https://{$GH_TOKEN}#github.com/yafred/test master
remote: Invalid username or password.
fatal: Authentication failed for 'https://{[secure]}#github.com/yafred/test/'
Is it at all possible ?
What am I doing wrong ?

Related

GitHub Action incapable of pushing due to "unsafe repository" error

I have a private GitHub repository that has a GitHub Action that pushes files which are created at the Action's runtime to the repository. Since yesterday (2022-04-12), the Action fails at the following step:
- name: Push data to repo
uses: github-actions-x/commit#v2.8
with:
push-branch: 'main'
commit-message: 'Add current data'
force-add: 'true'
files: *.zip
name: autoupdate
Running this step triggers the following error message:
Command line: | /usr/bin/git checkout -B main
Stderr: | fatal: unsafe repository ('/github/workspace' is owned by someone else)
| To add an exception for this directory, call:
|
| git config --global --add safe.directory /github/workspace
Based on the error message I added the following to my GitHub Action:
- name: Fix issue with repository ownership
run: |
git config --global --add safe.directory /home/runner/work/vksm/vksm
git config --global --add safe.directory /github/workspace
I have also added /home/runner/work/vksm/vksm as I was not sure if /github/workspace in the error message is meant as a generic path or not. /home/runner/work/vksm/vksm is where the checkout step puts the repository when the Action runs: /usr/bin/git init /home/runner/work/vksm/vksm
The whole sequence of steps is as follows:
steps:
- name: Checkout the repository
uses: actions/checkout#v2
- name: Fix issue with repository ownership
run: |
git config --global --add safe.directory /home/runner/work/vksm/vksm
git config --global --add safe.directory /github/workspace
- name: Set up Python 3.9
uses: actions/setup-python#v2
...
- name: Install dependencies
run: |
pip install requests
- name: Run Python script
run: |
python script.py
- name: Push data to repo
uses: github-actions-x/commit#v2.8
...
However, the error still occurs.
This questions is possibly related to Cannot add parent directory to safe.directory on git.
Windows 10
In my case "Unsafe repository is owned by someone else" resolved by command in mention folder
Use takeown from the command prompt to take ownership a folder, all its subfolders and files recursively.
takeown.exe /f . /r
This works well, but if you don't run your command line console as administrator it may fail for files you don't own.
This is happening because of a security vulnerability. The error is thrown inside the docker container before you can execute the git config commands to fix the unsafe repository problem. You need to modify the entrypoint of the docker container to execute the git command. You can check this link for details about the vulnerability.
A temporary workaround until git/action owners make a change could be to fork/clone the action that uses docker and modify it with something like this.
#!/bin/bash
set -o pipefail
# config
# ...
# Fix the unsafe repo error which was introduced by the CVE-2022-24765 git patches
git config --global --add safe.directory /github/workspace
#...
You can take a look at the comments in this issue for some ideas about a workaround.
I added the whole path to the current project:
git config --global --add safe.directory '/home/user/AndroidStudioProjects/MyRepoNameInc'
Then performed the push
git commit -m "first commit"
I had this issue with GitLab runner. spent hours doing everything. At last, it started to work after updating .gtlab-ci.yml .
Folder permissions were as below
/var/www/html/project - www-data:www-data
/var/www/html/projcect/.git - gitlab-runner:www-data
Updated script as below.
script:
- git config --global --add safe.directory /var/www/html/phase-3/public-ui

Upload file by git lfs correctly

I tried to upload large file ( 240mb ) to github by lfs by using
- git lfs install
- git init
- git remote add origin "my repo url"
- git lfs track "*.weights"
- git add yolov3.weights
- git commit -m "test"
- git push -u origin master
after uploaded i found the file content
versionversion https://git-lfs.github.com/spec/v1
oid sha256:c49c28814dc8bcd2c48aac1c3e41c92a183cf9b282f6ca4c05f3d99393137952
size 246305388
And not working but the size still 240 mb
How to upload the file right or what is the wrong?
Did you try pushing the code using this command ?
git push origin <branch name> --force
HTTPS protocol can sometimes be unreliable when it comes to pushing large files . It may break unexpectedly
why dont you try pushing the code via SSH method ?
Run these commands below ::
ssh-keygen -t rsa -b 4096 -C "<email id>"
notepad ~/.ssh/<required key>.pub
// paste this public key into your github account
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/<required_key>.pub
You can learn more about the ssh protocol in this article

How to add/update files in git repository from Azure DevOps Pipeline Dynamics 365 CE

Short Version
When a build pipeline is triggered, one of the build pipeline task will get the latest files and it has to be added/updated in the git repository of current running pipeline. I tried to do it by using command line task but its failing as not git repository
fatal: not a git repository (or any of the parent directories): .git
Long Version
I m tried to achieve solution pack and unpack process for dynamics 365 instance. So the build pipeline have the following tasks
Export solution from Dynamics 365 and store it in $(build.binariesdirectory)
Unpack the solution zip file and store in $(Build.Repository.LocalPath) i.e., adding/updating existing files
Command line task to commit and push the files to current pipeline repository
ECHO "Setting git config..."
git config --global user.email "xxx#xyz.com"
git config --global user.name "Admin"
ECHO "CHECK GIT STATUS..."
git status
ECHO "GIT ADD..."
git add -A
ECHO "CHECK GIT STATUS..."
git status
ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"
ECHO "Pushing the changes..."
git push -u origin master
ECHO "Customization Committed Successfully"
Updated
If a pipeline is created with 2 command line task i.e. one to create a random file in the Build.Sourcedirectory and another to commit the changes, then the git commit and push commands are working.
But if we add other tasks (such as unzip files in Build.Sourcedirectory directory) before the command line task then getting error as not a repository.
If you see the below screenshot, in the checkout phase the git repo is cloned to D:\a\1\s
And below screenshot is from command line task, where the current working directory is same as the checkout task (i.e., D:\a\1\s) and we can see that the ".git" folder is present so the current directory has local repository in it, but still getting error as fatal: not a git repository
Am I missing anything here?
By default the source files are checked out to the Build.SourcesDirectory (e.g : Directory: D:\a\1\s), it can be considered as a temporary git repository.
According to the error message, it appears that the working directory of the command line task is not under the Build.SourcesDirectory and you did't git checkout again to that working directory.
So, please try unpack the solution zip file and store in Build.SourcesDirectory, then run below Command line to push the commits (it works for me):
ECHO "Setting git config..."
git config --global user.email "xxx#xyz.com"
git config --global user.name "Admin"
ECHO "CHECK GIT STATUS..."
git status
git checkout -b master
ECHO "GIT ADD..."
git add -A
ECHO "CHECK GIT STATUS..."
git status
ECHO "Commiting the changes..."
git commit -m "Latest Customizations updated"
ECHO "Pushing the changes..."
git push -u origin master
ECHO "Customization Committed Successfully"
Please note that you need to Grant version control permissions to the build service and enable Allow scripts to access the system token.

Pushing on a Git repository with Travis-CI

I want to execute a script every time I push into the master, this script will create some files that I want to commit and push. The log of the Travis build seems to be adding the files, committing and pushing, but nothing happens.
My .travis.yml is this one:
before_install:
- openssl aes-256-cbc -K $encrypted_290c3b2c061d_key -iv $encrypted_290c3b2c061d_iv -in id_rsa.enc -out /tmp/id_rsa -d
- eval "$(ssh-agent -s)" # Start the ssh agent
- chmod 600 /tmp/id_rsa
- ssh-add /tmp/id_rsa
install:
- wget --user $docencia_ac_username --password $docencia_ac_password http://docencia.ac.upc.edu/FIB/grau/PEC/Protegido/Documentacion/eines-sisa-64BITS.tgz
- tar -xf eines-sisa-64BITS.tgz
- export PATH=$PATH:$(pwd)/eines-sisa/bin
script:
- chmod +x ./compile_to_hex.sh
- "./compile_to_hex.sh"
after_success:
- rm -rf $TRAVIS_BUILD_DIR/tmp/
- git config --local user.name "Marc43"
- git config --local user.email "my mail"
- git add $TRAVIS_BUILD_DIR/hex/*
- git commit -m "At $(date) hex files builded - travis-ci [skip ci]"
- git push git#github.com:Marc43/sisa_hexbuilder.git master > /dev/null 2>&1
before_deploy:
- rm -rf eines-sisa*
in the git user.email it really goes my email but I decided to delete it for the question.
And the travis log for the build is:
$ git add $TRAVIS_BUILD_DIR/hex/*
$ git commit -m "At $(date) hex files builded - travis-ci [skip ci]"
[detached HEAD 10e7e48] At Sun Apr 15 08:06:17 UTC 2018 hex files builded - travis-ci [skip ci]
4 files changed, 21 insertions(+)
create mode 100644 hex/exemple.hex
create mode 100644 hex/joc_io.hex
create mode 100644 hex/tb_branch.hex
create mode 100644 hex/tb_sum.hex
I know that there is another way to do this via GitHub tokens or something like that, anyway I don't know how to do it one way or the other. I've tried to do it with the deploy too but it never uploaded my files, just tagged the same commit I did. Any ideas?
Thank you,
Marc
I run several repositories that need documentation compiling to distributable formats (e.g. AsciiDoc to HTML, MD to PDF), rather than having to build and commit every time I want to update the distributable, I’d like to automate this process. This is where I use TravisCI as a build server.
before_install:
- sudo apt-get install pandoc
- gem install asciidoctor
script:
- make
after_success:
- .travis/push.sh
env:
global:
secure: hZJlqgOzA2zIUJSWIka0PylqNaTkfHq+kS48RrHmocrK0vLyCW7ECWrzez2f2RVdTNzPi0b+yJq2uCbFfWjImZqg+XY1I75/CVVdSYMk7PJkYZ/iBDixMYY8CAkRRd5yZft9uZAdZzR4KLCPN18n7qfISv/M9VA8989NKcVyiEU=
push.sh
#!/bin/sh
setup_git() {
git config --global user.email "travis#travis-ci.org"
git config --global user.name "Travis CI"
}
commit_website_files() {
git checkout -b gh-pages
git add . *.html
git commit --message "Travis build: $TRAVIS_BUILD_NUMBER"
}
upload_files() {
git remote add origin-pages https://${GH_TOKEN}#github.com/MVSE-outreach/resources.git > /dev/null 2>&1
git push --quiet --set-upstream origin-pages gh-pages
}
setup_git
commit_website_files
upload_files
Reference - https://gist.github.com/willprice/e07efd73fb7f13f917ea

How to create a new repo at Github using git bash?

How can I create a new repository from my machine using git bash?
I followed the below steps:
mkdir ~/Hello-World
cd ~/Hello-World
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin https://github.com/username/Hello-World.git
git push origin master
But I'm getting "Fatal error: did you run update-server-info on the server? "
You cannot create a repo on github using git bash. Git and github are different things. Github is a platform that let's you host and collaborate on code while git is the version control tool used. You can read more about them on wikipedia articles: github and git.
However if your intention is to create a github repo using terminal, you can do it using the github api and curl.
Probably the easiest way to create a repo on github is somewhere before this line:
git remote add origin https://github.com/username/Hello-World.git
go to https://github.com/new and create a repository on github, then run your last two lines and everything should work.
I have created this bash file to do it all automatically.
#!/bin/sh
reponame="$1"
if [ "$reponame" = "" ]; then
read -p "Enter Github Repository Name: " reponame
fi
mkdir ./$reponame
cd $reponame
curl -u USERNAME https://api.github.com/user/repos -d "{\"name\":\"$reponame\"}"
git init
echo "ADD README CONTENT" > README.md
git add README.md
git commit -m "Starting Out"
git remote add origin git#github.com:USERNAME/$reponame.git
git push -u origin master
So how:
copy the code above. save it as NAME.sh, add it to your PATH. restart terminal or open a new one.
$ NAME newreponame
$ NAME
$ Enter Github Repository Name:
Thanks.
First, try to do this right before the git push:
git pull repo branch
Then try to do the following:
$ git init --bare yourreponame.git
Then do what you were doing before:
touch README
git add README
git commit -m 'first commit'
git remote add origin https://github.com/username/Hello-World.git
git push origin master
I think it is doable.
You can do it using curl (if you are on Windows, you'll have to install it)
curl -u USER https://api.github.com/user/repos -d '{ "name": "REPO" }'
Make sure to replace USER and REPO with your github username and the name of the repository you want to create respectively
It asks for password, input your github admin password and you are good to go.
Actually answered by James Barnett here https://teamtreehouse.com/community/how-does-one-add-a-repository-to-github-using-git-commandline-calls-only
Overview
Command 'git' do not allow you to create repo but it's possible to create new repo at github from BASH script. All solutions use user/password authentication which is deplicated but stil in use. Authentication must be done using personal access token.
Below there are solutions:
3rd party application
https://github.com/github/hub
sudo apt install hub;
cd <folder with code>;
hub init;
hub create -p -d "<repo description>" -h "<project site>" \
"user_name>/<repo_name>";
More options: https://hub.github.com/hub-create.1.html
Pure BASH
REPONAME="TEST";
DOMAIN="www.example.com";
DESCRIPTION="Repo Description";
GITHUB_USER="github_user";
FOLDER="$HOME/temp/$REPONAME";
mkdir -p "$FOLDER"; cd "$FOLDER";
read -r -d '' JSON_TEMPLATE << EOF
{
"name" : "%s",
"description" : "%s",
"homepage" : "%s",
"visibility" : "private",
"private" : true,
"has_issues" : false,
"has_downloads" : false,
"has_wiki" : false,
"has_projects" : false
}
EOF
JSON_OUTPUT=$(printf "$JSON_TEMPLATE" "$REPO_NAME" \
"$DESCRIPTION" "http://$DOMAIN");
# https://developer.github.com/v3/repos/#create-an-organization-repository
curl -u ${GITHUB_USER} https://api.github.com/user/repos \
-d "$JSON_OUTPUT"
just try to add -u in your last line:
git push -u origin master
Maybe you are getting this error because you didn't set your identity:
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe#example.com
Here you can find the steps to create and put your repository on github:
http://programertools.blogspot.com/2014/04/how-to-use-github.html