Skip to content

Commit 4e9ca04

Browse files
xnyoCopilot
andauthored
feat(ci): add warning when ci and cd workflows are not on the same reference (#492)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 26d87fb commit 4e9ca04

5 files changed

Lines changed: 122 additions & 47 deletions
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Description:
2+
# Checks for release channel usage in workflow files.
3+
# This reusable workflow verifies that:
4+
# - The rolling releases channel (@main) is not being used (warning)
5+
# - Commit hashes are not used for pinning (error)
6+
# - All workflow references to ci.yml and cd.yml use the same version (warning)
7+
8+
name: Plugins - Check release channel
9+
10+
on:
11+
workflow_call:
12+
inputs:
13+
DO-NOT-USE-allow-pinned-commit-hashes:
14+
description: |
15+
FOR INTERNAL TESTING ONLY, DO NOT USE.
16+
If `true`, skip hard fail in case the workflow is pinned to a commit hash.
17+
Vault access may still fail in such cases, depending on the WIF policies in place.
18+
type: boolean
19+
required: false
20+
default: false
21+
22+
jobs:
23+
check-for-release-channel:
24+
name: Check for release channel
25+
runs-on: ubuntu-arm64-small
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
29+
30+
- name: Check for rolling releases channel
31+
run: |
32+
diff=$(grep -E 'grafana/plugin-ci-workflows.+@main' -rn .github/workflows/ || true)
33+
if [[ -n "$diff" ]]; then
34+
echo "Found usage of rolling releases channel in the following files:"
35+
echo "$diff"
36+
37+
title="Detected plugin-ci-workflows rolling release channel"
38+
message="You are using workflows from plugin-ci-workflows rolling releases channel (\`@main\`). \
39+
This is discouraged as it may lead to unexpected breaking changes. \
40+
Please pin to a specific tagged release to ensure better stability. \
41+
For more information, refer to the docs: https://enghub.grafana-ops.net/docs/default/component/grafana-plugins-platform/plugins-ci-github-actions/010-plugins-ci-github-actions/#versions-and-release-channels"
42+
43+
echo "::warning title=$title::$message"
44+
exit 0
45+
fi
46+
shell: bash
47+
48+
- name: Check for plugin-ci-workflows pinned to commit hash
49+
run: |
50+
diff=$(grep -E 'grafana/plugin-ci-workflows.+@[0-9a-f]{6,40}' -rn .github/workflows/ || true)
51+
if [[ -n "$diff" ]]; then
52+
echo "Found plugin-ci-workflows pinned to a commit hash in the following files:"
53+
echo "$diff"
54+
55+
title="Detected plugin-ci-workflows pinned to a commit hash"
56+
message="You are pinning plugin-ci-workflows to a commit hash. \
57+
To limit the amount of exposure (security reasons), this is not allowed and the workflow will fail. \
58+
Please pin to a specific tagged release instead. \
59+
For more information, refer to the docs: https://enghub.grafana-ops.net/docs/default/component/grafana-plugins-platform/plugins-ci-github-actions/010-plugins-ci-github-actions/#versions-and-release-channels"
60+
61+
echo "::error title=$title::$message"
62+
if [ "${ALLOW_PINNED_COMMIT_HASHES}" != "true" ]; then
63+
# Hard fail by default
64+
exit 1
65+
else
66+
exit 0
67+
fi
68+
fi
69+
env:
70+
ALLOW_PINNED_COMMIT_HASHES: ${{ inputs.DO-NOT-USE-allow-pinned-commit-hashes }}
71+
shell: bash
72+
73+
- name: Check for inconsistent workflow references
74+
run: |
75+
# Extract all workflow references to ci.yml and cd.yml from plugin-ci-workflows
76+
# Output format: filename:line:match
77+
refs_with_files=$(grep -rnoE 'grafana/plugin-ci-workflows/\.github/workflows/(ci|cd)\.yml@[^[:space:]"'"'"']+' .github/workflows/ || true)
78+
79+
if [[ -z "$refs_with_files" ]]; then
80+
echo "No workflow references to ci.yml or cd.yml found."
81+
exit 0
82+
fi
83+
84+
echo "Found workflow references:"
85+
echo "$refs_with_files"
86+
87+
# Get unique versions (the part after @)
88+
versions=$(echo "$refs_with_files" | sed 's/.*@//' | sort -u)
89+
version_count=$(echo "$versions" | wc -l | tr -d ' ')
90+
91+
if [ "$version_count" -gt 1 ]; then
92+
echo ""
93+
echo "Found inconsistent workflow references with different versions!"
94+
echo ""
95+
96+
# Build a markdown list showing each version and which files use it
97+
details=""
98+
while IFS= read -r version; do
99+
details="${details}%0A- \`@${version}\` is used in:"
100+
# Find files using this version
101+
while IFS=: read -r file line match; do
102+
if [[ "$match" == *"@${version}" ]]; then
103+
details="${details}%0A - \`${file}\` (line ${line})"
104+
fi
105+
done <<< "$refs_with_files"
106+
done <<< "$versions"
107+
108+
title="Inconsistent plugin-ci-workflows references"
109+
message="Found multiple versions of plugin-ci-workflows being referenced in workflow files. All references to ci.yml and cd.yml should use the same version.${details}"
110+
111+
echo "::warning title=$title::$message"
112+
else
113+
echo ""
114+
echo "All workflow references use the same version: $versions"
115+
fi
116+
shell: bash

.github/workflows/ci.yml

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -302,53 +302,9 @@ env:
302302
jobs:
303303
check-for-release-channel:
304304
name: Check for release channel
305-
runs-on: ubuntu-arm64-small
306-
steps:
307-
- name: Checkout
308-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
309-
310-
- name: Check for rolling releases channel
311-
run: |
312-
diff=$(grep -E 'grafana/plugin-ci-workflows.+@main' -rn .github/workflows/ || true)
313-
if [[ -n "$diff" ]]; then
314-
echo "Found usage of rolling releases channel in the following files:"
315-
echo "$diff"
316-
317-
title="Detected plugin-ci-workflows rolling release channel"
318-
message="You are using workflows from plugin-ci-workflows rolling releases channel (\`@main\`). \
319-
This is discouraged as it may lead to unexpected breaking changes. \
320-
Please pin to a specific tagged release to ensure better stability. \
321-
For more information, refer to the docs: https://enghub.grafana-ops.net/docs/default/component/grafana-plugins-platform/plugins-ci-github-actions/010-plugins-ci-github-actions/#versions-and-release-channels"
322-
323-
echo "::warning title=$title::$message"
324-
exit 0
325-
fi
326-
shell: bash
327-
328-
- name: Check for plugin-ci-workflows pinned to commit hash
329-
run: |
330-
diff=$(grep -E 'grafana/plugin-ci-workflows.+@[0-9a-f]{6,40}' -rn .github/workflows/ || true)
331-
if [[ -n "$diff" ]]; then
332-
echo "Found plugin-ci-workflows pinned to a commit hash in the following files:"
333-
echo "$diff"
334-
335-
title="Detected plugin-ci-workflows pinned to a commit hash"
336-
message="You are pinning plugin-ci-workflows to a commit hash. \
337-
To limit the amount of exposure (security reasons), this is not allowed and the workflow will fail. \
338-
Please pin to a specific tagged release instead. \
339-
For more information, refer to the docs: https://enghub.grafana-ops.net/docs/default/component/grafana-plugins-platform/plugins-ci-github-actions/010-plugins-ci-github-actions/#versions-and-release-channels"
340-
341-
echo "::error title=$title::$message"
342-
if [ "${ALLOW_PINNED_COMMIT_HASHES}" != "true" ]; then
343-
# Hard fail by default
344-
exit 1
345-
else
346-
exit 0
347-
fi
348-
fi
349-
env:
350-
ALLOW_PINNED_COMMIT_HASHES: ${{ inputs.DO-NOT-USE-allow-pinned-commit-hashes }}
351-
shell: bash
305+
uses: grafana/plugin-ci-workflows/.github/workflows/check-release-channel.yml@main
306+
with:
307+
DO-NOT-USE-allow-pinned-commit-hashes: ${{ inputs.DO-NOT-USE-allow-pinned-commit-hashes }}
352308

353309
test-and-build:
354310
name: Test and build plugin

.github/workflows/pr-checks-workflow-references.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
.github/workflows/cd.yml
3636
.github/workflows/playwright.yml
3737
.github/workflows/playwright-docker.yml
38+
.github/workflows/check-release-channel.yml
3839
actions/plugins/**
3940
4041
- name: Check drift

.github/workflows/release-please-pr-update-tagged-references.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jobs:
132132
.github/workflows/cd.yml
133133
.github/workflows/playwright.yml
134134
.github/workflows/playwright-docker.yml
135+
.github/workflows/check-release-channel.yml
135136
actions/plugins/**
136137
137138
# For "examples", update references by filtering for an additional prefix.

.github/workflows/release-please-restore-rolling-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
.github/workflows/cd.yml
7777
.github/workflows/playwright.yml
7878
.github/workflows/playwright-docker.yml
79+
.github/workflows/check-release-channel.yml
7980
actions/plugins/**
8081
8182
- name: Get bot user info

0 commit comments

Comments
 (0)