Blogs

How to create a CI/CD pipeline with GitHub Actions for Hostinger

06/18/24

My Blog Post

quote

Will write the detailed steps for this blog in upcoming few days, stay tuned.

name: Deploy a ReactJS website automatically to hostinger



on:

  push:

    branches:

      - master

env:

  CI: false



permissions:

  contents: write



jobs:

  build:

    runs-on: ubuntu-latest



    name: Build and Push

    steps:

      - name: git-checkout

        uses: actions/checkout@v4

        with:

          fetch-depth: 0



      - name: Setup Node.js

        uses: actions/setup-node@v2

        with:

          node-version: "20"



      - name: Install all dependencies

        run: npm install



      - name: Build

        run: npm run build



      - name: Check if branch exists

        id: checkbranch

        run: |

          BRANCH_EXIST=$(git ls-remote --heads origin build | wc -l)

          echo "BRANCH_EXIST=$BRANCH_EXIST" >> $GITHUB_ENV

      - name: Create branch if not exists

        run: git push origin HEAD:build

        if: env.BRANCH_EXIST == '0'



      - name: Push

        uses: s0/git-publish-subdir-action@develop

        env:

          REPO: self

          BRANCH: build

          FOLDER: dist 

          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

          MESSAGE: "Build: ({sha}) {msg}" # The commit message