-
Notifications
You must be signed in to change notification settings - Fork 2
106 lines (97 loc) · 3.45 KB
/
ccd-diff.yml
File metadata and controls
106 lines (97 loc) · 3.45 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
name: Diff CCD definition
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
target: [branch, master]
steps:
- uses: actions/setup-java@v5
with:
distribution: corretto
java-version: 21
- name: Checkout ${{ matrix.target }}
uses: actions/checkout@v6
with:
ref: ${{ matrix.target == 'master' && 'master' || github.head_ref }}
path: build/${{ matrix.target }}
- name: Build CCD Config (${{ matrix.target }})
run: ./gradlew generateCCDConfig
working-directory: build/${{ matrix.target }}
- uses: actions/upload-artifact@v6
with:
name: ${{ matrix.target }}
path: build/${{ matrix.target }}/build/definitions/PCS
report:
permissions:
pull-requests: write
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/setup-node@v6
with:
node-version: 24
- uses: actions/download-artifact@v7
with:
name: branch
path: build/branch
- uses: actions/download-artifact@v7
with:
name: master
path: build/master
- name: Generate report
id: ccd-diff
run: |
set -euo pipefail
mkdir -p ccd-report
npx -q @hmcts/ccd-diff build/master build/branch > ccd-report/ccd-diff-report.html
SUMMARY_FILE="ccd-report/ccd-comment-summary.md"
MAX_CHARS=65000
REPORT_FILE="ccd-report/ccd-diff-report.html"
TOTAL_CHARS=$(wc -c < "$REPORT_FILE")
head -c $MAX_CHARS "$REPORT_FILE" > "$SUMMARY_FILE"
if [ "$TOTAL_CHARS" -gt "$MAX_CHARS" ]; then
printf '\n\n…(truncated)…\n' >> "$SUMMARY_FILE"
else
printf '\n' >> "$SUMMARY_FILE"
fi
{
echo "report-dir=ccd-report"
echo "report-path=$REPORT_FILE"
echo "summary-path=$SUMMARY_FILE"
} >> "$GITHUB_OUTPUT"
- name: Upload HTML report
uses: actions/upload-artifact@v6
with:
name: ccd-diff-report-${{ github.run_id }}
path: ${{ steps.ccd-diff.outputs.report-path }}
- name: Create or update CCD diff comment
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
SUMMARY_PATH: ${{ steps.ccd-diff.outputs.summary-path }}
RUN_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?check_suite_focus=true
run: |
BODY_FILE="$(mktemp)"
{
printf '# CCD diff summary\n\n'
printf '👉 Full report: %s\n\n' "$RUN_URL"
cat "$SUMMARY_PATH"
} > "$BODY_FILE"
COMMENT_ID=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" \
--json comments \
--jq '[.comments[]
| select(.body | startswith("# CCD diff summary"))
| .url | capture("#issuecomment-(?<id>[0-9]+)$").id][-1]')
if [ -n "$COMMENT_ID" ]; then
echo "📝 Updating existing CCD diff comment ($COMMENT_ID)"
gh api repos/$GITHUB_REPOSITORY/issues/comments/$COMMENT_ID \
-X PATCH -f body="$(cat "$BODY_FILE")"
else
echo "💬 Creating new CCD diff comment"
gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --body-file "$BODY_FILE"
fi