-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (188 loc) · 7.02 KB
/
build-and-release.yml
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
name: Nightly Build and Release
on:
schedule:
- cron: "0 0 * * *" # Runs every day at midnight UTC
workflow_dispatch: # Allows manual trigger
permissions:
contents: write
packages: write
security-events: write
jobs:
check-and-build:
runs-on: ubuntu-latest
outputs:
new_release: ${{ steps.set-output.outputs.new_release }}
latest_commit_hash: ${{ steps.set-output.outputs.latest_commit_hash }}
latest_server_tag: ${{ steps.set-output.outputs.latest_server_tag }}
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
# Step 3: Install dependencies
- name: Install dependencies
run: npm install
# Step 4: Fetch latest Stremio versions
- name: Fetch latest Stremio versions
run: node scripts/fetch-latest-stremio.js
# Step 5: Get the latest release description
- name: Get latest release
id: latest-release
uses: actions/github-script@v6
with:
script: |
try {
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
core.setOutput('description', latestRelease.data.body || '');
core.setOutput('found', true);
} catch (error) {
if (error.status === 404) {
console.log('No releases found. This is the initial run.');
core.setOutput('description', '');
core.setOutput('found', false);
} else {
throw error;
}
}
# Step 6: Compare fetched versions with release versions and set outputs
- name: Check for new versions and set outputs
id: set-output
run: |
if [ "${{ steps.latest-release.outputs.found }}" != "true" ]; then
echo "new_release=true" >> $GITHUB_OUTPUT
else
LATEST_DESCRIPTION="${{ steps.latest-release.outputs.description }}"
if [[ "$LATEST_DESCRIPTION" == *"Web version: $LATEST_COMMIT_HASH"* && "$LATEST_DESCRIPTION" == *"Server version: $LATEST_SERVER_TAG"* ]]; then
echo "new_release=false" >> $GITHUB_OUTPUT
else
echo "new_release=true" >> $GITHUB_OUTPUT
fi
fi
echo "latest_commit_hash=$LATEST_COMMIT_HASH" >> $GITHUB_OUTPUT
echo "latest_server_tag=$LATEST_SERVER_TAG" >> $GITHUB_OUTPUT
- name: Debug Variables
run: |
echo "LATEST_COMMIT_HASH: $LATEST_COMMIT_HASH"
echo "LATEST_SERVER_TAG: $LATEST_SERVER_TAG"
# Step 7: Upload stremio-web and stremio-server as artifacts
- name: Upload stremio-web and stremio-server
if: ${{ steps.set-output.outputs.new_release == 'true' }}
uses: actions/upload-artifact@v4
with:
name: stremio-artifacts
path: |
src/stremio-web
src/stremio-server
build:
needs: check-and-build
if: ${{ needs.check-and-build.outputs.new_release == 'true' }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Download stremio-artifacts
- name: Download stremio-artifacts
uses: actions/download-artifact@v4
with:
name: stremio-artifacts
path: src
# Step 3: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
# Step 4: Install dependencies
- name: Install dependencies
run: npm install
# Step 5: Build for platform and handle Windows ZIP and setup.exe
- name: Build for ${{ matrix.os }}
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
echo "Building for Windows..."
npm run make -- --platform=win32
echo "Creating ZIP for Windows..."
mkdir -p out/windows/
# Compress with PowerShell, excluding start.exe
pwsh -Command "Compress-Archive -Path 'out/stremio-web-desktop-win32-x64/*' -DestinationPath 'out/windows/stremio-web-desktop-win32-x64.zip'"
# Find the setup.exe with random name and copy to out/windows/
setup_exe=$(find out/make/squirrel.windows/x64/ -type f -name "*.exe" | head -n 1)
cp "$setup_exe" out/windows/
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
echo "Building for macOS..."
npm run make -- --platform=darwin
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
echo "Building for Linux..."
npm run make -- --platform=linux
fi
# Step 6: Upload build artifacts
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: stremio-${{ matrix.os }}
path: |
# Windows: Upload ZIP and setup.exe
out/windows/*.zip
out/windows/*.exe
# macOS: Upload DMG
out/make/**/*.dmg
# Ubuntu: Upload DEB and RPM
out/make/**/*.deb
out/make/**/*.rpm
release:
needs: build
if: ${{ needs.check-and-build.outputs.new_release == 'true' }}
runs-on: ubuntu-latest
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v3
- name: Debug Variables
run: |
echo '${{toJSON(needs.check-and-build.outputs)}}'
# Step 2: Download all artifacts
- name: Download Windows artifacts
uses: actions/download-artifact@v4
with:
name: stremio-windows-latest
path: out/windows
- name: Download macOS artifacts
uses: actions/download-artifact@v4
with:
name: stremio-macos-latest
path: out/macos
- name: Download Ubuntu artifacts
uses: actions/download-artifact@v4
with:
name: stremio-ubuntu-latest
path: out/ubuntu
# Step 3: Create GitHub Release
- name: Create GitHub Release
uses: ncipollo/[email protected]
env:
LATEST_COMMIT_HASH: ${{needs.check-and-build.outputs.latest_commit_hash}}
LATEST_SERVER_TAG: ${{needs.check-and-build.outputs.latest_server_tag}}
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ github.run_number }}
name: "Stremio Web Desktop v${{ github.run_number }}"
body: |
Web version: "$LATEST_COMMIT_HASH"
Server version: "$LATEST_SERVER_TAG"
artifacts: |
out/windows/**/*.zip
out/windows/**/*.exe
out/macos/**/*.dmg
out/ubuntu/**/*.deb
out/ubuntu/**/*.rpm