Github action

Github build and deploy to my server

name: DeployMain

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    #if: contains(github.event.head_commit.message, 'deploy')
    steps:
      - name: Send message start
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.chatid }}
          token: ${{ secrets.tele }}
          message: setup environment for build
      - name: Install SSH Key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.KEY }}
          known_hosts: 'just-a-placeholder-so-we-dont-get-errors'
      - name: Adding Known Hosts
        run: ssh-keyscan -p ${{ secrets.PORT }} -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
      - uses: actions/checkout@v3
      - name: Set up JDK 1.8
        uses: actions/setup-java@v3
        with:
          java-version: '8'
          distribution: 'temurin'
          cache: maven
      - name: Send message before build
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.chatid }}
          token: ${{ secrets.tele }}
          message: setup done. build project. waits
      - name: Build with Maven
        run: mvn -B package --file pom.xml
      - name: Send message after build
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.chatid }}
          token: ${{ secrets.tele }}
          message: build done. clean up
      - name: Clean build
        run: rm -rf ./target/*.jar && rm -rf ./target/unwoven-*
      - name: Send message before deploy
        uses: appleboy/telegram-action@master
        with:
          to: ${{ secrets.chatid }}
          token: ${{ secrets.tele }}
          message: clean up done. deploy
      - name: Backup old class
        run: ssh -p ${{ secrets.PORT }} root@${{ secrets.HOST }} "./game/backup.sh"
      - name: Deploy with rsync
        run:  rsync -avh --delete -e "ssh -p ${{ secrets.PORT }}" ./target/ root@${{ secrets.HOST }}:/root/game/target/
      - name: Restart Server
        run: ssh -p ${{ secrets.PORT }} root@${{ secrets.HOST }} "./game/silenceRun.sh"
This entry was posted in tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *