|
| 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 |
0 commit comments