-
Notifications
You must be signed in to change notification settings - Fork 3
87 lines (77 loc) · 3.62 KB
/
consistent_workflow_names.yml
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
# Check workflow names are consistent with their filenames for easier debugging
name: consistent_workflow_names
on:
pull_request:
# only when workflow file is changed
paths: ['.github/workflows/**']
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
check:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Print contexts
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
ENV_CONTEXT: ${{ toJson(env) }}
VARS_CONTEXT: ${{ toJson(vars) }}
JOB_CONTEXT: ${{ toJson(job) }}
STEPS_CONTEXT: ${{ toJson(steps) }}
RUNNER_CONTEXT: ${{ toJson(runner) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
MATRIX_CONTEXT: ${{ toJson(matrix) }}
NEEDS_CONTEXT: ${{ toJson(needs) }}
INPUTS_CONTEXT: ${{ toJson(inputs) }}
run: |
echo "******************************"
echo "github:" "$GITHUB_CONTEXT"
echo "******************************"
echo "env:" "$ENV_CONTEXT"
echo "******************************"
echo "vars:" "$VARS_CONTEXT"
echo "******************************"
echo "job:" "$JOB_CONTEXT"
echo "******************************"
echo "steps:" "$STEPS_CONTEXT"
echo "******************************"
echo "runner:" "$RUNNER_CONTEXT"
echo "******************************"
echo "secrets:" "$SECRETS_CONTEXT"
echo "******************************"
echo "strategy:" "$STRATEGY_CONTEXT"
echo "******************************"
echo "matrix:" "$MATRIX_CONTEXT"
echo "******************************"
echo "needs:" "$NEEDS_CONTEXT"
echo "******************************"
echo "inputs:" "$INPUTS_CONTEXT"
echo "******************************"
- uses: actions/checkout@v3
- name: Check workflow names
run: |
set -euxo pipefail # stop on errors, print commands, fail on pipe fails
cd .github/workflows
# Iterate through files in the current directory
for file in *.yml *.yaml; do
# Check if the item is a file (not a directory)
if [[ -f "$file" ]]; then
# find the first line beginning with "name:"
first_line=$(grep -m 1 "^name:" "$file")
# Extract name from the first line
name=$(echo "$first_line" | awk -F ': ' '{print $2}')
# Check if the extracted value matches the filename
if [[ "$name" == "${file%.*}" ]]; then
echo "File: $file - Name: $name (Match)"
else
echo "File: $file - Name: $name (No Match)"
exit 1
fi
fi
done