Github Actions

Introduction

What the hell is Github Actions and Google App Engine?

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Google App Engine is a Platform as a Service and cloud computing platform for developing and hosting web applications in Google-managed data centers. Applications are sandboxed and run across multiple servers.

Ingredients

I’m assuming you’d already have your project up and running locally. Once it’s done you can manually deploy your project to app engine via gcloud app deploy.

  • GAE Project.
    • GCP_SA_KEY Service Account (Download the configuration JSON).
    • GCP_SA_EMAIL Service Account Email.
    • GCP_PROJECT_ID Project ID.
  • Github Repository (If you don’t have your codebase yet, you can use one of the boilerplate of your language of choice offered by Google for GAE).

Secrets

Go to your project’s secrets (https://github.com/<username>/<repository>/settings/secrets) and update the details you just gathered.

Note: For GCP_SA_KEY, you need to first convert the JSON to base64 and then put the base64 value in the secrets. You can get the base64 value by passing your json to base64 binary as base64 -i service-account-config.json.

Setup

  • Go to your project’s actions workspace.
    • https://github.com/<username>/<repository>/actions/new
  • Paste this configuration in the editor and save with whatever name you want to .yml.
name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v2
    
    - name: setup
      uses: zxyle/publish-gae-action@v2.3
      with:
        service_account_email: ${{ secrets.GCP_SA_EMAIL }}
        service_account_key: ${{ secrets.GCP_SA_KEY }}
        project_id: ${{ secrets.GCP_PROJECT_ID }}

    - name: deploy
      run: |
        gcloud auth activate-service-account ${{ secrets.GCP_SA_EMAIL }} --key-file=client-secret.json
        gcloud config set project ${{ secrets.GCP_PROJECT_ID }}
        gcloud -q app deploy app.yaml --promote
  • Commit this workflow file.
  • Now whenever you merge a change to master, it’ll get deployed to App Engine.