-
Notifications
You must be signed in to change notification settings - Fork 5
84 lines (73 loc) · 2.63 KB
/
environment-cd.yml
File metadata and controls
84 lines (73 loc) · 2.63 KB
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
75
76
77
78
79
80
81
82
83
84
name: Environment CD
on:
push:
branches: [main]
paths: ['environments/**/config.yaml']
permissions:
contents: read
actions: read
jobs:
detect:
runs-on: ubuntu-latest
outputs:
environments: ${{ steps.diff.outputs.items }}
has_changes: ${{ steps.diff.outputs.has_changes }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect changed environments
id: diff
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
pip install pyyaml -q
python scripts/cd/detect_environments.py "$GITHUB_OUTPUT"
apply:
needs: detect
if: needs.detect.outputs.has_changes == 'true'
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
item: ${{ fromJSON(needs.detect.outputs.environments) }}
environment: ${{ matrix.item.github_env }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install Snowflake CLI
uses: snowflakedb/snowflake-cli-action@v2.0
- name: Install dependencies
run: pip install -r scripts/cd/requirements-cd.txt
- name: Compute diff
env:
SNOWFLAKE_ACCOUNT_URL: ${{ vars.SNOWFLAKE_ACCOUNT_URL }}
SNOWFLAKE_USER: ${{ vars.SNOWFLAKE_USER }}
SNOWFLAKE_PAT: ${{ secrets.SNOWFLAKE_PAT }}
SNOWFLAKE_ROLE: ${{ vars.SNOWFLAKE_ROLE }}
NIFI_RUNTIME_PAT: ${{ secrets.NIFI_RUNTIME_PAT }}
run: |
cd scripts/cd
python describe_live_state.py ../../environments/${{ matrix.item.config_env }}/config.yaml > /tmp/live-state.json
python diff_live.py /tmp/live-state.json ../../environments/${{ matrix.item.config_env }}/config.yaml > /tmp/live-diff.json
python translate_live_diff.py /tmp/live-diff.json > /tmp/changes.json
echo "--- Change Plan ---"
cat /tmp/changes.json
- name: Apply changes
env:
SNOWFLAKE_ACCOUNT_URL: ${{ vars.SNOWFLAKE_ACCOUNT_URL }}
SNOWFLAKE_USER: ${{ vars.SNOWFLAKE_USER }}
SNOWFLAKE_PAT: ${{ secrets.SNOWFLAKE_PAT }}
SNOWFLAKE_ROLE: ${{ vars.SNOWFLAKE_ROLE }}
NIFI_RUNTIME_PAT: ${{ secrets.NIFI_RUNTIME_PAT }}
NIFIHUB_REGISTRY_PAT: ${{ secrets.NIFIHUB_REGISTRY_PAT }}
GH_SECRETS_JSON: ${{ toJSON(secrets) }}
GH_VARS_JSON: ${{ toJSON(vars) }}
run: |
cd scripts/cd
python orchestrate.py /tmp/changes.json ../../environments/${{ matrix.item.config_env }}/config.yaml