-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (63 loc) · 2.2 KB
/
cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
name: "Deployment"
on:
push:
paths:
- ".github/workflows/cd.yml"
- ".github/workflows/destroy.yml"
- "setup.py"
- "terraform/**"
- "treehouse/**"
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
steps:
- uses: actions/checkout@v2
- name: Set environment vars
run: |
echo "PYTHON_VERSION=3.8" >> $GITHUB_ENV
echo "PLATFORM_TOOLS_VERSION=$(python setup.py --version)" >> $GITHUB_ENV
working-directory: ./
- name: Use default workspace (main branch)
if: endsWith(github.ref, '/main')
run: |
echo "WORKSPACE=default" >> $GITHUB_ENV
- name: Use custom workspace (feature branch)
if: endsWith(github.ref, '/main') == false
run: |
echo "WORKSPACE=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Create package with dependencies
run: |
python setup.py bdist_egg --dist-dir .
working-directory: ./
- name: Rename egg
run: |
mv platform_tools-${{ env.PLATFORM_TOOLS_VERSION }}-py${{ env.PYTHON_VERSION }}.egg platform_tools.egg
working-directory: ./
- name: Put variables in env var
run: |
echo "VARIABLES_JSON={\"git_branch\": \"${GITHUB_REF#refs/heads/}\", \"platform_tools_artifact_filename\": \"platform_tools.egg\"}" >> $GITHUB_ENV
- uses: Pararius/[email protected]
with:
google_credentials: ${{ secrets.GCLOUD_AUTH_TF_RW }}
terraform_directory: ./terraform
terraform_do_apply: true
terraform_do_destroy: false
terraform_lock: true
terraform_variables: ${{ env.VARIABLES_JSON }}
terraform_workspace: ${{ env.WORKSPACE }}
- name: Send alert for failing apply on main
if: endsWith(github.ref, '/main')
uses: ravsamhq/notify-slack-action@v1
with:
status: ${{ job.status }}
notify_when: "failure"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}