Introduction
In this tutorial I will show how to use the api that github offers us through its token, to apply an action for the continuous deployment of private repositories.
Create token
- Open settings of our account.
- Click on the
Developer settingsoption.
- Click on the
Personal access tokens option.
- Click on
generate new tokenand copy and save it to use it.
Create secret keys needed to use them in the actions
- Open the settings of our project and click on the Secrets section.Open the settings of our project and click on the Secrets section. In my case I have the following secret keys:
Repository url via API
To download the latest changes from the private repository we will use the github api together with our previously generated and configured token, so that it is as follows:
- git pull
https://${{ secrets.GIT_TOKEN }}:x-oauth-basic@github.com/susomejias/portfolio.gitmaster
Example for a deployment of a private repository in a VPS
Within our project we will create a folder called
.githuband in another one calledworkflowsthe latter will contain the files for our actions.In this example we will create a file called
ci.ymlwhich will contain the functionality of the action.In my case I have used the example of the action that I use for the deployment of my portfolio:
name: CI
on: [push]
jobs:
deploy:
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Push to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: cd ${{ secrets.PROJECT_PATH }} && git pull https://${{ secrets.GIT_TOKEN }}:x-oauth-basic@github.com/susomejias/portfolio.git master && npm install && ng build --prod && cp htaccess dist/portfolio/
Perform a upload to test the new action
Thanks for reading me. 😊





Top comments (4)
If you're using
actions/checkout@v2you now need to use the following config to prevent your inline token being overridden and npm/yarn failing to reach your private repo:Wow this is waay better than the github doc, Thank You.
Thanks for your comment! 🤗
Thanks mate!! You saved my ass. I'd spent several hours before I found your post. Btw
persist-credentials: falsecomment from above didn't work for me.