otiai10/amesh-bot

View on GitHub
.github/workflows/gae-deploy.yml

Summary

Maintainability
Test Coverage
name: GAE Deploy

on:
  push:
    branches: [ main, develop ]

jobs:

  validate:
    name: Build
    runs-on: ubuntu-latest
    env:
      GO111MODULE: "on"
    steps:
    - name: Set up Go 1.18
      uses: actions/setup-go@v3
      with:
        go-version: 1.18
    - name: Check out code into the Go module directory
      uses: actions/checkout@v3
    - name: Get dependencies
      run: go get -v -t -d ./...
    - name: Build
      run: go build -v .
    - name: Test
      run: go test -v -cover -race -coverprofile=coverage.txt -covermode=atomic

  gae-deploy:
    name: GAE Deploy
    if: github.ref == 'refs/heads/main'
    needs: [validate]
    runs-on: ubuntu-latest
    steps:
    - name: Check out code into the Go module directory
      uses: actions/checkout@v3
    - name: Auth GCP
      uses: google-github-actions/auth@v1
      with:
        credentials_json: '${{ secrets.GCP_SA_KEY }}'
    - name: Set up Cloud SDK
      uses: google-github-actions/setup-gcloud@v1
    - name: Recover App Secrets
      run: 'echo "$APP_SECRETS_YAML" > app-secrets.yaml'
      shell: bash
      env:
        APP_SECRETS_YAML: ${{ secrets.APP_SECRETS_YAML }}
    - name: Deploy
      run: gcloud app deploy ./app.yaml --no-cache --quiet
    - name: Announce
      run: |
        curl -XPOST \
          -d "{
            \"channel\": \"${{ secrets.AMESH_DEV_PROJECT_CHANNEL }}\",
            \"text\": \":tada: 新しいバージョンがproduction環境にデプロイされました.\nhttps://github.com/${GITHUB_REPOSITORY}/commits/main\",
            \"unfurl_links\": false
          }" \
          -H "Authorization: Bearer ${{ secrets.AMESH_DEV_BOT_ACCESS_TOKEN }}" \
          -H "Content-Type: application/json" \
          https://slack.com/api/chat.postMessage

  gae-deploy-dev:
    name: GAE Deploy DEV
    if: github.ref == 'refs/heads/develop'
    needs: [validate]
    runs-on: ubuntu-latest
    steps:
    - name: Check out code into the Go module directory
      uses: actions/checkout@v3
    - name: Auth GCP
      uses: google-github-actions/auth@v1
      with:
        credentials_json: '${{ secrets.GCP_SA_KEY }}'
    - name: Set up Cloud SDK
      uses: google-github-actions/setup-gcloud@v1
    - name: Recover App Secrets DEV
      run: 'echo "$APP_SECRETS_DEV_YAML" > app-secrets.dev.yaml'
      shell: bash
      env:
        APP_SECRETS_DEV_YAML: ${{ secrets.APP_SECRETS_DEV_YAML }}
    - name: Deploy DEV
      run: gcloud app deploy ./app.dev.yaml --no-cache --quiet
    - name: Announce
      run: |
        curl -XPOST \
          -d "{
            \"channel\": \"${{ secrets.AMESH_DEV_PROJECT_CHANNEL }}\",
            \"text\": \":robot_face: [DEV環境の自動更新]\nhttps://github.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}\"
          }" \
          -H "Authorization: Bearer ${{ secrets.AMESH_DEV_BOT_ACCESS_TOKEN }}" \
          -H "Content-Type: application/json" \
          https://slack.com/api/chat.postMessage