Fix release-binaries.yaml workflow hardcoded origin/main references (… #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rolling Release Binaries | |
on: | |
push: | |
branches: | |
- main | |
- master | |
workflow_dispatch: # Allow manual triggering | |
jobs: | |
build-rolling-release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
strategy: | |
matrix: | |
target: | |
- x86_64-pc-windows-msvc | |
- x86_64-apple-darwin | |
- aarch64-apple-darwin | |
- x86_64-unknown-linux-gnu | |
- aarch64-unknown-linux-gnu | |
steps: | |
- name: Setup repo | |
uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 # Fetch full history for git commands | |
- name: Setup Deno | |
uses: denoland/setup-deno@v2 | |
with: | |
deno-version: v2.x | |
- name: Set binary name | |
id: binary-name | |
run: | | |
echo "Building for target: ${{ matrix.target }}" | |
SHORT_COMMIT=$(git rev-parse --short HEAD) | |
case "${{ matrix.target }}" in | |
*-windows-*) | |
echo "name=invidious_companion.exe" >> $GITHUB_OUTPUT | |
echo "archive_name=invidious_companion-${{ matrix.target }}-${SHORT_COMMIT}.zip" >> $GITHUB_OUTPUT | |
;; | |
*) | |
echo "name=invidious_companion" >> $GITHUB_OUTPUT | |
echo "archive_name=invidious_companion-${{ matrix.target }}-${SHORT_COMMIT}.tar.gz" >> $GITHUB_OUTPUT | |
;; | |
esac | |
echo "Binary name: $(cat $GITHUB_OUTPUT | grep '^name=' | cut -d= -f2)" | |
echo "Archive name: $(cat $GITHUB_OUTPUT | grep '^archive_name=' | cut -d= -f2)" | |
- name: Build binary | |
run: | | |
deno compile \ | |
--target="${{ matrix.target }}" \ | |
--include ./src/lib/helpers/youtubePlayerReq.ts \ | |
--include ./src/lib/helpers/getFetchClient.ts \ | |
--output "${{ steps.binary-name.outputs.name }}" \ | |
--allow-import=github.com:443,jsr.io:443,cdn.jsdelivr.net:443,esm.sh:443,deno.land:443 \ | |
--allow-net \ | |
--allow-env \ | |
--allow-read \ | |
--allow-sys=hostname \ | |
--allow-write=/var/tmp/youtubei.js,/tmp/invidious-companion.sock \ | |
src/main.ts \ | |
--_version_date="$(git log -1 --format=%ci | awk '{print $1}' | sed s/-/./g)" \ | |
--_version_commit="$(git rev-list HEAD --max-count=1 --abbrev-commit)" | |
- name: Verify binary | |
run: | | |
if [ -f "${{ steps.binary-name.outputs.name }}" ]; then | |
echo "✅ Binary created successfully: ${{ steps.binary-name.outputs.name }}" | |
ls -la "${{ steps.binary-name.outputs.name }}" | |
else | |
echo "❌ Binary not found: ${{ steps.binary-name.outputs.name }}" | |
exit 1 | |
fi | |
- name: Create archive | |
run: | | |
case "${{ matrix.target }}" in | |
*-windows-*) | |
zip "${{ steps.binary-name.outputs.archive_name }}" "${{ steps.binary-name.outputs.name }}" | |
;; | |
*) | |
tar -czf "${{ steps.binary-name.outputs.archive_name }}" "${{ steps.binary-name.outputs.name }}" | |
;; | |
esac | |
- name: Upload artifact for binaries job | |
uses: actions/upload-artifact@v4 | |
with: | |
name: binary-${{ matrix.target }} | |
path: | | |
${{ steps.binary-name.outputs.archive_name }} | |
retention-days: 1 | |
manage-binaries: | |
needs: build-rolling-release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Setup repo | |
uses: actions/checkout@v5 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./binaries | |
- name: Setup git for binaries branch | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Create or switch to binaries branch | |
run: | | |
# Check if binaries branch exists remotely | |
if git ls-remote --heads origin binaries | grep -q binaries; then | |
echo "Binaries branch exists, checking it out" | |
git fetch origin binaries:binaries | |
git checkout binaries | |
else | |
echo "Creating new binaries branch" | |
git checkout --orphan binaries | |
git rm -rf . | |
echo "# Rolling Release Binaries" > README.md | |
echo "" >> README.md | |
echo "This branch contains pre-compiled binaries for invidious-companion." >> README.md | |
echo "Binaries are automatically built from each commit to the main branch." >> README.md | |
echo "" >> README.md | |
echo "## Latest Binaries" >> README.md | |
echo "" >> README.md | |
git add README.md | |
git commit -m "Initialize binaries branch" | |
fi | |
- name: Add new binaries | |
run: | | |
# Create timestamp-based directory | |
# Use the branch that triggered this workflow | |
TRIGGER_BRANCH="${{ github.ref_name }}" | |
COMMIT_SHORT=$(git log -1 --format="%h" "origin/$TRIGGER_BRANCH") | |
COMMIT_DATE=$(git log -1 --format="%Y%m%d-%H%M" "origin/$TRIGGER_BRANCH") | |
BINARY_DIR="${COMMIT_DATE}-${COMMIT_SHORT}" | |
mkdir -p "${BINARY_DIR}" | |
mkdir -p "latest" | |
# Move all downloaded binaries to both timestamped and latest directories | |
find ./binaries -name "*.tar.gz" -o -name "*.zip" | while read -r file; do | |
if [ -f "$file" ]; then | |
cp "$file" "${BINARY_DIR}/" | |
cp "$file" "latest/" | |
echo "Added: ${BINARY_DIR}/$(basename "$file")" | |
echo "Added: latest/$(basename "$file")" | |
fi | |
done | |
# Clean up artifacts directory | |
rm -rf ./binaries | |
- name: Clean up old binaries (keep latest 20) | |
run: | | |
# Count current timestamped directories (excluding . and .. and latest) | |
TOTAL_DIRS=$(find . -maxdepth 1 -type d -name "*-*" ! -name "latest" | wc -l) | |
echo "Total timestamped binary directories: $TOTAL_DIRS" | |
if [ "$TOTAL_DIRS" -gt 20 ]; then | |
# Get directories sorted by modification time (oldest first) | |
# Remove oldest directories to keep only 20 latest | |
DIRS_TO_REMOVE=$((TOTAL_DIRS - 20)) | |
echo "Removing $DIRS_TO_REMOVE old binary directories" | |
find . -maxdepth 1 -type d -name "*-*" ! -name "latest" -printf "%T@ %p\n" | \ | |
sort -n | \ | |
head -n $DIRS_TO_REMOVE | \ | |
cut -d' ' -f2- | \ | |
while read -r dir; do | |
echo "Removing old directory: $dir" | |
rm -rf "$dir" | |
done | |
fi | |
- name: Update README with latest binaries | |
run: | | |
# Generate new README.md with current binaries | |
echo "# Rolling Release Binaries" > README.md | |
echo "" >> README.md | |
echo "This branch contains pre-compiled binaries for invidious-companion." >> README.md | |
echo "Binaries are automatically built from each commit to the main branch." >> README.md | |
echo "" >> README.md | |
echo "## 🚀 Latest Binaries (Recommended)" >> README.md | |
echo "" >> README.md | |
echo "The latest binaries are always available in the \`latest\` directory:" >> README.md | |
echo "" >> README.md | |
# List latest binaries | |
if [ -d "latest" ]; then | |
find "latest" -type f \( -name "*.tar.gz" -o -name "*.zip" \) | \ | |
sort | \ | |
while read -r file; do | |
filename=$(basename "$file") | |
echo "- [$filename]($file)" >> README.md | |
done | |
fi | |
echo "" >> README.md | |
echo "## 📚 All Available Builds" >> README.md | |
echo "" >> README.md | |
echo "Historical builds are organized by build date and commit hash:" >> README.md | |
echo "" >> README.md | |
# List directories in reverse chronological order (newest first) | |
find . -maxdepth 1 -type d -name "*-*" ! -name "latest" -printf "%T@ %p\n" | \ | |
sort -nr | \ | |
cut -d' ' -f2- | \ | |
head -20 | \ | |
while read -r dir; do | |
dirname=$(basename "$dir") | |
echo "### $dirname" >> README.md | |
echo "" >> README.md | |
if [ -d "$dir" ]; then | |
find "$dir" -type f \( -name "*.tar.gz" -o -name "*.zip" \) | \ | |
sort | \ | |
while read -r file; do | |
filename=$(basename "$file") | |
echo "- [$filename]($file)" >> README.md | |
done | |
fi | |
echo "" >> README.md | |
done | |
echo "" >> README.md | |
echo "## Platform Support" >> README.md | |
echo "" >> README.md | |
echo "- **Linux**: \`x86_64\` and \`aarch64\` (ARM64) - \`.tar.gz\` archives" >> README.md | |
echo "- **macOS**: Intel (\`x86_64\`) and Apple Silicon (\`aarch64\`) - \`.tar.gz\` archives" >> README.md | |
echo "- **Windows**: \`x86_64\` - \`.zip\` archives" >> README.md | |
echo "" >> README.md | |
echo "## Installation" >> README.md | |
echo "" >> README.md | |
echo "1. **Recommended**: Download from the \`latest\` directory above for the most recent build" >> README.md | |
echo "2. Alternatively, choose a specific build from the historical builds section" >> README.md | |
echo "3. Download the archive for your platform" >> README.md | |
echo "4. Extract the archive to get the \`invidious_companion\` binary" >> README.md | |
echo "5. Make the binary executable (Linux/macOS): \`chmod +x invidious_companion\`" >> README.md | |
echo "6. Run the binary: \`./invidious_companion\`" >> README.md | |
echo "" >> README.md | |
- name: Commit and push binaries | |
run: | | |
git add . | |
if git diff --staged --quiet; then | |
echo "No changes to commit" | |
else | |
# Use the branch that triggered this workflow | |
TRIGGER_BRANCH="${{ github.ref_name }}" | |
COMMIT_SHORT=$(git log -1 --format="%h" "origin/$TRIGGER_BRANCH") | |
COMMIT_MSG=$(git log -1 --format="%s" "origin/$TRIGGER_BRANCH") | |
git commit -m "Add binaries for commit $COMMIT_SHORT: $COMMIT_MSG" | |
git push origin binaries | |
echo "✅ Binaries pushed to binaries branch" | |
fi |