Skip to content

Commit d12d847

Browse files
committed
ci: add environments in github
1 parent 6333b54 commit d12d847

2 files changed

Lines changed: 154 additions & 50 deletions

File tree

.github/workflows/deploy-prod.yaml

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ permissions:
1717
contents: write
1818

1919
jobs:
20-
promote-prod-from-staging:
20+
promote-api-v3-main:
2121
runs-on: ubuntu-latest
22+
environment:
23+
name: api-v3-main
24+
url: https://api-v3-main.cfg.embrio.tech
25+
permissions:
26+
contents: write
27+
deployments: write
2228
steps:
2329
- name: Create GitHub App token
2430
id: app-token
@@ -33,40 +39,90 @@ jobs:
3339
token: ${{ steps.app-token.outputs.token }}
3440
ref: ${{ github.ref }}
3541

36-
- name: Promote staging image tags to production yamls
42+
- name: Promote mainnet (main-s → main)
3743
run: |
3844
set -euo pipefail
39-
promote_pair() {
40-
local staging="$1"
41-
local prod="$2"
42-
local idx qry
43-
idx="$(yq '.indexer.image.tag' "$staging")"
44-
qry="$(yq '.query.image.tag' "$staging")"
45-
export IDX_TAG="$idx" QRY_TAG="$qry"
46-
yq -i '.indexer.image.tag = strenv(IDX_TAG)' "$prod"
47-
yq -i '.query.image.tag = strenv(QRY_TAG)' "$prod"
48-
# Prod now runs this build; avoid duplicate indexers on staging for the same tag.
49-
local prod_idx
50-
prod_idx="$(yq '.indexer.image.tag' "$prod")"
51-
if [ "$idx" = "$prod_idx" ]; then
52-
yq -i '.indexer.enabled = false' "$staging"
53-
fi
54-
}
55-
promote_pair environments/main-s.yaml environments/main.yaml
56-
promote_pair environments/test-s.yaml environments/test.yaml
45+
staging="environments/main-s.yaml"
46+
prod="environments/main.yaml"
47+
idx="$(yq '.indexer.image.tag' "$staging")"
48+
qry="$(yq '.query.image.tag' "$staging")"
49+
export IDX_TAG="$idx" QRY_TAG="$qry"
50+
yq -i '.indexer.image.tag = strenv(IDX_TAG)' "$prod"
51+
yq -i '.query.image.tag = strenv(QRY_TAG)' "$prod"
52+
prod_idx="$(yq '.indexer.image.tag' "$prod")"
53+
if [ "$idx" = "$prod_idx" ]; then
54+
yq -i '.indexer.enabled = false' "$staging"
55+
fi
56+
57+
- name: Commit and push (mainnet)
58+
env:
59+
GIT_AUTHOR_NAME: api-gitops[bot]
60+
GIT_AUTHOR_EMAIL: ${{ secrets.DEPLOYMENT_APP_ID }}+api-gitops[bot]@users.noreply.github.com
61+
GIT_COMMITTER_NAME: api-gitops[bot]
62+
GIT_COMMITTER_EMAIL: ${{ secrets.DEPLOYMENT_APP_ID }}+api-gitops[bot]@users.noreply.github.com
63+
run: |
64+
set -euo pipefail
65+
git add environments/main.yaml environments/main-s.yaml
66+
if git diff --staged --quiet; then
67+
echo "No mainnet env changes to commit."
68+
exit 0
69+
fi
70+
git commit -m "chore(cd): promote api-v3-main from staging yamls"
71+
git push origin "HEAD:${{ github.ref_name }}"
72+
73+
promote-api-v3-test:
74+
needs: promote-api-v3-main
75+
runs-on: ubuntu-latest
76+
environment:
77+
name: api-v3-test
78+
url: https://api-v3-test.cfg.embrio.tech
79+
permissions:
80+
contents: write
81+
deployments: write
82+
steps:
83+
- name: Create GitHub App token
84+
id: app-token
85+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf
86+
with:
87+
app-id: ${{ secrets.DEPLOYMENT_APP_ID }}
88+
private-key: ${{ secrets.DEPLOYMENT_APP_PRIVATE_KEY }}
89+
90+
- name: Checkout release-please branch
91+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
92+
with:
93+
token: ${{ steps.app-token.outputs.token }}
94+
ref: ${{ github.ref }}
95+
96+
- name: Pull latest (includes mainnet promotion commit)
97+
run: git pull origin "${{ github.ref_name }}"
98+
99+
- name: Promote testnet (test-s → test)
100+
run: |
101+
set -euo pipefail
102+
staging="environments/test-s.yaml"
103+
prod="environments/test.yaml"
104+
idx="$(yq '.indexer.image.tag' "$staging")"
105+
qry="$(yq '.query.image.tag' "$staging")"
106+
export IDX_TAG="$idx" QRY_TAG="$qry"
107+
yq -i '.indexer.image.tag = strenv(IDX_TAG)' "$prod"
108+
yq -i '.query.image.tag = strenv(QRY_TAG)' "$prod"
109+
prod_idx="$(yq '.indexer.image.tag' "$prod")"
110+
if [ "$idx" = "$prod_idx" ]; then
111+
yq -i '.indexer.enabled = false' "$staging"
112+
fi
57113
58-
- name: Commit and push to release-please branch
114+
- name: Commit and push (testnet)
59115
env:
60116
GIT_AUTHOR_NAME: api-gitops[bot]
61117
GIT_AUTHOR_EMAIL: ${{ secrets.DEPLOYMENT_APP_ID }}+api-gitops[bot]@users.noreply.github.com
62118
GIT_COMMITTER_NAME: api-gitops[bot]
63119
GIT_COMMITTER_EMAIL: ${{ secrets.DEPLOYMENT_APP_ID }}+api-gitops[bot]@users.noreply.github.com
64120
run: |
65121
set -euo pipefail
66-
git add environments/main.yaml environments/test.yaml environments/main-s.yaml environments/test-s.yaml
122+
git add environments/test.yaml environments/test-s.yaml
67123
if git diff --staged --quiet; then
68-
echo "No environment changes to commit (already promoted)."
124+
echo "No testnet env changes to commit."
69125
exit 0
70126
fi
71-
git commit -m "chore(cd): promote prod image tags from staging yamls"
127+
git commit -m "chore(cd): promote api-v3-test from staging yamls"
72128
git push origin "HEAD:${{ github.ref_name }}"

