Repository navigation
140 lines (121 loc) · 4.69 KB
/
Copy pathpreview.yaml
File metadata and controls
140 lines (121 loc) · 4.69 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
name: Preview generated SDK vs main
on:
pull_request:
paths:
- "sdk-generator/**"
- "package-lock.json"
workflow_dispatch:
jobs:
generate-and-diff:
name: Generate SDK and diff vs main
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
pull-requests: write
steps:
- name: Checkout current ref
uses: actions/checkout@v4
- name: Checkout main
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: main
path: main-sdk
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
cache: "npm"
registry-url: "https://npm.pkg.github.com/"
scope: "@rebilly"
cache-dependency-path: |
package-lock.json
- name: Login to GitHub Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Install dependencies
run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build PHP SDK
run: |
mkdir -p /tmp/sdk
npm run generate /tmp/sdk https://www.rebilly.com/_spec/catalog/all.yaml
cp -r examples /tmp/sdk
- name: Generate diff (generated SDK vs main)
id: text-diff
working-directory: main-sdk
run: |
# Replace main's SDK files with generated ones, then diff
rm -rf src composer.json .php-cs-fixer.php psalm.xml 2>/dev/null || true
cp -r /tmp/sdk/src .
cp /tmp/sdk/composer.json . 2>/dev/null || true
cp /tmp/sdk/psalm.xml . 2>/dev/null || true
cp /tmp/sdk/.php-cs-fixer.php . 2>/dev/null || true
# Add all files to git to ensure diff works correctly
git add -A || true
# Generate text diff (staged = generated vs main's content)
git diff --no-color --cached > /tmp/rebilly-sdk-diff.txt || true
# Check diff size (GitHub PR comment limit is ~65,536 characters)
DIFF_SIZE=$(wc -c < /tmp/rebilly-sdk-diff.txt)
echo "diff_size=$DIFF_SIZE" >> $GITHUB_OUTPUT
echo "Diff size: $DIFF_SIZE bytes"
if [ "$DIFF_SIZE" -gt 0 ] && [ "$DIFF_SIZE" -lt 60000 ]; then
echo "include_diff=true" >> $GITHUB_OUTPUT
else
echo "include_diff=false" >> $GITHUB_OUTPUT
fi
if [ "$DIFF_SIZE" -eq 0 ]; then
echo "diff_empty=true" >> $GITHUB_OUTPUT
else
echo "diff_empty=false" >> $GITHUB_OUTPUT
fi
- name: Generate HTML diff
working-directory: main-sdk
run: |
npx -y diff2html-cli -s side -t 'Rebilly PHP SDK' -F /tmp/rebilly-sdk-diff.html
- name: Upload Artifact
id: diff-upload
uses: actions/upload-artifact@v4
with:
name: rebilly-sdk-diff
path: /tmp/rebilly-sdk-diff.html
retention-days: 3
if-no-files-found: ignore
- name: Prepare PR Comment Message
if: github.event_name == 'pull_request'
id: comment-message
run: |
echo "## 🔍 PHP SDK Changes Preview" >> /tmp/pr-comment.md
echo "" >> /tmp/pr-comment.md
if [ "${{ steps.text-diff.outputs.include_diff }}" == "true" ]; then
{
echo '```diff'
cat /tmp/rebilly-sdk-diff.txt
echo '```'
} >> /tmp/pr-comment.md
else
echo "**Diff is too large to display inline**" >> /tmp/pr-comment.md
fi
echo "" >> /tmp/pr-comment.md
echo "📦 Download the **rebilly-sdk-diff** artifact from the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for a formatted HTML diff." >> /tmp/pr-comment.md
echo "" >> /tmp/pr-comment.md
echo "---" >> /tmp/pr-comment.md
echo "**Updated:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")" >> /tmp/pr-comment.md
echo "**Commit:** [${{ github.event.pull_request.head.sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }})" >> /tmp/pr-comment.md
{
echo "message<<EOF"
cat /tmp/pr-comment.md
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Create/Update PR Comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ github.token }}
number: ${{ github.event.pull_request.number }}
message: ${{ steps.comment-message.outputs.message }}