In this article we will deploy our Angular app to shared hosting like hostgator service via Github actions and FTP credentials of the shared hosting server.
We will create and push our application to GitHub repository and we have to create an actions on the same repository. Create a file named “dev.yml” and provide the following context –
name: DEV - Angular Application
on:
push:
branches: [ "develop" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build_dev
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: node-app
path: ./dist/<YOUR_PROJECT_NAME>
deploy:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: 'Development'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: node-app
- name: Sync files
uses: SamKirkland/FTP-Deploy-Action@v4.3.4
with:
server: ${{ secrets.FTP_SERVER }}
protocol: ftp
port: 21
username: ${{ secrets.FTP_USER }}
password: ${{ secrets.FTP_PWD }}
exclude: |
**/.git*
**/.git*/**
**/node_modules/**
*.exe
appsettings.json
appsettings.development.json
web.config
Replace <YOUR_PROEJCT_NAME> with your actual project name and commit it on github repositiory.
We also have to create few Environment variable on GitHub for FTP credentials.
FTP_SERVER
FTP_USER
FTP_PWD
Now onward whenever you push your code on “develop” branch it will trigger the build and after completing successful build of your app it will push the build to your shared hosting server.