DEV Community

Kay Gosho
Kay Gosho

Posted on

1 1

Kick CircleCI from Slack command + Google Apps Script

I've automated app deployment with CircleCI + Slack + Google Apps Script.

  1. Create slack bot

  2. Get Slack Webhook token

  3. Create CircleCI Job

  4. Get CircleCI Token

  5. Create Google Apps Script:

const GITHUB_REPO = 'account/repo'
const CIRCLE_TOKEN = '***'
const SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/***/***/***'

function doPost(e) {
  const branch = e.parameters.text[0];

  _deployToCircle('deploy', branch);

  return ContentService.createTextOutput('ok');
}

function _deployToCircle(circleJob, branch) {
  const url = 'https://circleci.com/api/v1.1/project/' + GITHUB_REPO + 'tree/' + branch + '?circle-token=' + CIRCLE_TOKEN;
  const payload = {
    build_parameters: {
      CIRCLE_JOB: circleJob,
      STAGING: 'true', // additional params
    }
  }
  const circleRes = UrlFetchApp.fetch(url, {
    method: 'post',
    muteHttpExceptions: true,
    contentType: 'application/json',
    payload: JSON.stringify(payload),
  });
  Logger.log(circleRes.getResponseCode());
  Logger.log(circleRes.getContent());

  const message = 'branch deploy start: ' + branch + '\nCircleCI response: ' + circleRes.getResponseCode()

  const slackRes = UrlFetchApp.fetch(SLACK_WEBHOOK_URL, {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify({ text: message }),
  });
  Logger.log(JSON.stringify(slackRes));
}

function doPostTest() {
  doPost({
    parameters: {
      text: ['branch_name_to_deploy'],
    }
  })
}
Enter fullscreen mode Exit fullscreen mode
  1. Set Slack command to kick the Google Apps Script

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay