name: IBM Cloud Auto Restart

on:
  push:
    branches: [ master ]
  schedule:
    - cron: '0 7 * * SUN'

jobs:
  ibm-cloud-restart:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Init
      run: |
        chmod -R 777 ./extra/IBM_Cloud_CLI/
        ./extra/IBM_Cloud_CLI/ibmcloud config --check-version=false
    - name: Login IBM Cloud
      env:
        IBM_ACCOUNT: ${{ secrets.IBM_ACCOUNT }}
        REGION_NUM: ${{ secrets.REGION_NUM }}
      run: |
        ./extra/IBM_Cloud_CLI/ibmcloud login <<EOF
        $IBM_ACCOUNT
        $REGION_NUM
        no
        EOF
    - name: Target IBM Cloud
      env:
        RESOURSE_ID: ${{ secrets.RESOURSE_ID }}
      run: |
        ./extra/IBM_Cloud_CLI/ibmcloud target -g "$RESOURSE_ID"
        ./extra/IBM_Cloud_CLI/ibmcloud target --cf
        ./extra/IBM_Cloud_CLI/ibmcloud cf install -f -v 6.15.0
    - name: Restart IBM Cloud
      env:
        IBM_APP_NAME: ${{ secrets.IBM_APP_NAME }}
      run: |
        ./extra/IBM_Cloud_CLI/ibmcloud cf restart "$IBM_APP_NAME"
