-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
161 lines (139 loc) · 5.7 KB
/
Copy pathpackage-tests.yml
File metadata and controls
161 lines (139 loc) · 5.7 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
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Verify Packages
on:
pull_request:
paths:
- src/**
permissions:
contents: read
jobs:
verify:
name: Verify Packages
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Fetch branch from where the PR started
env:
GH_TOKEN: ${{ github.token }}
run: |
# Credentials are not persisted by the checkout, so remote operations are given
# the job token explicitly. Public repositories would also accept anonymous reads,
# private forks do not.
git fetch --no-tags --prune --depth=1 "https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY" +refs/heads/*:refs/remotes/origin/*
- name: Find packages
id: find-packages
env:
BASE_REF: ${{ github.base_ref }}
run: |
packages=$(php .github/get-modified-packages.php \
"$(find src/Symfony -mindepth 2 -type f -name composer.json -printf '%h\n' | grep -v src/Symfony/Component/Emoji/Resources/bin | jq -R -s -c 'split("\n")[:-1]')" \
"$(git diff --name-only "origin/$BASE_REF" HEAD | grep src/ | jq -R -s -c 'split("\n")[:-1]')")
echo "packages=$packages" >> "$GITHUB_OUTPUT"
- name: Verify meta files are correct
env:
PACKAGES_JSON: ${{ steps.find-packages.outputs.packages }}
run: |
ok=0
_file_exist() {
if [ ! -f "${1}" ]; then
echo "File ${1} does not exist"
return 1
fi
}
_file_not_exist() {
if [ -f "${1}" ]; then
echo "File ${1} should not be here"
return 1
fi
}
_correct_license_file() {
FIRST_LINE="Copyright (c) $(date +"%Y")-present Fabien Potencier"
PACKAGE_FIRST_LINE=$(head -1 ${1})
if [[ "$FIRST_LINE" != "$PACKAGE_FIRST_LINE" ]]; then
echo "First line of the license file is wrong. Maybe it is the wrong year?"
return 1
fi
TEMPLATE=$(tail -n +2 LICENSE)
PACKAGE_LICENSE=$(tail -n +2 ${1})
if [[ "$TEMPLATE" != "$PACKAGE_LICENSE" ]]; then
echo "Wrong content in license file"
return 1
fi
}
json="$PACKAGES_JSON"
for package in $(echo "${json}" | jq -r '.[] | @base64'); do
_jq() {
echo ${package} | base64 --decode | jq -r ${1}
}
DIR=$(_jq '.directory')
NAME=$(_jq '.name')
echo "::group::$NAME"
TYPE=$(_jq '.type')
localExit=0
if [ $TYPE != 'contract' ] && [ $TYPE != 'contracts' ]; then
_file_exist $DIR/.gitattributes || localExit=1
fi
_file_exist $DIR/.gitignore || localExit=1
_file_exist $DIR/CHANGELOG.md || localExit=1
_file_exist $DIR/LICENSE || localExit=1
if [ $TYPE != 'contract' ]; then
_file_exist $DIR/phpunit.xml.dist || localExit=1
fi
_file_exist $DIR/README.md || localExit=1
_file_not_exist $DIR/phpunit.xml || localExit=1
if [ $(_jq '.new') == true ]; then
echo "Verifying new package"
_correct_license_file $DIR/LICENSE || localExit=1
if [ $TYPE != 'component_bridge' ]; then
if [ ! $(cat composer.json | jq -e ".replace.\"$NAME\"|test(\"self.version\")") ]; then
echo "Composer.json's replace section needs to contain $NAME"
localExit=1
fi
fi
fi
ok=$(( $localExit || $ok ))
echo ::endgroup::
if [ $localExit -ne 0 ]; then
echo "::error::$NAME failed"
fi
done
exit $ok
- name: Verify symfony/deprecation-contracts requirements
env:
PACKAGES_JSON: ${{ steps.find-packages.outputs.packages }}
run: |
set +e
ok=0
json="$PACKAGES_JSON"
for package in $(echo "${json}" | jq -r '.[] | @base64'); do
_jq() {
echo ${package} | base64 --decode | jq -r ${1}
}
NAME=$(_jq '.name')
if [[ $NAME = 'symfony/deprecation-contracts' || $NAME = 'symfony/contracts' ]]; then
continue
fi
echo "::group::$NAME"
DIR=$(_jq '.directory')
localExit=0
grep -rq 'trigger_deprecation(' --include=*.php --exclude-dir=Tests/ --exclude-dir=Bridge/ $DIR
triggersDeprecation=$?
if [[ $triggersDeprecation -eq 0 && $(_jq '.requires_deprecation_contracts') == false ]]; then
errorMessage="::error::$NAME does not require symfony/deprecation-contracts but triggers at least one deprecation"
localExit=1
elif [[ $triggersDeprecation -eq 1 && $(_jq '.requires_deprecation_contracts') == true ]]; then
errorMessage="::error::$NAME requires symfony/deprecation-contracts but does not trigger any deprecation"
localExit=1
elif [[ $triggersDeprecation -ne 0 && $triggersDeprecation -ne 1 ]]; then
echo "::error::grep failed"
exit 2
fi
ok=$(( $localExit || $ok ))
echo ::endgroup::
if [ $localExit -ne 0 ]; then
echo $errorMessage
fi
done
exit $ok