Skip to content

Commit

Permalink
🐝 destroy staging server on PR merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold committed Oct 20, 2023
1 parent e511b78 commit a85ba65
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/scripts/buildkite_destroy_staging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
import os

import requests

organization_slug = "our-world-in-data"
pipeline_slug = "grapher-destroy-staging-environment"
api_access_token = os.environ["BUILDKITE_API_ACCESS_TOKEN"]

url = f"https://api.buildkite.com/v2/organizations/{organization_slug}/pipelines/{pipeline_slug}/builds"

headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_access_token}",
}

payload = {
"commit": "HEAD",
"branch": "master",
"message": "Triggered build via Github action in etl repository",
"env": {
"BRANCH": os.environ["BRANCH"],
},
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 201:
print("Build successfully triggered!")
print(json.dumps(response.json(), indent=2))
else:
print(f"Error: {response.status_code}")
print(response.text)
28 changes: 28 additions & 0 deletions .github/workflows/buildkite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Buildkite

on:
pull_request:
types:
- closed

jobs:
destroy_staging:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install dependencies
run: pip install requests

- name: Run script
env:
BUILDKITE_API_ACCESS_TOKEN: ${{ secrets.BUILDKITE_API_ACCESS_TOKEN }}
BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
python .github/scripts/buildkite_destroy_staging.py

0 comments on commit a85ba65

Please sign in to comment.