-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (123 loc) · 4.66 KB
/
build.yml
File metadata and controls
137 lines (123 loc) · 4.66 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
name: iOS CI
on:
pull_request:
env:
SCHEME: DevLog
XCODE_VERSION: latest
MATCH_GIT_URL: ${{ secrets.MATCH_GIT_URL }}
MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }}
permissions:
contents: read
issues: write
pull-requests: write
checks: write
jobs:
detect_qa_tag:
runs-on: macos-latest
outputs:
has_qa_tag: ${{ steps.detect.outputs.has_qa_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Detect QA Tag on PR Head
id: detect
shell: bash
run: |
set -euo pipefail
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"
MATCHED_TAG="$(git tag --points-at "$PR_HEAD_SHA" | grep -E '^qa(-local)?-' | head -n 1 || true)"
if [ -n "$MATCHED_TAG" ]; then
echo "Found QA tag on PR head: $MATCHED_TAG"
echo "has_qa_tag=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "No QA tag found on PR head"
echo "has_qa_tag=false" >> "$GITHUB_OUTPUT"
build:
needs: detect_qa_tag
if: needs.detect_qa_tag.outputs.has_qa_tag != 'true'
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install private config files
uses: ./.github/actions/install-private-config
with:
git_url: ${{ env.MATCH_GIT_URL }}
git_basic_authorization: ${{ env.MATCH_GIT_BASIC_AUTHORIZATION }}
- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ env.XCODE_VERSION }}
- name: Cache SwiftPM
uses: actions/cache@v4
with:
path: |
~/.swiftpm
~/Library/Caches/org.swift.swiftpm
~/Library/Developer/Xcode/SourcePackages
.spm
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Build
uses: ./.github/actions/ios-simulator-build
with:
scheme: ${{ env.SCHEME }}
- name: Comment build failure on PR
if: failure() && github.event.pull_request.head.repo.fork == false
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = 'build.log';
let body = '❌ iOS CI build failed.\n\n';
if (fs.existsSync(path)) {
const log = fs.readFileSync(path, 'utf8');
const lines = log.split(/\r?\n/);
const errorLines = lines.filter((line) => /error:/i.test(line));
if (errorLines.length > 0) {
body += "Lines containing 'error:':\n\n```\n" + errorLines.join('\n') + '\n```\n';
const repoRoot = process.env.GITHUB_WORKSPACE || process.cwd();
const pathMod = require('path');
const snippets = [];
for (const line of errorLines) {
const match = line.match(/^(.*?):(\d+):(\d+):\s+error:/);
if (!match) continue;
const filePath = match[1];
const lineNum = parseInt(match[2], 10);
const absPath = filePath.startsWith('/') ? filePath : pathMod.join(repoRoot, filePath);
if (!fs.existsSync(absPath)) continue;
const fileLines = fs.readFileSync(absPath, 'utf8').split(/\r?\n/);
const start = Math.max(0, lineNum - 3);
const end = Math.min(fileLines.length, lineNum + 2);
const snippet = fileLines
.slice(start, end)
.map((l, idx) => {
const ln = start + idx + 1;
return `${ln.toString().padStart(4, ' ')}| ${l}`;
})
.join('\n');
snippets.push(`File: ${filePath}:${lineNum}\n${snippet}`);
}
if (snippets.length > 0) {
body += "\nCode excerpts:\n\n```\n" + snippets.join('\n\n') + "\n```\n";
}
} else {
body += "No lines containing 'error:' were found in build.log.";
}
} else {
body += 'build.log not found.';
}
if (!context.payload.pull_request) {
core.info('No PR context; skipping comment.');
return;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body
});