Run commands in codeship without vm for every commit in a branch - github

I want to deploy my application in github page. I want the build job to be automated. My build commands basically include running unit tests,building a production version, gh-deploy command to deploy to github page. Can i achieve this using code ship. Do i require a actual vm like ec2 to do this?

The official automation process with codeship involves pushing to GitHub.
If your build process can populate the content you want to publish, then you can simply push it from the codeship job itself.
As an example, see "Auto-deploying to gh-pages with Codeship " (Martyn Chamberlin), which is about publishing a Gulp build:
git clone <the ssh link to your repo> dist
cd dist
git checkout gh-pages || git checkout --orphan gh-pages
cd ..
rm -rf dist/**/* || exit 0
npm install
gulp deploy
cd dist
git config user.email "<the email address you used for your machine user GitHub account>"
git config user.name "<the username you used for your machine user GitHub account>"
git add .
git commit -m "Deploy to GitHub Pages: ${CI_COMMIT_ID} --skip-ci"
git push origin gh-pages
This is a clever little set of commands, really.
It’s creating a git repo inside of another git repo in order to handle the build correctly.
I wish I could say I was the one who came up with this idea but the hat tip belongs to Domenic who gave me the idea with his Travis gist.
A few things to note about this:
This assumes that npm install; gulp deploy is the series of commands you use to combine and minify your assets.
That’s true of my project but yours may be different (particularly the second one). Be sure to replace lines 6 and 7 with your actual ones (as well as the values, of course).
This also assumes your output directory is dist. Hopefully it is, because that’s the convention, but if you’ve got something else, you’ll need to update lines 1, 2, and 8.
I’m completely bypassing Codeship’s recommendation of handling the final git push via their own provided code (“include the commands from continuous-deployments/git-push.sh”).
Not a big deal either way, I just don’t see the need for an extra HTTP request.

Related

Upload to Heroku from GitHub other ways

As the GitHub linking is no longer working due to security issues, my app is still on GitHub and I want to put it on Heroku how do I do this easily?
As the security notification says, you can still deploy via git push.
Assuming you have a local copy of your repository¹ and you would normally do something like git push origin main to deploy to GitHub:
cd to your project directory
Check your remotes:
git remote -v
Do you see a Heroku remote?
If so, make note of its name and go to the next step.
Otherwise, add one:
heroku git:remote -a YOUR_APP_NAME
Now, push directly to the Heroku remote. Assuming it is called heroku:
git push heroku main
You'll probably also want to push to GitHub to ensure the code for your latest release is synced.
I believe this is the simplest option if you're migrating from GitHub integration, but the documentation also lists other options:
Docker-based deployments
Using dpl
Via Git hook
Via Terraform
¹If, for whatever reason, you don't have a local copy of your repository, git clone it from GitHub and then proceed as above.

Using github CLI (cli/cli) to deploy repo

Trying to deploy internal development from GitHub to a Centos 7 webserver, running into 2 issues.
Firstly, I'm using PHP and need to deploy the class files to a folder that is not /var/www/html/, where I have cloned the repository to using
cd /var/www/
gh repo clone linkto/repo html (this may be the wrong thing to do).
Secondly, Prompting me to think that I've done the first part wrong, when trying to use gh repo sync linkto/repo i get the error can't determine source repository for GitUser/home because repository is not fork leading me to believe that instead of cloning I need to fork it. My intention here is that no code would ever be changed on the server-side just updated on GitHub then push to the server. Am I trying to do too much with GitHub? or am I trying to do it wrong?
EDIT:
doing cd /var/www/html/ gh repo fork gh repo sync and setting a remote back to the origin has solved the second issue
Thanks,
In
cd /var/www/html/
Running once to setup:
gh repo fork with a remote set to the origin
Each time to update:
gh repo sync setting the base repository each time to update
Then using
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
a server-side post-receive hook to move the classes directory to the desired location

Not able to upload file in the github repository

I am new to GitHub and I have to submit one assignment through GitHub.
I have been reading this blog for uploading files through github, but am not able to see any button labeled Upload files on my home screen of the repository
What am I missing?
See the "or push an existing repository from the command line" to push existant files to your repository. You won't have to load them by a form but with your command line from your project.
Github does not work like cloud storage platform. You actually need to have git installed on your computer in order to be able to push code to your repositories.
First of all, you need to install git( download links here ).
Then you need to init your local repositories with git init. Caution you need to run this command inside the directory your code is placed.
Run git add --all to stage the changes
Run git commit -m "your message" to commit your changes
Run git add remote origin (repo_link or ssh) to add your Github repo as a remote repository
Run git push -u origin master to push your master branch to remote origin
This might look a lot at first place but, you 'll get used to it really soon
Alternative
You can also the git and GitHub GUI which are much friendlier for a beginner.

GitHub pipeline/CI to generate files and push them back to the repository

