Skip to content

Commit 405e825

Browse files
authored
workflows: Move code samples jobs to new file (#2722)
1 parent 9fa74a9 commit 405e825

File tree

2 files changed

+145
-140
lines changed

2 files changed

+145
-140
lines changed

.github/workflows/build.yaml

Lines changed: 0 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -86,143 +86,3 @@ jobs:
8686
with:
8787
reporter: github-check
8888
filter_mode: added
89-
90-
code-samples:
91-
name: Validate code samples
92-
runs-on: "ubuntu-22.04"
93-
strategy:
94-
matrix:
95-
php:
96-
- "8.3"
97-
steps:
98-
- uses: actions/checkout@v4
99-
100-
- name: Setup PHP Action
101-
uses: shivammathur/setup-php@v2
102-
with:
103-
php-version: ${{ matrix.php }}
104-
coverage: none
105-
extensions: "pdo_sqlite, gd"
106-
tools: cs2pr
107-
108-
- name: Add composer keys for private packagist
109-
run: |
110-
composer config http-basic.updates.ibexa.co $SATIS_NETWORK_KEY $SATIS_NETWORK_TOKEN
111-
composer config github-oauth.github.com $TRAVIS_GITHUB_TOKEN
112-
env:
113-
SATIS_NETWORK_KEY: ${{ secrets.SATIS_NETWORK_KEY }}
114-
SATIS_NETWORK_TOKEN: ${{ secrets.SATIS_NETWORK_TOKEN }}
115-
TRAVIS_GITHUB_TOKEN: ${{ secrets.TRAVIS_GITHUB_TOKEN }}
116-
117-
- uses: ramsey/composer-install@v3
118-
with:
119-
dependency-versions: highest
120-
121-
- name: Run PHPStan analysis
122-
run: composer phpstan
123-
124-
code-samples-inclusion-check:
125-
name: Check code samples inclusion
126-
runs-on: ubuntu-latest
127-
if: github.event_name == 'pull_request'
128-
permissions:
129-
# Needed to manage the comment
130-
pull-requests: write
131-
132-
steps:
133-
- name: List modified files
134-
id: list
135-
run: |
136-
URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files"
137-
echo 'CODE_SAMPLES_CHANGE<<CODE_SAMPLES_CHANGE_DELIMITER' >> "$GITHUB_OUTPUT"
138-
curl -s -X GET -G $URL | jq -r '.[] | .filename,.previous_filename' | grep '^code_samples/' | tr '\n' ' ' >> "$GITHUB_OUTPUT"
139-
echo '' >> "$GITHUB_OUTPUT"
140-
echo 'CODE_SAMPLES_CHANGE_DELIMITER' >> "$GITHUB_OUTPUT"
141-
142-
- name: Checkout target branch (base_ref)
143-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
144-
uses: actions/checkout@v3
145-
with:
146-
ref: ${{ github.base_ref }}
147-
- name: Log target branch code_samples usage
148-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
149-
run: |
150-
git fetch origin
151-
git checkout origin/${{ github.head_ref }} -- tools/code_samples/code_samples_usage.php
152-
php tools/code_samples/code_samples_usage.php ${{ steps.list.outputs.CODE_SAMPLES_CHANGE }} > $HOME/code_samples_usage_target.txt
153-
154-
- name: Checkout source branch (head_ref)
155-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
156-
uses: actions/checkout@v3
157-
with:
158-
ref: ${{ github.head_ref }}
159-
- name: Log source branch code_samples usage
160-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
161-
run: php tools/code_samples/code_samples_usage.php ${{ steps.list.outputs.CODE_SAMPLES_CHANGE }} > $HOME/code_samples_usage_source.txt
162-
163-
- name: Compare code_samples usages (diff --unified)
164-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
165-
# diff returns 1 if there is a difference, this is normal but seen as an error by the job.
166-
continue-on-error: true
167-
run: |
168-
source_length=`wc -l < $HOME/code_samples_usage_source.txt`
169-
target_length=`wc -l < $HOME/code_samples_usage_target.txt`
170-
diff -U $(( source_length > target_length ? source_length : target_length )) $HOME/code_samples_usage_target.txt $HOME/code_samples_usage_source.txt > $HOME/code_samples_usage.diff
171-
- name: Check for differences
172-
id: diff
173-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
174-
run: |
175-
echo "CODE_SAMPLES_DIFF=$(wc -l < $HOME/code_samples_usage.diff | xargs)" >> "$GITHUB_OUTPUT"
176-
- name: Convert code_samples usages differences (diff2html)
177-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
178-
run: |
179-
npm install -g diff2html-cli
180-
diff2html -f html -s side -t 'code_samples/ changes report' --su hidden --fct false -o stdout -i file -- $HOME/code_samples_usage.diff > $HOME/code_samples_usage.diff.html
181-
- name: Upload code_samples usages differences artifact
182-
id: artifact
183-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
184-
uses: actions/upload-artifact@v4
185-
with:
186-
name: code_samples_usage.diff.html
187-
path: ~/code_samples_usage.diff.html
188-
overwrite: true
189-
- name: Convert code_samples usages for comment
190-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
191-
run: |
192-
title='# code_samples/ change report'
193-
link='<a href="${{ steps.artifact.outputs.artifact-url }}">Download colorized diff</a>'
194-
echo "$title" > code_samples_usage.diff.md
195-
echo '' >> code_samples_usage.diff.md
196-
php tools/code_samples/code_samples_usage_diff2html.php $HOME/code_samples_usage.diff >> code_samples_usage.diff.md
197-
echo "$link" >> code_samples_usage.diff.md
198-
if [[ `wc -m < code_samples_usage.diff.md | xargs` -ge $((2**16)) ]]; then
199-
echo "$title" > code_samples_usage.diff.md
200-
echo '' >> code_samples_usage.diff.md
201-
echo "Report's diff is too long to be displayed in a comment." >> code_samples_usage.diff.md
202-
echo '' >> code_samples_usage.diff.md
203-
echo "$link" >> code_samples_usage.diff.md
204-
fi
205-
- name: Find Comment
206-
id: find-comment
207-
uses: peter-evans/find-comment@v3
208-
with:
209-
issue-number: ${{ github.event.pull_request.number }}
210-
comment-author: 'github-actions[bot]'
211-
body-includes: 'code_samples/ change report'
212-
- name: Delete comment
213-
if: steps.find-comment.outputs.comment-id != ''
214-
uses: actions/github-script@v6
215-
with:
216-
script: |
217-
github.rest.issues.deleteComment({
218-
owner: context.repo.owner,
219-
repo: context.repo.repo,
220-
comment_id: ${{ steps.find-comment.outputs.comment-id }}
221-
})
222-
- name: Create comment
223-
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
224-
uses: peter-evans/create-or-update-comment@v4
225-
with:
226-
issue-number: ${{ github.event.pull_request.number }}
227-
body-path: code_samples_usage.diff.md
228-
edit-mode: replace

.github/workflows/code_samples.yaml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: "Check code samples"
2+
3+
on:
4+
pull_request: ~
5+
6+
jobs:
7+
code-samples-validation:
8+
name: Validate code samples
9+
runs-on: "ubuntu-22.04"
10+
strategy:
11+
matrix:
12+
php:
13+
- "8.3"
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup PHP Action
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
coverage: none
22+
extensions: "pdo_sqlite, gd"
23+
tools: cs2pr
24+
25+
- name: Add composer keys for private packagist
26+
run: |
27+
composer config http-basic.updates.ibexa.co $SATIS_NETWORK_KEY $SATIS_NETWORK_TOKEN
28+
composer config github-oauth.github.com $TRAVIS_GITHUB_TOKEN
29+
env:
30+
SATIS_NETWORK_KEY: ${{ secrets.SATIS_NETWORK_KEY }}
31+
SATIS_NETWORK_TOKEN: ${{ secrets.SATIS_NETWORK_TOKEN }}
32+
TRAVIS_GITHUB_TOKEN: ${{ secrets.TRAVIS_GITHUB_TOKEN }}
33+
34+
- uses: ramsey/composer-install@v3
35+
with:
36+
dependency-versions: highest
37+
38+
- name: Run PHPStan analysis
39+
run: composer phpstan
40+
41+
code-samples-inclusion-check:
42+
name: Check code samples inclusion
43+
runs-on: ubuntu-latest
44+
if: github.event_name == 'pull_request'
45+
permissions:
46+
# Needed to manage the comment
47+
pull-requests: write
48+
49+
steps:
50+
- name: List modified files
51+
id: list
52+
run: |
53+
URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files"
54+
echo 'CODE_SAMPLES_CHANGE<<CODE_SAMPLES_CHANGE_DELIMITER' >> "$GITHUB_OUTPUT"
55+
curl -s -X GET -G $URL | jq -r '.[] | .filename,.previous_filename' | grep '^code_samples/' | tr '\n' ' ' >> "$GITHUB_OUTPUT"
56+
echo '' >> "$GITHUB_OUTPUT"
57+
echo 'CODE_SAMPLES_CHANGE_DELIMITER' >> "$GITHUB_OUTPUT"
58+
59+
- name: Checkout target branch (base_ref)
60+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
61+
uses: actions/checkout@v3
62+
with:
63+
ref: ${{ github.base_ref }}
64+
- name: Log target branch code_samples usage
65+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
66+
run: |
67+
git fetch origin
68+
git checkout origin/${{ github.head_ref }} -- tools/code_samples/code_samples_usage.php
69+
php tools/code_samples/code_samples_usage.php ${{ steps.list.outputs.CODE_SAMPLES_CHANGE }} > $HOME/code_samples_usage_target.txt
70+
71+
- name: Checkout source branch (head_ref)
72+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
73+
uses: actions/checkout@v3
74+
with:
75+
ref: ${{ github.head_ref }}
76+
- name: Log source branch code_samples usage
77+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
78+
run: php tools/code_samples/code_samples_usage.php ${{ steps.list.outputs.CODE_SAMPLES_CHANGE }} > $HOME/code_samples_usage_source.txt
79+
80+
- name: Compare code_samples usages (diff --unified)
81+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
82+
# diff returns 1 if there is a difference, this is normal but seen as an error by the job.
83+
continue-on-error: true
84+
run: |
85+
source_length=`wc -l < $HOME/code_samples_usage_source.txt`
86+
target_length=`wc -l < $HOME/code_samples_usage_target.txt`
87+
diff -U $(( source_length > target_length ? source_length : target_length )) $HOME/code_samples_usage_target.txt $HOME/code_samples_usage_source.txt > $HOME/code_samples_usage.diff
88+
- name: Check for differences
89+
id: diff
90+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != ''
91+
run: |
92+
echo "CODE_SAMPLES_DIFF=$(wc -l < $HOME/code_samples_usage.diff | xargs)" >> "$GITHUB_OUTPUT"
93+
- name: Convert code_samples usages differences (diff2html)
94+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
95+
run: |
96+
npm install -g diff2html-cli
97+
diff2html -f html -s side -t 'code_samples/ changes report' --su hidden --fct false -o stdout -i file -- $HOME/code_samples_usage.diff > $HOME/code_samples_usage.diff.html
98+
- name: Upload code_samples usages differences artifact
99+
id: artifact
100+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: code_samples_usage.diff.html
104+
path: ~/code_samples_usage.diff.html
105+
overwrite: true
106+
- name: Convert code_samples usages for comment
107+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
108+
run: |
109+
title='# code_samples/ change report'
110+
link='<a href="${{ steps.artifact.outputs.artifact-url }}">Download colorized diff</a>'
111+
echo "$title" > code_samples_usage.diff.md
112+
echo '' >> code_samples_usage.diff.md
113+
php tools/code_samples/code_samples_usage_diff2html.php $HOME/code_samples_usage.diff >> code_samples_usage.diff.md
114+
echo "$link" >> code_samples_usage.diff.md
115+
if [[ `wc -m < code_samples_usage.diff.md | xargs` -ge $((2**16)) ]]; then
116+
echo "$title" > code_samples_usage.diff.md
117+
echo '' >> code_samples_usage.diff.md
118+
echo "Report's diff is too long to be displayed in a comment." >> code_samples_usage.diff.md
119+
echo '' >> code_samples_usage.diff.md
120+
echo "$link" >> code_samples_usage.diff.md
121+
fi
122+
- name: Find Comment
123+
id: find-comment
124+
uses: peter-evans/find-comment@v3
125+
with:
126+
issue-number: ${{ github.event.pull_request.number }}
127+
comment-author: 'github-actions[bot]'
128+
body-includes: 'code_samples/ change report'
129+
- name: Delete comment
130+
if: steps.find-comment.outputs.comment-id != ''
131+
uses: actions/github-script@v6
132+
with:
133+
script: |
134+
github.rest.issues.deleteComment({
135+
owner: context.repo.owner,
136+
repo: context.repo.repo,
137+
comment_id: ${{ steps.find-comment.outputs.comment-id }}
138+
})
139+
- name: Create comment
140+
if: steps.list.outputs.CODE_SAMPLES_CHANGE != '' && steps.diff.outputs.CODE_SAMPLES_DIFF != '0'
141+
uses: peter-evans/create-or-update-comment@v4
142+
with:
143+
issue-number: ${{ github.event.pull_request.number }}
144+
body-path: code_samples_usage.diff.md
145+
edit-mode: replace

0 commit comments

Comments
 (0)