|
| 1 | +name: Validate Release Please Config |
| 2 | +description: >- |
| 3 | + Fails a repository whose release-please configuration is not where every |
| 4 | + repository keeps it. |
| 5 | +author: TrogonStack |
| 6 | + |
| 7 | +runs: |
| 8 | + using: composite |
| 9 | + steps: |
| 10 | + - name: Validate release-please configuration |
| 11 | + shell: bash |
| 12 | + run: | |
| 13 | + set -euo pipefail |
| 14 | +
|
| 15 | + config=.github/release-please-config.json |
| 16 | + manifest=.github/release-please-manifest.json |
| 17 | + failed=0 |
| 18 | +
|
| 19 | + fail() { |
| 20 | + printf '::error file=%s::%s\n' "$1" "$2" |
| 21 | + failed=1 |
| 22 | + } |
| 23 | +
|
| 24 | + # A copy left behind after a move is worse than never moving, because |
| 25 | + # release-please reads the one the workflow names and the other rots. |
| 26 | + strays=$(git ls-files \ |
| 27 | + | grep -E '(^|/)\.?release-please-(config|manifest)\.json$' \ |
| 28 | + | grep -vxF "$config" \ |
| 29 | + | grep -vxF "$manifest" || true) |
| 30 | +
|
| 31 | + workflows=$(git ls-files '.github/workflows/*.yml' '.github/workflows/*.yaml') |
| 32 | + releasing='' |
| 33 | + for workflow in $workflows; do |
| 34 | + if grep -q 'release-please-action' "$workflow"; then |
| 35 | + releasing="${releasing} ${workflow}" |
| 36 | + fi |
| 37 | + done |
| 38 | +
|
| 39 | + if [ -z "$releasing" ] && [ -z "$strays" ] && [ ! -f "$config" ] && [ ! -f "$manifest" ]; then |
| 40 | + echo "This repository does not use release-please, so there is nothing to place." |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | +
|
| 44 | + for file in "$config" "$manifest"; do |
| 45 | + if [ ! -f "$file" ]; then |
| 46 | + fail "$file" "Missing. Every repository keeps release-please configuration here." |
| 47 | + elif ! python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$file" 2>/dev/null; then |
| 48 | + fail "$file" "Not valid JSON." |
| 49 | + fi |
| 50 | + done |
| 51 | +
|
| 52 | + for stray in $strays; do |
| 53 | + fail "$stray" "Release-please configuration belongs in .github/ only." |
| 54 | + done |
| 55 | +
|
| 56 | + for workflow in $releasing; do |
| 57 | + for pair in "config-file:$config" "manifest-file:$manifest"; do |
| 58 | + key=${pair%%:*} |
| 59 | + want=${pair#*:} |
| 60 | + got=$(grep -E "^[[:space:]]*${key}:" "$workflow" \ |
| 61 | + | head -1 \ |
| 62 | + | sed -E "s/^[[:space:]]*${key}:[[:space:]]*//" \ |
| 63 | + | tr -d "\"'" || true) |
| 64 | +
|
| 65 | + if [ -z "$got" ]; then |
| 66 | + fail "$workflow" "Does not set ${key}. It must be ${want}." |
| 67 | + elif [ "$got" != "$want" ]; then |
| 68 | + fail "$workflow" "Sets ${key} to ${got}. It must be ${want}." |
| 69 | + fi |
| 70 | + done |
| 71 | + done |
| 72 | +
|
| 73 | + exit "$failed" |
0 commit comments