Skip to content

Deploy Angular to Production with Github Actions

Posted in Javascript, and Server

Github Actions is cool. Angular is the best. Deploy your Angular application with Github Actions. Here’s how

To create your Github action, you can go here:

Create a blank workflow, and copy paste the section below

name: CI

on: [push]


    # using Ubuntu
    runs-on: ubuntu-latest

    - uses: actions/checkout@v1
    - uses: actions/setup-node@v1 #this installs node and npm for us
        node-version: '10.x'

    - uses: actions/cache@v1 # this allows for re-using node_modules caching, making builds a bit faster.
        path: ~/.npm
        key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-node-

    - run: npm install
    - run: npm install -g @angular/cli > /dev/null
    - run: ng build --prod

    - name: copy file via ssh key
      uses: appleboy/scp-action@master
        USERNAME: khophi
        PORT: 22
        KEY: ${{ secrets.forSSH }}
        source: "./dist/your-angular-app-name/"
        target: "/home/user/"
        strip_components: 3 # this is important

For the above workflow to work, the last step is to add the contents of your ~/.ssh/id_rsa to

That way, the KEY: ${{ secrets.forSSH }} part will work. Remember to name it forSSH or anything you like, and change it accordingly in the above workflow script.

That way, the above will copy the contents after the build looks like this

The destination folder is /home/user/

The source folder, which is the temporal project folder created by github during the actions is ./dist/your-project name

I hope the above helps. Happy coding!