added test setup key #1
@ -19,11 +19,12 @@ jobs:
|
|||||||
id: changed
|
id: changed
|
||||||
run: |
|
run: |
|
||||||
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- 'state/*.json')
|
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- 'state/*.json')
|
||||||
ENVS="[]"
|
ENVS=$(python3 -c "
|
||||||
for f in $FILES; do
|
import os, json
|
||||||
ENV=$(basename "$f" .json)
|
files = '''$FILES'''.strip().split('\n')
|
||||||
ENVS=$(echo "$ENVS" | jq -c ". + [\"$ENV\"]")
|
envs = [os.path.basename(f).replace('.json','') for f in files if f.strip()]
|
||||||
done
|
print(json.dumps(envs))
|
||||||
|
")
|
||||||
echo "envs=$ENVS" >> "$GITHUB_OUTPUT"
|
echo "envs=$ENVS" >> "$GITHUB_OUTPUT"
|
||||||
echo "Changed environments: $ENVS"
|
echo "Changed environments: $ENVS"
|
||||||
|
|
||||||
@ -65,16 +66,24 @@ jobs:
|
|||||||
echo "$RESPONSE" >> "$GITHUB_OUTPUT"
|
echo "$RESPONSE" >> "$GITHUB_OUTPUT"
|
||||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Format plan as markdown
|
- name: Format and post PR comment
|
||||||
id: format
|
|
||||||
if: steps.plan.outputs.response != '{}'
|
if: steps.plan.outputs.response != '{}'
|
||||||
|
env:
|
||||||
|
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
||||||
|
GIT_URL: ${{ secrets.GIT_URL }}
|
||||||
|
RESPONSE: ${{ steps.plan.outputs.response }}
|
||||||
|
ENV_NAME: ${{ matrix.env }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
run: |
|
run: |
|
||||||
cat <<'SCRIPT' > format.py
|
python3 <<'SCRIPT'
|
||||||
import json, sys
|
import json, os, urllib.request, urllib.parse
|
||||||
data = json.loads(sys.stdin.read())
|
|
||||||
|
data = json.loads(os.environ["RESPONSE"])
|
||||||
ops = data.get("operations", [])
|
ops = data.get("operations", [])
|
||||||
summary = data.get("summary", {})
|
summary = data.get("summary", {})
|
||||||
env = sys.argv[1]
|
env = os.environ["ENV_NAME"]
|
||||||
|
|
||||||
lines = [f"## Reconciliation Plan: `{env}`\n"]
|
lines = [f"## Reconciliation Plan: `{env}`\n"]
|
||||||
if not ops:
|
if not ops:
|
||||||
lines.append("No changes detected.\n")
|
lines.append("No changes detected.\n")
|
||||||
@ -86,21 +95,14 @@ jobs:
|
|||||||
lines.append("")
|
lines.append("")
|
||||||
s = summary
|
s = summary
|
||||||
lines.append(f"**Summary:** {s.get('created',0)} create, {s.get('updated',0)} update, {s.get('deleted',0)} delete")
|
lines.append(f"**Summary:** {s.get('created',0)} create, {s.get('updated',0)} update, {s.get('deleted',0)} delete")
|
||||||
print("\n".join(lines))
|
|
||||||
SCRIPT
|
|
||||||
COMMENT=$(echo '${{ steps.plan.outputs.response }}' | python3 format.py "${{ matrix.env }}")
|
|
||||||
echo "comment<<EOF" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "$COMMENT" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Post PR comment
|
comment = "\n".join(lines)
|
||||||
if: steps.plan.outputs.response != '{}'
|
url = f"{os.environ['GIT_URL']}/api/v1/repos/{os.environ['REPO']}/issues/{os.environ['PR_NUMBER']}/comments"
|
||||||
env:
|
body = json.dumps({"body": comment}).encode()
|
||||||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
req = urllib.request.Request(url, data=body, method="POST", headers={
|
||||||
run: |
|
"Authorization": f"token {os.environ['GIT_TOKEN']}",
|
||||||
curl -sf \
|
"Content-Type": "application/json",
|
||||||
-X POST \
|
})
|
||||||
-H "Authorization: token ${GIT_TOKEN}" \
|
urllib.request.urlopen(req)
|
||||||
-H "Content-Type: application/json" \
|
print(f"Posted comment to PR #{os.environ['PR_NUMBER']}")
|
||||||
-d "{\"body\": $(echo '${{ steps.format.outputs.comment }}' | jq -Rs .)}" \
|
SCRIPT
|
||||||
"${{ secrets.GIT_URL }}/api/v1/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
|
|
||||||
|
|||||||
@ -21,11 +21,12 @@ jobs:
|
|||||||
id: changed
|
id: changed
|
||||||
run: |
|
run: |
|
||||||
FILES=$(git diff --name-only HEAD~1 HEAD -- 'state/*.json')
|
FILES=$(git diff --name-only HEAD~1 HEAD -- 'state/*.json')
|
||||||
ENVS="[]"
|
ENVS=$(python3 -c "
|
||||||
for f in $FILES; do
|
import os, json
|
||||||
ENV=$(basename "$f" .json)
|
files = '''$FILES'''.strip().split('\n')
|
||||||
ENVS=$(echo "$ENVS" | jq -c ". + [\"$ENV\"]")
|
envs = [os.path.basename(f).replace('.json','') for f in files if f.strip()]
|
||||||
done
|
print(json.dumps(envs))
|
||||||
|
")
|
||||||
echo "envs=$ENVS" >> "$GITHUB_OUTPUT"
|
echo "envs=$ENVS" >> "$GITHUB_OUTPUT"
|
||||||
echo "Changed environments: $ENVS"
|
echo "Changed environments: $ENVS"
|
||||||
|
|
||||||
@ -80,10 +81,10 @@ jobs:
|
|||||||
echo "$RESPONSE" >> "$GITHUB_OUTPUT"
|
echo "$RESPONSE" >> "$GITHUB_OUTPUT"
|
||||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
STATUS=$(echo "$RESPONSE" | jq -r '.status')
|
STATUS=$(python3 -c "import json,sys; print(json.loads(sys.stdin.read()).get('status','ok'))" <<< "$RESPONSE")
|
||||||
if [ "$STATUS" = "error" ]; then
|
if [ "$STATUS" = "error" ]; then
|
||||||
echo "Reconcile failed for ${{ matrix.env }}"
|
echo "Reconcile failed for ${{ matrix.env }}"
|
||||||
echo "$RESPONSE" | jq .
|
python3 -m json.tool <<< "$RESPONSE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -91,14 +92,14 @@ jobs:
|
|||||||
if: success()
|
if: success()
|
||||||
env:
|
env:
|
||||||
AGE_PUBLIC_KEY: ${{ secrets[steps.env.outputs.age_key] }}
|
AGE_PUBLIC_KEY: ${{ secrets[steps.env.outputs.age_key] }}
|
||||||
|
RESPONSE: ${{ steps.reconcile.outputs.response }}
|
||||||
run: |
|
run: |
|
||||||
KEYS=$(echo '${{ steps.reconcile.outputs.response }}' | jq -r '.created_keys // empty')
|
KEYS=$(python3 -c "import json,os; d=json.loads(os.environ['RESPONSE']); k=d.get('created_keys'); print(json.dumps(k) if k and k != {} else '')")
|
||||||
if [ -n "$KEYS" ] && [ "$KEYS" != "{}" ] && [ "$KEYS" != "null" ] && [ -n "$AGE_PUBLIC_KEY" ]; then
|
if [ -n "$KEYS" ] && [ -n "$AGE_PUBLIC_KEY" ]; then
|
||||||
echo "$KEYS" | age -r "$AGE_PUBLIC_KEY" -o setup-keys-${{ matrix.env }}.age
|
echo "$KEYS" | age -r "$AGE_PUBLIC_KEY" -o setup-keys-${{ matrix.env }}.age
|
||||||
echo "Setup keys for ${{ matrix.env }} encrypted"
|
echo "Setup keys for ${{ matrix.env }} encrypted"
|
||||||
else
|
else
|
||||||
echo "No new keys created for ${{ matrix.env }}"
|
echo "No new keys created for ${{ matrix.env }}"
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Upload artifact
|
- name: Upload artifact
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user