DEV Community

Hao Yang
Hao Yang

Posted on

CI/CD for Kotlin and CloudFunctions

My Workflow

This is a workflow that covers Kotlin Building, Test Coverage Badge Generation and Cloud Functions Deployment.

At the begging of the year I wanted to create a project to try out serverless computation and cloud-native, using Kotlin with the Cloud Functions form GCP seems like a good start point to me, so I created a small crawler to crawl some apartment buying registration information and send out an email notification. (In my city the building companies publish buying registration information once they decide to start selling, and you need to register first if you want to buy one).

So my next problem was to create a CI/CD pipeline, which I decided to try out Github Actions, and I was happy to found out there are already some great actions that could help me to generate a fancy test coverage badge and deploy my code to Cloud Functions easily. By leveraging cicirello/jacoco-badge-generator@v2 and google-github-actions/deploy-cloud-functions@v0.1.2, my pipeline was built quickly.

And the final result looks like this:

Submission Category:

Wacky Wildcards

Yaml File or Link to Code

name: CI/CD

    branches: [ master ]
      - src/**

  # Allows you to run this workflow manually from the Actions tab

    runs-on: ubuntu-latest

      - uses: actions/checkout@v2

      - name: Set up JDK 8
        uses: actions/setup-java@v2
          java-version: '8'
          distribution: 'adopt'

      - name: Build with Gradle
        run: ./gradlew build

      - name: Generate JaCoCo Badge
        uses: cicirello/jacoco-badge-generator@v2
          jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv
          generate-branches-badge: true

      - name: Log coverage percentage
        run: |
          echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
          echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"

      - name: Commit and push the badge (if it changed)
        uses: EndBug/add-and-commit@v7
          default_author: github_actions
          message: 'doc: update badge'
          add: '*.svg'

      - name: Upload JaCoCo coverage report
        uses: actions/upload-artifact@v2
          name: jacoco-report
          path: build/reports/jacoco/test/html

    needs: build
    runs-on: ubuntu-latest

      - uses: actions/checkout@v2

      - name: Cloud Functions Deploy
        uses: google-github-actions/deploy-cloud-functions@v0.1.2
          credentials: ${{ secrets.GCP_SA_KEY }}
          name: apartment-registration-alert
          region: asia-northeast1
          env_vars: AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }},AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
          entry_point: Application
          runtime: java11
          service_account_email: ${{ secrets.SERVICE_ACCOUNT_EMAIL }}
          max_instances: 1
          event_trigger_type: google.pubsub.topic.publish
          event_trigger_resource: projects/apartment-registration-alert/topics/schedule-trigger

Enter fullscreen mode Exit fullscreen mode

GitHub logo hyrepo / apartment-registration-notification

A serverless, cloud-native crawler that uses AWS and GCP free tier to crawl apartment purchasing information and sending email notifications.

License Continuous Delivery Coverage Branches

This application crawls apartments information hourly, if there are new apartments in particular areas open for purchase, then an email notification will be triggered.

The logic is pretty simple, but the main purpose of this application is to try out:

  • Running an application in the cloud for totally free
  • Serverless computation
  • Cloud-native




All cloud components are covered in the free tier as bellow, this application cost $0.

Component Type Free Tier Platform
Cloud Functions Serverless Platform(FaaS) 200M calls / month GCP
Cloud Scheduler Scheduler 3 jobs / month GCP
Cloud Pub/Sub Message Service 10GB / month GCP
Cloud Firestore NoSQL DB 1GB storage, 50000 reads & 20000 writes / day GCP
SNS Notification Service 1000 Email AWS

Top comments (0)