Skip to content

Commit f033119

Browse files
Copilotunixfox
andauthored
Add GitHub Actions workflow for rolling release binaries with automated cleanup and latest directory (#187)
* Initial plan * Add GitHub Actions workflow for cross-platform binary releases Co-authored-by: unixfox <[email protected]> * Enhance release workflow with binary verification and update README with installation instructions Co-authored-by: unixfox <[email protected]> * Implement rolling release binaries with automated cleanup in separate branch Co-authored-by: unixfox <[email protected]> * Add latest binaries directory alongside timestamped builds Co-authored-by: unixfox <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: unixfox <[email protected]>
1 parent 875cdc8 commit f033119

File tree

2 files changed

+287
-0
lines changed

2 files changed

+287
-0
lines changed
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
name: Rolling Release Binaries
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch: # Allow manual triggering
9+
10+
jobs:
11+
build-rolling-release:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
16+
strategy:
17+
matrix:
18+
target:
19+
- x86_64-pc-windows-msvc
20+
- x86_64-apple-darwin
21+
- aarch64-apple-darwin
22+
- x86_64-unknown-linux-gnu
23+
- aarch64-unknown-linux-gnu
24+
25+
steps:
26+
- name: Setup repo
27+
uses: actions/checkout@v5
28+
with:
29+
fetch-depth: 0 # Fetch full history for git commands
30+
31+
- name: Setup Deno
32+
uses: denoland/setup-deno@v2
33+
with:
34+
deno-version: v2.x
35+
36+
- name: Set binary name
37+
id: binary-name
38+
run: |
39+
echo "Building for target: ${{ matrix.target }}"
40+
SHORT_COMMIT=$(git rev-parse --short HEAD)
41+
case "${{ matrix.target }}" in
42+
*-windows-*)
43+
echo "name=invidious_companion.exe" >> $GITHUB_OUTPUT
44+
echo "archive_name=invidious_companion-${{ matrix.target }}-${SHORT_COMMIT}.zip" >> $GITHUB_OUTPUT
45+
;;
46+
*)
47+
echo "name=invidious_companion" >> $GITHUB_OUTPUT
48+
echo "archive_name=invidious_companion-${{ matrix.target }}-${SHORT_COMMIT}.tar.gz" >> $GITHUB_OUTPUT
49+
;;
50+
esac
51+
echo "Binary name: $(cat $GITHUB_OUTPUT | grep '^name=' | cut -d= -f2)"
52+
echo "Archive name: $(cat $GITHUB_OUTPUT | grep '^archive_name=' | cut -d= -f2)"
53+
54+
- name: Build binary
55+
run: |
56+
deno compile \
57+
--target="${{ matrix.target }}" \
58+
--include ./src/lib/helpers/youtubePlayerReq.ts \
59+
--include ./src/lib/helpers/getFetchClient.ts \
60+
--output "${{ steps.binary-name.outputs.name }}" \
61+
--allow-import=github.com:443,jsr.io:443,cdn.jsdelivr.net:443,esm.sh:443,deno.land:443 \
62+
--allow-net \
63+
--allow-env \
64+
--allow-read \
65+
--allow-sys=hostname \
66+
--allow-write=/var/tmp/youtubei.js,/tmp/invidious-companion.sock \
67+
src/main.ts \
68+
--_version_date="$(git log -1 --format=%ci | awk '{print $1}' | sed s/-/./g)" \
69+
--_version_commit="$(git rev-list HEAD --max-count=1 --abbrev-commit)"
70+
71+
- name: Verify binary
72+
run: |
73+
if [ -f "${{ steps.binary-name.outputs.name }}" ]; then
74+
echo "✅ Binary created successfully: ${{ steps.binary-name.outputs.name }}"
75+
ls -la "${{ steps.binary-name.outputs.name }}"
76+
else
77+
echo "❌ Binary not found: ${{ steps.binary-name.outputs.name }}"
78+
exit 1
79+
fi
80+
81+
- name: Create archive
82+
run: |
83+
case "${{ matrix.target }}" in
84+
*-windows-*)
85+
zip "${{ steps.binary-name.outputs.archive_name }}" "${{ steps.binary-name.outputs.name }}"
86+
;;
87+
*)
88+
tar -czf "${{ steps.binary-name.outputs.archive_name }}" "${{ steps.binary-name.outputs.name }}"
89+
;;
90+
esac
91+
92+
- name: Upload artifact for binaries job
93+
uses: actions/upload-artifact@v4
94+
with:
95+
name: binary-${{ matrix.target }}
96+
path: |
97+
${{ steps.binary-name.outputs.archive_name }}
98+
retention-days: 1
99+
100+
manage-binaries:
101+
needs: build-rolling-release
102+
runs-on: ubuntu-latest
103+
permissions:
104+
contents: write
105+
106+
steps:
107+
- name: Setup repo
108+
uses: actions/checkout@v5
109+
with:
110+
fetch-depth: 0
111+
token: ${{ secrets.GITHUB_TOKEN }}
112+
113+
- name: Download all artifacts
114+
uses: actions/download-artifact@v4
115+
with:
116+
path: ./binaries
117+
118+
- name: Setup git for binaries branch
119+
run: |
120+
git config user.name "github-actions[bot]"
121+
git config user.email "github-actions[bot]@users.noreply.github.com"
122+
123+
- name: Create or switch to binaries branch
124+
run: |
125+
# Check if binaries branch exists remotely
126+
if git ls-remote --heads origin binaries | grep -q binaries; then
127+
echo "Binaries branch exists, checking it out"
128+
git fetch origin binaries:binaries
129+
git checkout binaries
130+
else
131+
echo "Creating new binaries branch"
132+
git checkout --orphan binaries
133+
git rm -rf .
134+
echo "# Rolling Release Binaries" > README.md
135+
echo "" >> README.md
136+
echo "This branch contains pre-compiled binaries for invidious-companion." >> README.md
137+
echo "Binaries are automatically built from each commit to the main branch." >> README.md
138+
echo "" >> README.md
139+
echo "## Latest Binaries" >> README.md
140+
echo "" >> README.md
141+
git add README.md
142+
git commit -m "Initialize binaries branch"
143+
fi
144+
145+
- name: Add new binaries
146+
run: |
147+
# Create timestamp-based directory
148+
COMMIT_SHORT=$(git log -1 --format="%h" origin/main)
149+
COMMIT_DATE=$(git log -1 --format="%Y%m%d-%H%M" origin/main)
150+
BINARY_DIR="${COMMIT_DATE}-${COMMIT_SHORT}"
151+
152+
mkdir -p "${BINARY_DIR}"
153+
mkdir -p "latest"
154+
155+
# Move all downloaded binaries to both timestamped and latest directories
156+
find ./binaries -name "*.tar.gz" -o -name "*.zip" | while read -r file; do
157+
if [ -f "$file" ]; then
158+
cp "$file" "${BINARY_DIR}/"
159+
cp "$file" "latest/"
160+
echo "Added: ${BINARY_DIR}/$(basename "$file")"
161+
echo "Added: latest/$(basename "$file")"
162+
fi
163+
done
164+
165+
# Clean up artifacts directory
166+
rm -rf ./binaries
167+
168+
- name: Clean up old binaries (keep latest 20)
169+
run: |
170+
# Count current timestamped directories (excluding . and .. and latest)
171+
TOTAL_DIRS=$(find . -maxdepth 1 -type d -name "*-*" ! -name "latest" | wc -l)
172+
echo "Total timestamped binary directories: $TOTAL_DIRS"
173+
174+
if [ "$TOTAL_DIRS" -gt 20 ]; then
175+
# Get directories sorted by modification time (oldest first)
176+
# Remove oldest directories to keep only 20 latest
177+
DIRS_TO_REMOVE=$((TOTAL_DIRS - 20))
178+
echo "Removing $DIRS_TO_REMOVE old binary directories"
179+
180+
find . -maxdepth 1 -type d -name "*-*" ! -name "latest" -printf "%T@ %p\n" | \
181+
sort -n | \
182+
head -n $DIRS_TO_REMOVE | \
183+
cut -d' ' -f2- | \
184+
while read -r dir; do
185+
echo "Removing old directory: $dir"
186+
rm -rf "$dir"
187+
done
188+
fi
189+
190+
- name: Update README with latest binaries
191+
run: |
192+
# Generate new README.md with current binaries
193+
echo "# Rolling Release Binaries" > README.md
194+
echo "" >> README.md
195+
echo "This branch contains pre-compiled binaries for invidious-companion." >> README.md
196+
echo "Binaries are automatically built from each commit to the main branch." >> README.md
197+
echo "" >> README.md
198+
echo "## 🚀 Latest Binaries (Recommended)" >> README.md
199+
echo "" >> README.md
200+
echo "The latest binaries are always available in the \`latest\` directory:" >> README.md
201+
echo "" >> README.md
202+
203+
# List latest binaries
204+
if [ -d "latest" ]; then
205+
find "latest" -type f \( -name "*.tar.gz" -o -name "*.zip" \) | \
206+
sort | \
207+
while read -r file; do
208+
filename=$(basename "$file")
209+
echo "- [$filename]($file)" >> README.md
210+
done
211+
fi
212+
213+
echo "" >> README.md
214+
echo "## 📚 All Available Builds" >> README.md
215+
echo "" >> README.md
216+
echo "Historical builds are organized by build date and commit hash:" >> README.md
217+
echo "" >> README.md
218+
219+
# List directories in reverse chronological order (newest first)
220+
find . -maxdepth 1 -type d -name "*-*" ! -name "latest" -printf "%T@ %p\n" | \
221+
sort -nr | \
222+
cut -d' ' -f2- | \
223+
head -20 | \
224+
while read -r dir; do
225+
dirname=$(basename "$dir")
226+
echo "### $dirname" >> README.md
227+
echo "" >> README.md
228+
if [ -d "$dir" ]; then
229+
find "$dir" -type f \( -name "*.tar.gz" -o -name "*.zip" \) | \
230+
sort | \
231+
while read -r file; do
232+
filename=$(basename "$file")
233+
echo "- [$filename]($file)" >> README.md
234+
done
235+
fi
236+
echo "" >> README.md
237+
done
238+
239+
echo "" >> README.md
240+
echo "## Platform Support" >> README.md
241+
echo "" >> README.md
242+
echo "- **Linux**: \`x86_64\` and \`aarch64\` (ARM64) - \`.tar.gz\` archives" >> README.md
243+
echo "- **macOS**: Intel (\`x86_64\`) and Apple Silicon (\`aarch64\`) - \`.tar.gz\` archives" >> README.md
244+
echo "- **Windows**: \`x86_64\` - \`.zip\` archives" >> README.md
245+
echo "" >> README.md
246+
echo "## Installation" >> README.md
247+
echo "" >> README.md
248+
echo "1. **Recommended**: Download from the \`latest\` directory above for the most recent build" >> README.md
249+
echo "2. Alternatively, choose a specific build from the historical builds section" >> README.md
250+
echo "3. Download the archive for your platform" >> README.md
251+
echo "4. Extract the archive to get the \`invidious_companion\` binary" >> README.md
252+
echo "5. Make the binary executable (Linux/macOS): \`chmod +x invidious_companion\`" >> README.md
253+
echo "6. Run the binary: \`./invidious_companion\`" >> README.md
254+
echo "" >> README.md
255+
256+
- name: Commit and push binaries
257+
run: |
258+
git add .
259+
if git diff --staged --quiet; then
260+
echo "No changes to commit"
261+
else
262+
COMMIT_SHORT=$(git log -1 --format="%h" origin/main)
263+
COMMIT_MSG=$(git log -1 --format="%s" origin/main)
264+
git commit -m "Add binaries for commit $COMMIT_SHORT: $COMMIT_MSG"
265+
git push origin binaries
266+
echo "✅ Binaries pushed to binaries branch"
267+
fi

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
Companion for Invidious which handle all the video stream retrieval from YouTube servers.
44

5+
## Installation
6+
7+
### Pre-built binaries (Rolling Release)
8+
9+
Pre-built binaries are automatically generated for every commit and are available in the [`binaries`](https://github.com/iv-org/invidious-companion/tree/binaries) branch. Binaries are provided for:
10+
11+
- **Linux**: `x86_64` and `aarch64` (ARM64)
12+
- **macOS**: Intel (`x86_64`) and Apple Silicon (`aarch64`)
13+
- **Windows**: `x86_64`
14+
15+
To download:
16+
1. Visit the [`binaries`](https://github.com/iv-org/invidious-companion/tree/binaries) branch
17+
2. Navigate to the latest directory (organized by date and commit)
18+
3. Download the appropriate binary archive for your platform
19+
4. Extract and run the binary
20+
21+
The 20 most recent builds are kept available in the binaries branch.
22+
23+
### Build from source
24+
525
## Requirements
626

727
- [deno](https://docs.deno.com/runtime/)

0 commit comments

Comments
 (0)