-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (124 loc) · 4.42 KB
/
ci-dryrun.yaml
File metadata and controls
148 lines (124 loc) · 4.42 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
###############################################################################
# CI Dry-Run — Validates templates and demo
#
# Runs on push to main, PRs, and manual dispatch.
# Catches regressions in YAML syntax, shell scripts, version extraction,
# GHCR tag discovery, and the release-PR logic.
###############################################################################
name: "CI: Dry-run validation"
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
lint-yaml:
name: Lint YAML
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install yq
run: |
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/v4.44.6/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
- name: Validate all YAML files
run: |
status=0
while IFS= read -r f; do
if yq e '.' "$f" > /dev/null 2>&1; then
echo "OK: $f"
else
echo "FAIL: $f"
status=1
fi
done < <(find templates demo -name '*.yaml' -o -name '*.yml' | sort)
exit $status
lint-shell:
name: Lint Shell
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run shellcheck on deployment scripts
run: |
shellcheck templates/gitops-ci/deployment.sh
shellcheck demo/projects/demo-app/deployment.sh
test-version-extraction:
name: Test version extraction
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Extract and assert versions from demo .env
run: |
ENV_FILE="demo/projects/demo-app/.env"
source "${ENV_FILE}"
echo "backend=${BACKEND_TAG} frontend=${FRONTEND_TAG}"
errors=0
if [[ "${BACKEND_TAG}" != "0.24.0" ]]; then
echo "FAIL: BACKEND_TAG=${BACKEND_TAG}, expected 0.24.0"
errors=$((errors + 1))
fi
if [[ "${FRONTEND_TAG}" != "0.23.0" ]]; then
echo "FAIL: FRONTEND_TAG=${FRONTEND_TAG}, expected 0.23.0"
errors=$((errors + 1))
fi
if [[ $errors -gt 0 ]]; then
echo "::error::${errors} version extraction assertion(s) failed"
exit 1
fi
echo "All version extraction assertions passed"
test-ghcr-tag:
name: Test GHCR tag discovery
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Discover latest trivy tag
id: discover
uses: ./templates/gitops-ci/.github/actions/ghcr-latest-tag
with:
image: "aquasecurity/trivy"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Assert tag is non-empty semver
env:
TAG: ${{ steps.discover.outputs.tag }}
run: |
echo "Discovered tag: ${TAG}"
if [[ -z "${TAG}" ]]; then
echo "::error::GHCR tag discovery returned empty"
exit 1
fi
if [[ ! "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Tag '${TAG}' is not a valid semver"
exit 1
fi
echo "Tag '${TAG}' is valid semver"
test-release-pr-dryrun:
name: Test release PR (dry-run)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Discover latest tag
id: discover
uses: ./templates/gitops-ci/.github/actions/ghcr-latest-tag
with:
image: "aquasecurity/trivy"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Compare with demo .env
env:
LATEST_TAG: ${{ steps.discover.outputs.tag }}
run: |
ENV_FILE="demo/projects/demo-app/.env"
source "${ENV_FILE}"
currentTag="${BACKEND_TAG}"
echo "Current pinned: ${currentTag}"
echo "Latest on GHCR: ${LATEST_TAG}"
if [[ "${currentTag}" == "${LATEST_TAG}" ]]; then
echo "Tags match — no PR would be created"
else
echo "Tags differ — a release PR would update ${currentTag} -> ${LATEST_TAG}"
# Show what the updated .env would look like
cp "${ENV_FILE}" /tmp/env-updated
sed -i "s/^BACKEND_TAG=.*/BACKEND_TAG=${LATEST_TAG}/" /tmp/env-updated
sed -i "s/^FRONTEND_TAG=.*/FRONTEND_TAG=${LATEST_TAG}/" /tmp/env-updated
echo "--- Diff ---"
diff "${ENV_FILE}" /tmp/env-updated || true
fi