name: gin-vue-admin-backend ci&cd

on:
  push:
    branches: [ action-ci ]

jobs:

  build:
    name: Build
    runs-on: [ self-hosted ]
    steps:

    - name: Check out the repository
      uses: actions/checkout@master

    - name: Show files
      run: |
        pwd
        ls -la

    - name: Get dependencies
      run: |
        go get -v -t -d ./...
        if [ -f Gopkg.toml ]; then
            curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
            dep ensure
        fi
      working-directory: ./server

    - name: Build
      run: |
        su root -p $ROOT_PASS
        go build -o /usr/local/projects/gin-vue/run -v
      working-directory: ./server

    - name: Modify config params
      run: |
        sed -i 's/%{mysql_address}/'$MYSQL_ADDR'/' config.yaml
        sed -i 's/%{mysql_username}/'$MYSQL_USERNAME'/' config.yaml
        sed -i 's/%{mysql_password}/'$MSQL_PASSWORD'/' config.yaml
        sed -i 's/%{redis_address}/'$REDIS_ADDR'/' config.yaml
        sed -i 's/%{redis_password}/'$REDIS_PASSWORD'/' config.yaml
      working-directory: ./server

    - name: Move config file 
      run: | 
        su root -p $ROOT_PASS
        mv ./config.yaml /usr/local/projects/gin-vue/config.yaml
      working-directory: ./server