I maintain a public repository on GitHub where changes are only made to a single YAML file. I'm looking for a solution to process that file on every push and generate files based on it. Essentially, a pipeline or CI should parse the file and create many different markdown files. These files (or more specifically, the changes to these files) should then be pushed back to the repository.
Requirements:
Manual changes to the YAML file and automatic changes to the markdown files should both be pushed to the master branch.
The version history should be kept (e.g. forced push might not work).
There is an arbitrary number of files that are generated.
There are Travis providers for GitHub Pages and GitHub Releases. But both have limitations that make them unsuitable for my requirements.
Using what tool/CI/pipeline can I achieve that on GitHub? I would prefer a service over a self-hosted CI.
Assuming that you already have the program/script to parse the YAML file and to generate the Markdown files, I can give you some insights on how I would do this from Jenkins CI. While I draw my experience from running my own instance, there are also hosted options such as CloudBees that you can explore.
Create a new Jenkins Freestyle project.
Under the Source Code Management section, configure your GitHub project coordinates.
Under Build Triggers section, activate the 'Build when a change is pushed to GitHub' option. That would launch the CI job at the moment you push a new version of the YAML file into the repository.
Under the build section, add an Execute shell build step.
In the shell step, launch the program or script that processes the YAML file/generates the .md files. End the script by adding the git add ., git commit -m "message", git pull and git push commands (assumes git is in the path).
Enable the new job to make it active in Jenkins.
You can do this now with the free GitHub Actions option for the repositories.
You need to put this step into your YAML file.
- name: Commit back to GitHub
run: |
git config --global user.name "github-actiuons[bot]"
git config --global user.email "41898282+github-actions[bot]#users.noreply.github.com"
git add -A
git commit -m "Updating some file"
git push
There are some items in the marketplace, but they didn't work for me.
The email of the bot is based on this thread:
https://github.community/t/github-actions-bot-email-address/17204
Update the commit message.
Be careful with the folder paths if you decide to push a specific file in a folder.

One way hg to git sync

I have a mercurial repository which contains a monolith project I am trying to gradually split. While doing those, I figured I would convert the new sub projects to git hence the one way sync.
A few more details about what I am doing:
the hg repo and the new git repos are located in a private bitbucket cloud account.
I want to keep the commits history while doing the split
All our development is Windows based (although I'm open to do the migration using a unix based system)
the initial repo is 7 years old, it has all sort of tags, closed branches, some branches with unsupported git characters. But more importantly I am happy if I can migrate only the default/master (if it helps me get the job done and doesn't imply losing history)
As we are gradually converting some projects inside the repo (lets say I have 30 projects and I want incrementally to move them) I need to do one way syncs from hg to git. I am not afraid of the merges and I am happy to keep my new repo work outside of master and then just rebase with the hg changes as we go.
I get the idea our mercurial repo is not properly configured (I saw multiple heads, etc) but I am outside my comfort zone when I dig deep into into mercurial backbone.
So far I tried several tools such as fast-export, mercurial hg hggit plugin. However I am struggling to find good step by step tools. (and almost all approaches in this thread Convert Mercurial project to Git)
fast-export was the tool that gave me the best results, I was able to migrate the project once and everything but when I tried to resync I started to get errors, like branch modified outside and multiple heads.
Now that I explained my problem in more detail I can ask the question.
What would be the best approach and tools to use for me to be able to do a one way hg to git migration?
Also, how can I make sure my mercurial repository is correctly configured to avoid any potential issues when migrating to git?
After countless tries, I think I found a way to do what I wanted in a consistent way. For future reference this were the steps:
Installing Necessary tools
Install Git for Windows
Install Tortoise HG or Mercurial standalone
Install Python 2.7 (fast-export does not support Python 3.X at the moment)
Open a Command Line prompt (Run as Admin).
Check if you can run git, mercurial and python as follow:
$ git
$ mercurial
$ python
If you have installed the other ones above and you are getting errors you need to set the path, in my case I only had to do it for Python. So I did:
$ setx path "%path%;C:\Python27"
restart the command prompt and everything should be ready to go.
Install fast-export and clone the mercurial and git repos
Create a clean directory so the work will be contained in there (In my case I wont use the repos inside this directory for anything other than syncing the projects). e.g:
c:\syncprojects
From inside c:\syncprojects start by cloning fast-export
$ git clone https://github.com/frej/fast-export.git fast-export
Then clone the mercurial project
$ hg clone https://bitbucket.org/user/mercurialrepo
Then clone the git project you want to sync into
$ git clone https://bitbucket.org/user/gitrepo gitrepo
It helped me to have a authors file configured correctly so I did
$ cd mercurialrepo
$ hg log | grep user: | sort | uniq | sed 's/user: *//' > ../authors
Then open the authors file which was created in c:\syncprojects make sure the authors file matches something similar to this:
bob=Bob Jones <bob#company.com>
bob#localhost=Bob Jones <bob#company.com>
bob <bob#company.com>=Bob Jones <bob#company.com>
Next step is to start the actual migration, for this step I felt more comfortable using the git bash so I did: In windows explorer, right click on the gitrepo folder and select "Git Bash here"
Then I made my local git repo case sensitive, this helps with the process but its a good thing to have, as I run in to problems with case sensitive folders in the past. Just do:
git config core.ignoreCase false
Trigger the sync
Finally I did:
$ c:\syncprojects\fast-export\hg-fast-export.sh -r c:\syncprojects\mercurialrepo -A c:\syncprojects\authors --force
If all goes well (and this does not necessarily happen all the time, for multiple reasons I had issues with the heads in mercurial, issues with local changes in the git repo I am trying to sync into).
All we need to do is checkout the head and push the changes to remote, as such:
$ git checkout HEAD
$ git push -u origin master
The next time you want to do a sync just repeat the final part:
$ c:\syncprojects\fast-export\hg-fast-export.sh -r c:\syncprojects\mercurialrepo -A c:\syncprojects\authors --force
$ git checkout HEAD
$ git push -u origin master
Unfortunately the steps are not as fast forward as it looks but this was the more concise and consistent way I found to tackle my problem.
A few more tips:
I did not merge any new code to master in the newly created git repo.
Until I am totally satisfied and able to stop the sync I will have a
branch that contains the changes I do in my day to day and
periodically merge master back into that branch.
Do not use this repos for development, fast-export stores data inside
the repos that might get lost and make the re-syncing project very
hard to achieve. Clone the repos in a separate location (and please
be careful with checking other branches out in this repos for the
same reason).