-
-
Notifications
You must be signed in to change notification settings - Fork 49
101 lines (87 loc) · 3.26 KB
/
Copy pathvalidate-apps.yml
File metadata and controls
101 lines (87 loc) · 3.26 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
name: Validate app files
on:
pull_request_target:
paths:
- 'apps/**'
permissions:
contents: read
pull-requests: write
jobs:
validate:
runs-on: ubuntu-latest
container:
image: registry.gitlab.com/kazam0180/pla-site-tool:latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
allow-unsafe-pr-checkout: true
- name: Mark workspace as safe
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Get modified app files
id: changed
shell: bash
run: |
FILES=$(git diff --name-only --diff-filter=ACMR origin/main...HEAD -- 'apps/*' | grep -v '\.template$' || true)
echo "files<<EOF" >> $GITHUB_OUTPUT
echo "$FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Validate files
if: steps.changed.outputs.files != ''
id: validate
shell: bash
run: |
INPUT_ARGS=""
while IFS= read -r file; do
[ -z "$file" ] && continue
INPUT_ARGS="$INPUT_ARGS -i $file"
done <<< "${{ steps.changed.outputs.files }}"
echo "Running: ./pla-site-tool $INPUT_ARGS validate-apps"
set +e
STDERR=$(pla-site-tool $INPUT_ARGS validate-apps 2>&1)
EXIT_CODE=$?
set -e
echo "$STDERR"
if [ $EXIT_CODE -ne 0 ]; then
echo "STDERR<<EOF" >> $GITHUB_OUTPUT
echo "$STDERR" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "has_failed=true" >> $GITHUB_OUTPUT
else
echo "has_failed=false" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
if: steps.validate.outputs.has_failed == 'true'
uses: actions/github-script@v9
with:
script: |
const stderr = `${{ steps.validate.outputs.stderr }}`.trim();
const body = `### App file validation failed\n\n${stderr}\n\nPlease check the file format against [\`apps/.template\`](https://github.com/Portable-Linux-Apps/Portable-Linux-Apps.github.io/blob/main/apps/.template) and fix any syntax errors.`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c => c.user.type === 'Bot' && c.body.includes('App file validation failed'));
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Fail if validation errors
if: steps.validate.outputs.has_failed == 'true'
run: |
echo "Validation failed for the files listed in the PR comment."
exit 1