.github/workflows/deploy-staging.yaml

Lines changed: 74 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
permissions:
15-
contents: write
16-
pull-requests: write
15+
contents: read
1716

1817
jobs:
19-
deploy-staging:
18+
patch-staging-yaml:
2019
if: >-
2120
${{
2221
github.event.workflow_run.conclusion == 'success'
@@ -25,7 +24,67 @@ jobs:
2524
|| github.event.workflow_run.event == 'release'
2625
)
2726
}}
27+
strategy:
28+
fail-fast: true
29+
matrix:
30+
include:
31+
- name: api-v3-main-s
32+
staging: environments/main-s.yaml
33+
prod: environments/main.yaml
34+
url: https://api-v3-main-s.cfg.embrio.tech
35+
- name: api-v3-test-s
36+
staging: environments/test-s.yaml
37+
prod: environments/test.yaml
38+
url: https://api-v3-test-s.cfg.embrio.tech
2839
runs-on: ubuntu-latest
40+
environment:
41+
name: ${{ matrix.name }}
42+
url: ${{ matrix.url }}
43+
permissions:
44+
contents: read
45+
deployments: write
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
49+
with:
50+
ref: main
51+
52+
- name: Set image tag (short SHA)
53+
id: vars
54+
env:
55+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
56+
run: echo "image_tag=sha-${HEAD_SHA::7}" >> "$GITHUB_OUTPUT"
57+
58+
- name: Update staging env and indexer guard
59+
env:
60+
IMAGE_TAG: ${{ steps.vars.outputs.image_tag }}
61+
STAGING: ${{ matrix.staging }}
62+
PROD: ${{ matrix.prod }}
63+
run: |
64+
set -euo pipefail
65+
yq -i ".indexer.image.tag = strenv(IMAGE_TAG)" "$STAGING"
66+
yq -i ".query.image.tag = strenv(IMAGE_TAG)" "$STAGING"
67+
prod_tag="$(yq '.indexer.image.tag' "$PROD")"
68+
if [ "$IMAGE_TAG" = "$prod_tag" ]; then
69+
echo "Tag clash with prod ($PROD): disabling indexer on $STAGING"
70+
yq -i '.indexer.enabled = false' "$STAGING"
71+
else
72+
yq -i '.indexer.enabled = true' "$STAGING"
73+
fi
74+
75+
- name: Upload patched values file
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: ${{ matrix.name }}
79+
path: ${{ matrix.staging }}
80+
81+
open-staging-pr:
82+
needs: patch-staging-yaml
83+
if: success()
84+
runs-on: ubuntu-latest
85+
permissions:
86+
contents: write
87+
pull-requests: write
2988
steps:
3089
- name: Create GitHub App token
3190
id: app-token
@@ -40,34 +99,23 @@ jobs:
4099
token: ${{ steps.app-token.outputs.token }}
41100
ref: main
42101

43-
- name: Set image tag (short SHA)
102+
- name: Download api-v3-main-s values
103+
uses: actions/download-artifact@v4
104+
with:
105+
name: api-v3-main-s
106+
path: .
107+
- name: Download api-v3-test-s values
108+
uses: actions/download-artifact@v4
109+
with:
110+
name: api-v3-test-s
111+
path: .
112+
113+
- name: Set image tag (for PR message)
44114
id: vars
45115
env:
46116
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
47117
run: echo "image_tag=sha-${HEAD_SHA::7}" >> "$GITHUB_OUTPUT"
48118

49-
- name: Update staging envs and indexer guard
50-
env:
51-
IMAGE_TAG: ${{ steps.vars.outputs.image_tag }}
52-
run: |
53-
set -euo pipefail
54-
sync_staging() {
55-
local staging="$1"
56-
local prod="$2"
57-
yq -i ".indexer.image.tag = strenv(IMAGE_TAG)" "$staging"
58-
yq -i ".query.image.tag = strenv(IMAGE_TAG)" "$staging"
59-
local prod_tag
60-
prod_tag="$(yq '.indexer.image.tag' "$prod")"
61-
if [ "$IMAGE_TAG" = "$prod_tag" ]; then
62-
echo "Tag clash with prod ($prod): disabling indexer on $staging"
63-
yq -i '.indexer.enabled = false' "$staging"
64-
else
65-
yq -i '.indexer.enabled = true' "$staging"
66-
fi
67-
}
68-
sync_staging environments/main-s.yaml environments/main.yaml
69-
sync_staging environments/test-s.yaml environments/test.yaml
70-
71119
- name: Open staging deployment PR
72120
id: cpr
73121
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0

0 commit comments

Comments
 (0)