|
8 | 8 | branches: |
9 | 9 | - master |
10 | 10 | workflow_dispatch: |
| 11 | + schedule: |
| 12 | + - cron: '0 0 * * *' # Runs every day at midnight UTC |
11 | 13 |
|
12 | 14 | jobs: |
13 | 15 | build: |
@@ -64,8 +66,128 @@ jobs: |
64 | 66 | echo "SOLUNA_BINARY=$SOLUNA_BINARY" >> $GITHUB_OUTPUT |
65 | 67 | - uses: actions/upload-artifact@v4 |
66 | 68 | name: Upload |
| 69 | + if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' |
67 | 70 | with: |
68 | 71 | name: "soluna-${{ runner.os }}-${{ steps.build.outputs.SOLUNA_BINARY }}" |
69 | 72 | if-no-files-found: "error" |
70 | 73 | path: "${{ steps.build.outputs.SOLUNA_PATH }}" |
71 | 74 | overwrite: "true" |
| 75 | + release: |
| 76 | + name: Create Nightly Release |
| 77 | + needs: build |
| 78 | + runs-on: ubuntu-latest |
| 79 | + if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' |
| 80 | + permissions: |
| 81 | + contents: write |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v5 |
| 84 | + - name: Download all artifacts |
| 85 | + uses: actions/download-artifact@v5 |
| 86 | + with: |
| 87 | + path: artifacts |
| 88 | + - name: Prepare release assets |
| 89 | + run: | |
| 90 | + mkdir -p release-assets |
| 91 | + find artifacts -type f -name "soluna*" -exec cp {} release-assets/ \; |
| 92 | + ls -la release-assets/ |
| 93 | + - name: Delete existing nightly releases |
| 94 | + uses: actions/github-script@v7 |
| 95 | + with: |
| 96 | + script: | |
| 97 | + const releases = await github.rest.repos.listReleases({ |
| 98 | + owner: context.repo.owner, |
| 99 | + repo: context.repo.repo, |
| 100 | + per_page: 100 |
| 101 | + }); |
| 102 | + |
| 103 | + for (const release of releases.data) { |
| 104 | + if (release.tag_name.includes('nightly') || release.name.includes('Nightly')) { |
| 105 | + console.log(`Deleting release: ${release.tag_name}`); |
| 106 | + try { |
| 107 | + await github.rest.repos.deleteRelease({ |
| 108 | + owner: context.repo.owner, |
| 109 | + repo: context.repo.repo, |
| 110 | + release_id: release.id |
| 111 | + }); |
| 112 | + |
| 113 | + try { |
| 114 | + await github.rest.git.deleteRef({ |
| 115 | + owner: context.repo.owner, |
| 116 | + repo: context.repo.repo, |
| 117 | + ref: `tags/${release.tag_name}` |
| 118 | + }); |
| 119 | + } catch (error) { |
| 120 | + console.log(`Tag ${release.tag_name} might not exist or already deleted`); |
| 121 | + } |
| 122 | + } catch (error) { |
| 123 | + console.log(`Failed to delete release ${release.tag_name}: ${error.message}`); |
| 124 | + } |
| 125 | + } |
| 126 | + } |
| 127 | + - name: Create nightly release |
| 128 | + id: create-release |
| 129 | + uses: actions/github-script@v7 |
| 130 | + with: |
| 131 | + script: | |
| 132 | + const timestamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, -5); |
| 133 | + const commitSha = context.sha.substring(0, 7); |
| 134 | + const tagName = 'nightly'; |
| 135 | + const releaseNotes = `🌙 **Nightly Build** |
| 136 | +
|
| 137 | + **Build Information:** |
| 138 | + - **Commit:** \`${context.sha}\` |
| 139 | + - **Branch:** \`${context.ref.replace('refs/heads/', '')}\` |
| 140 | + - **Build Time:** \`${new Date().toISOString()}\` |
| 141 | + - **Workflow:** [${context.runId}](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) |
| 142 | +
|
| 143 | + **Assets:** |
| 144 | + - soluna-Windows-soluna.exe |
| 145 | + - soluna-macOS-soluna |
| 146 | +
|
| 147 | + > ⚠️ **Note:** This is an automated nightly build. It may contain unstable features and bugs. |
| 148 | + > |
| 149 | + > 📦 **Previous nightly releases are automatically removed to keep the repository clean.`; |
| 150 | + |
| 151 | + const { data } = await github.rest.repos.createRelease({ |
| 152 | + owner: context.repo.owner, |
| 153 | + repo: context.repo.repo, |
| 154 | + tag_name: tagName, |
| 155 | + name: `Nightly Build (${timestamp})`, |
| 156 | + body: releaseNotes, |
| 157 | + prerelease: true, |
| 158 | + make_latest: 'false' |
| 159 | + }); |
| 160 | + |
| 161 | + console.log(`Created release: ${data.html_url}`); |
| 162 | + return data.id; |
| 163 | + - name: Upload release assets |
| 164 | + uses: actions/github-script@v7 |
| 165 | + with: |
| 166 | + script: | |
| 167 | + const fs = require('fs'); |
| 168 | + const path = require('path'); |
| 169 | + const releaseId = ${{ steps.create-release.outputs.result }}; |
| 170 | + |
| 171 | + const assetsDir = 'release-assets'; |
| 172 | + const files = fs.readdirSync(assetsDir); |
| 173 | + |
| 174 | + for (const file of files) { |
| 175 | + const filePath = path.join(assetsDir, file); |
| 176 | + const stats = fs.statSync(filePath); |
| 177 | + |
| 178 | + if (stats.isFile()) { |
| 179 | + console.log(`Uploading ${file}...`); |
| 180 | + |
| 181 | + const content = fs.readFileSync(filePath); |
| 182 | + |
| 183 | + await github.rest.repos.uploadReleaseAsset({ |
| 184 | + owner: context.repo.owner, |
| 185 | + repo: context.repo.repo, |
| 186 | + release_id: releaseId, |
| 187 | + name: file, |
| 188 | + data: content |
| 189 | + }); |
| 190 | + |
| 191 | + console.log(`✅ Uploaded ${file}`); |
| 192 | + } |
| 193 | + } |
0 commit comments