-
Notifications
You must be signed in to change notification settings - Fork 24
215 lines (201 loc) · 7.78 KB
/
nightly.yml
File metadata and controls
215 lines (201 loc) · 7.78 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Nightly Build
on:
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # Runs every day at midnight UTC
jobs:
check:
name: Determine Build Necessity
runs-on: ubuntu-latest
outputs:
proceed: ${{ steps.check.outputs.proceed }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get the last nightly commit
id: last_nightly
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
const nightlyRelease = releases.data.find(release => release.tag_name.includes('nightly') || release.name.includes('Nightly'));
if (nightlyRelease) {
const tagName = nightlyRelease.tag_name;
const tag = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tagName}`
});
const commitSha = tag.data.object.sha;
return commitSha;
} else {
return null;
}
- name: Check the proceed condition
id: check
run: |
LAST_NIGHTLY_COMMIT="${{ steps.last_nightly.outputs.result }}"
CURRENT_COMMIT="${GITHUB_SHA}"
echo "Last nightly commit: $LAST_NIGHTLY_COMMIT"
echo "Current commit: $CURRENT_COMMIT"
if [ -z "$LAST_NIGHTLY_COMMIT" ]; then
echo "No previous nightly release found. Proceeding with build."
echo "proceed=true" >> $GITHUB_OUTPUT
elif [ "$LAST_NIGHTLY_COMMIT" != "$CURRENT_COMMIT" ]; then
echo "New commits found since last nightly release. Proceeding with build."
echo "proceed=true" >> $GITHUB_OUTPUT
else
echo "No new commits since last nightly release. Skipping build."
echo "proceed=false" >> $GITHUB_OUTPUT
fi
build:
name: Nightly Build on ${{ matrix.os }}
needs: check
if: needs.check.outputs.proceed == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
- uses: ./.github/actions/soluna
name: Build
id: build
with:
soluna_path: "."
- uses: actions/upload-artifact@v4
name: Upload
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
with:
name: "soluna-${{ runner.os }}-${{ steps.build.outputs.SOLUNA_BINARY }}"
if-no-files-found: "error"
path: "${{ steps.build.outputs.SOLUNA_PATH }}"
overwrite: "true"
- uses: actions/upload-artifact@v4
name: Upload Emscripten
if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && runner.os == 'Linux'
with:
name: "soluna-emscripten"
if-no-files-found: "error"
overwrite: "true"
path: |
${{ steps.build.outputs.SOLUNA_WASM_PATH }}
${{ steps.build.outputs.SOLUNA_JS_PATH }}
release:
name: Create Nightly Release
needs: [check, build]
runs-on: ubuntu-latest
if: (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule') && github.actor != 'nektos/act'
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v5
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release-assets
find artifacts -type f -name "soluna*" -exec cp {} release-assets/ \;
ls -la release-assets/
- name: Delete existing nightly releases
uses: actions/github-script@v7
with:
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
for (const release of releases.data) {
if (release.tag_name.includes('nightly') || release.name.includes('Nightly')) {
console.log(`Deleting release: ${release.tag_name}`);
try {
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id
});
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${release.tag_name}`
});
} catch (error) {
console.log(`Tag ${release.tag_name} might not exist or already deleted`);
}
} catch (error) {
console.log(`Failed to delete release ${release.tag_name}: ${error.message}`);
}
}
}
- name: Create nightly release
id: create-release
uses: actions/github-script@v7
with:
script: |
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5);
const commitSha = context.sha.substring(0, 7);
const tagName = 'nightly';
const releaseNotes = `🌙 **Nightly Build**
**Build Information:**
- **Commit:** \`${context.sha}\`
- **Branch:** \`${context.ref.replace('refs/heads/', '')}\`
- **Build Time:** \`${new Date().toISOString()}\`
- **Workflow:** [${context.runId}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})
> ⚠️ **Note:** This is an automated nightly build. It may contain unstable features and bugs.
>
> 📦 **Previous nightly releases are automatically removed to keep the repository clean.**`;
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Nightly Build (${timestamp})`,
body: releaseNotes,
prerelease: true,
make_latest: 'true',
draft: false,
});
console.log(`Created release: ${data.html_url}`);
return data.id;
- name: Upload release assets
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const releaseId = ${{ steps.create-release.outputs.result }};
const assetsDir = 'release-assets';
const files = fs.readdirSync(assetsDir);
for (const file of files) {
const filePath = path.join(assetsDir, file);
const stats = fs.statSync(filePath);
if (stats.isFile()) {
console.log(`Uploading ${file}...`);
const content = fs.readFileSync(filePath);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: file,
data: content
});
console.log(`Uploaded ${file}`);
}
}