name: Manual Deploy [cardie]

on:
  workflow_dispatch:
    inputs:
      ref:
        description: Git branch/tag
        required: true
      environment:
        description: Deployment environment
        required: false
        default: staging

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.ref }}

      - name: Install apt packages including waypoint
        run: |
          curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
          sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
          sudo apt-get install awscli waypoint

      - name: Set up env
        env:
          INPUT_ENVIRONMENT: ${{ github.event.inputs.environment }}
        run: |
          if [ "$INPUT_ENVIRONMENT" = "staging" ]; then
            echo "AWS_ACCESS_KEY_ID=${{ secrets.STAGING_WAYPOINT_AWS_ACCESS_KEY }}" >> $GITHUB_ENV
            echo "AWS_SECRET_ACCESS_KEY=${{ secrets.STAGING_WAYPOINT_AWS_SECRET }}" >> $GITHUB_ENV
            echo "WAYPOINT_SERVER_TOKEN=${{ secrets.STAGING_WAYPOINT_SERVER_TOKEN }}" >> $GITHUB_ENV
            echo "WAYPOINT_SERVER_ADDR=${{ secrets.STAGING_WAYPOINT_SERVER_ADDR }}" >> $GITHUB_ENV
          else
            echo "unrecognized environment"
            exit 1;
          fi

      - uses: volta-cli/action@v1

      - name: Set up yarn cache
        uses: actions/cache@v2
        with:
          path: ~/.cache/yarn
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - run: yarn --prefer-offline

      - name: Deploy cardie
        run: waypoint up --app=cardie -prune-retain=0 -plain
        env:
          AWS_DEFAULT_REGION: us-east-1
          WAYPOINT_SERVER_TLS: 1
          WAYPOINT_SERVER_TLS_SKIP_VERIFY: 1

Add manual workflow for cardie
ci: Add manual workflow for cardie
