-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (99 loc) · 3.43 KB
/
build.yml
File metadata and controls
106 lines (99 loc) · 3.43 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: Build
on: [pull_request, push]
permissions:
issues: write
contents: read
jobs:
build-with-bazel:
runs-on: ubuntu-24.04
steps:
- name: checkout repository
uses: actions/checkout@v4
- uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
- name: build
run: bazel build --verbose_failures //... > build.log 2>&1
- name: Prepare artifacts for upload
run: |
mkdir -p release_artifacts
BIN_PATH=$(bazel info bazel-bin)
for dir in "$BIN_PATH/subprojects"/*/ ; do
dir_name=$(basename "$dir")
zip_file="$dir/${dir_name}.zip"
if [ -f "$zip_file" ]; then
cp "$zip_file" release_artifacts/
fi
done
- name: capture build artifacts
if: success()
uses: actions/upload-artifact@v4
with:
name: artifacts
path: release_artifacts/
- name: Upload build log on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-log
path: build.log
handle-failure:
runs-on: ubuntu-latest
needs: build-with-bazel
if: failure()
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build log
uses: actions/download-artifact@v4
with:
name: build-log
path: .
- name: Get commit information
id: commit_info
run: |
echo "short_sha=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_OUTPUT
commit_message=$(git log --format=%B -n 1 ${{ github.sha }})
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
echo "$commit_message" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Check for existing issue
id: check_issue
run: |
issue_count=$(gh issue list --repo ${{ github.repository }} --label "bug" --search "\"\${{ steps.commit_info.outputs.short_sha }} 构建失败\" in:title" | wc -l)
if [ $issue_count -gt 0 ]; then
echo "issue_exists=true" >> $GITHUB_OUTPUT
else
echo "issue_exists=false" >> $GITHUB_OUTPUT
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create issue with log
if: steps.check_issue.outputs.issue_exists == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: ${{ steps.commit_info.outputs.commit_message }}
SHORT_SHA: ${{ steps.commit_info.outputs.short_sha }}
HEAD_SHA: ${{ github.sha }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
REPO: ${{ github.repository }}
SERVER_URL: ${{ github.server_url }}
run: |
LOG_BODY=$(tail -c 40000 build.log)
cat <<EOF > issue-body.md
构建在 commit [$SHORT_SHA]($SERVER_URL/$REPO/commit/$HEAD_SHA) 失败。
**Commit Message:**
$COMMIT_MESSAGE
[查看失败的构建]($RUN_URL)
<details>
<summary>构建日志片段</summary>
\`\`\`
$LOG_BODY
\`\`\`
</details>
EOF
gh issue create --repo $REPO --title "$SHORT_SHA 构建失败" --body-file issue-body.md --label "bug"