I have a CI pipeline that is likely doing something semi-perverted. Let's not debate that part.
As part of the CI, I will generate an artifact (README.md) which I would like to commit and push back to the same repository. Simply using git push origin ... doesn't work due to authentication error.
Am I constrained to using something like a secret variable and a token, and adding another remote so that it can push?
There are ways to add a ssh token to your build runtime which is able to commit or even do a push to origin.
I think even recently GitLab added a new functionality that for each build a unique token is generated which can be used for same sake.
However in general I dont think you can commit anything on the same git base that build is running on, as the check out is in a detached head mode. This means you will not be able to add to history, specially in a remote.
Next problem to consider is what this means if you were able to commit back for the build system, which can potentially trigger another build and a cycle will be triggered.
So probably either use the artifact system for it or do add the ssh token and clone/checkout/commit/push in a separate directory during the build. Anyway this doc explains how to add the token: https://docs.gitlab.com/ee/ci/ssh_keys/README.html
Gitlab seems to change .git folder after fetching project for CI job. I'm not sure it changes only remote section. So I found only solution is to add gitlab-runner user with sshkeys to gitlab. And in my job make git clone in separate folder, make changes, then commit and push it.
Related
How would you use your own fork of Next.js in a project?
I tried using patch-package but the next package gets overridden by Vercel
Also tried releasing to npm but it's pretty difficult since it needs to release to many #next/ packages first
How would you go about this?
Some people frown on this technique, but I've used it in many projects with great success.
tl;dr - fork the repo on git and install directly from git. Works with monorepos by using GitPkg.
Fork the repository you want on git
Clone your new fork: git clone https://github.com/<your-user-name>/<package-name>
Make any changes and push those changes. Take note of the commit hash.
Install the dependency using the following format:
npm install <your-user-name>/<package-name>#<commit-ish>
Important: replace the <commit-ish> with the hash from Step #3 (note: a tag or branch name works too). This step is important as it makes sure you are locked to a specific version.
If you are referencing a monorepo, you can specify the subdir for the particular package you want by using GitPkg.
Continue working like you normally would. As you make changes to the package, you will need to push those changes and repeat Steps #3-4 to get the new changes in your project.
Keeping things up-to-date
To update the package, you will need to merge any new "upstream" changes made by the original author and push those to your forked repository. Then repeat Step #4 above.
Add the original "upstream" remote:
git add upstream https://github.com/vercel/next.js.git
Pull down any changes and merge them - make sure to reference the right branch name:
git fetch upstream
git checkout <main-branch>
git merge upstream/<main-branch>
Resolve any merge conflicts and then push to your fork: git push origin
Repeat step #4 from above for installing the latest changes - make sure to pick a new commit hash or tag in order to get the latest changes.
I am trying to push the selenium scripts to git server so that jenkins will automatically download the latest scripts. I wanted to give web interface to select the automation scripts and upload the same scripts in Git. I want to programatically handle the pushing of choosen files to server so that only those files are run for automation. I need an example from JGit.
You use the PushCommand for invoking a push to a remote server. There are options among others for choosing which remote is pushed to.
Keep in mind that you cannot push some files selectively, but only whole commits on a branch, so there is no way to do what you would like with simple push. An option would be to create separate commits on a separate branch and only push this one branch via defining the references via the PushCommand.add() method.
try (Git git = new Git(repository)) {
git.push().call();
}
See also a related snippet in the jgit-cookbook
We've got a "bare" git repository on a server, for a Web portal project. Several programmers, designers, etc... perform dozens of push and pull from/to it.
Now we want to test the project on the server itself, and always test the last commit through an Apache web server which is installed on the same machine the "bare" git repository is stored in.
How can we 'unbare' the repository, and let the working directory contain always and only the last commit deriving from the last push?
Or anything else aiming to achieve the same result?
You can use a post-receive hook to do a git pull inside your webserver document root/repository.
in your bare repository
do
mv hooks/post-receive.sample hooks/post-receive
chmod +x .git/hooks/post-receive
the post receive should be something like
#!/bin/sh
WEB_ROOT='/var/www/project'
cd $WEB_ROOT
git pull
A more elegant solution that doesn't involve that the web server area being a git repository, you can also review the git documentation about hooks
Note: if you use the simple solution, please make sure that your webserver doesn't serve the .git directory, this would give some hackers/crackers the access to the website source code!
I am a noob in these server related work. I am writing some PHP code in my local system and has been updating my repo in github regularly. Each time I want to test my application, I copy all the files from my local system onto my server through FTP and then do it. Now I want to know whether is there a way to automatically make the commits that I make to reflect in the files in the server. Is there a way to automatically make the server get the files from the repo periodically? (say, once everyday).
Can this be done other way, like when I make a push from my local machine, the repo gets updated and in turn the files on the server also get updated?
My Server Details: Apache 2.2.15, Architecture i686 with Linux Kernel 2.6.18-194.32.1.el5
In addition to cronjobs, you can use a post-receive hook: http://help.github.com/post-receive-hooks/
If you have cronjobs you can use them. First set up the repository on your server. Then you can set up the cronjob, choose a time in which it should be executed, and then in the cronjob execute the following command:
cd your/repository/folder; git pull master origin
Perhaps explore the git archive command, which you can use to get a zip file or similar of your code. You could then perhaps use a script to copy that to your (other) server?
git archive --format=zip --output=./src.zip HEAD
will create a zip file called src.zip from the HEAD of your repo
More info:
http://www.kernel.org/pub/software/scm/git/docs/git-archive.html
Do a "git export" (like "svn export")?
Is there a way to use Github and Unfuddle for the same repo? I am responsible for a repo hosted at Unfuddle, but I am not the main owner and it's private because it's part of an ongoing project. I still need to update the repo there when changes are made, but I would like to use the same set of files to create and update a public Github repo associated with my own account, is that possible? The reason I want to use the same files is that it's a WordPress plugin and it needs to be tested before I commit changes, therefore I need to use one set of files to not complicate the matter. Any help would be appreciated.
You can set up both the repositories as remotes and push/pull to and from both of them; Git is decentralized and thus doesn't really care about whether you have one remote or many.
http://www.kernel.org/pub/software/scm/git/docs/git-remote.html
Example:
git remote add github git#github.com:username/reponame.git
and then...
git push github <branchname>
git pull github
git log github/<branchname>
etc...
Create your github repository, then from your Unfuddle local repository, run:
git remote add github git#github.com:YourUsername/YourReponame.git
Where YourUsername is your github user name, and YourRepository is your repository name. After setting up the github repository, the above URL with the user name and repository name filled in, should appear on your github repository page anyway.
Everything works like you'd expect, for example, pushing:
git push github
Your settings for the Unfuddle repository will work like before.