-
Notifications
You must be signed in to change notification settings - Fork 35
122 lines (107 loc) · 4.29 KB
/
Copy pathbuild-preview.yml
File metadata and controls
122 lines (107 loc) · 4.29 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
name: Build Preview
on:
pull_request:
types:
- labeled
- synchronize
permissions:
contents: read
issues: write
pull-requests: write
jobs:
build-preview:
if: >
github.repository == 'mattrossman/forecaswatch2' &&
(
(github.event.action == 'labeled' && github.event.label.name == 'build-preview') ||
(github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'build-preview'))
) &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-24.04
concurrency:
group: build-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Check out repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Set up mise toolchain
uses: jdx/mise-action@dba19683ed58901619b14f395a24841710cb4925 # v4.1.0
with:
install: true
cache: true
- name: Install Pebble SDK
run: scripts/ensure-pebble-sdk.sh
- name: Build dev .pbw
env:
TELEMETRY_ENDPOINT: ${{ secrets.TELEMETRY_ENDPOINT_PREVIEW }}
shell: bash
run: |
set -euo pipefail
mkdir -p build
mise build dev 2>&1 | tee build/build-preview.log
- name: Verify artifact exists
run: test -f build/forecaswatch2-dev.pbw
- name: Upload .pbw artifact
id: upload
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: forecaswatch2-dev-pbw-pr-${{ github.event.pull_request.number }}.zip
path: build/forecaswatch2-dev.pbw
if-no-files-found: error
retention-days: 14
- name: Upsert PR comment with artifact link
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
ARTIFACT_URL: ${{ steps.upload.outputs.artifact-url }}
MEMORY_LOG_PATH: ${{ github.workspace }}/build/build-preview.log
with:
script: |
const fs = require('node:fs');
const { parsePebbleMemoryReport, renderPebbleMemoryReport } = require(`${process.env.GITHUB_WORKSPACE}/scripts/parse-pebble-memory-report`);
const marker = '<!-- build-preview-artifact -->';
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
if (!process.env.ARTIFACT_URL) {
throw new Error('upload-artifact did not return artifact-url');
}
const runUrl = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const prNumber = context.payload.pull_request.number;
const artifactName = `forecaswatch2-dev-pbw-pr-${prNumber}.zip`;
const memoryLogPath = process.env.MEMORY_LOG_PATH;
const memoryReport = memoryLogPath && fs.existsSync(memoryLogPath)
? renderPebbleMemoryReport(parsePebbleMemoryReport(fs.readFileSync(memoryLogPath, 'utf8')))
: '_No memory usage log was captured for this run._';
const body = [
marker,
'✅ Preview dev build available.',
'',
`Download [${artifactName}](${process.env.ARTIFACT_URL})`,
'',
memoryReport,
'',
'Artifacts are attached to the workflow run/job and require GitHub access to this repository.',
`Run: [#${process.env.GITHUB_RUN_NUMBER}](${runUrl})`,
].join('\n');
const comments = await github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: prNumber,
per_page: 100,
});
const existing = comments.find((comment) =>
comment.user?.type === 'Bot' && comment.body?.includes(marker)
);
if (existing) {
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body,
});
}