Skip to content

Move the updater to new github endpoints #6

Move the updater to new github endpoints

Move the updater to new github endpoints #6

name: Build Renderer (Windows)
on:
push:
branches: [ main ]
paths:
- 'projects/renderer/**'
- '.github/workflows/build-renderer.yml'
pull_request:
branches: [ main ]
paths:
- 'projects/renderer/**'
- '.github/workflows/build-renderer.yml'
jobs:
build:
runs-on: windows-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Get package version
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: package_version
run: |
cd projects/renderer
$VERSION = node -p "require('./package.json').version"
echo "version=$VERSION" >> $env:GITHUB_OUTPUT
- name: Check if version changed
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
id: version_check
run: |
if (Test-Path "build-meta/latest/renderer.json") {
try {
$CURRENT_VERSION = node -p "JSON.parse(require('fs').readFileSync('build-meta/latest/renderer.json', 'utf8')).version" 2>$null
if ("$CURRENT_VERSION" -eq "${{ steps.package_version.outputs.version }}") {
echo "version_changed=false" >> $env:GITHUB_OUTPUT
echo "Version ${{ steps.package_version.outputs.version }} already exists, skipping build"
} else {
echo "version_changed=true" >> $env:GITHUB_OUTPUT
echo "Version changed from '$CURRENT_VERSION' to '${{ steps.package_version.outputs.version }}'"
}
} catch {
echo "version_changed=true" >> $env:GITHUB_OUTPUT
echo "Could not read existing version, creating new build"
}
} else {
echo "version_changed=true" >> $env:GITHUB_OUTPUT
echo "No existing meta file found, creating new one"
}
- name: Setup Yarn
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
run: npm install -g yarn
- name: Install dependencies
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
run: |
cd projects/renderer
yarn install
echo "version_changed=true" >> $env:GITHUB_OUTPUT
echo "No existing meta file found, creating new one"
}
- name: Build Electron app
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
run: |
cd projects/renderer
yarn build
- name: Get current date
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
id: date
run: |
$DATE = Get-Date -Format "yyyyMMdd_HHmmss"
echo "date=$DATE" >> $env:GITHUB_OUTPUT
- name: Get build file hash
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
id: build_hash
run: |
cd projects/renderer
$SETUP_FILE = Get-ChildItem -Path "dist" -Filter "*.exe" | Select-Object -First 1
if ($SETUP_FILE) {
$HASH = Get-FileHash -Path $SETUP_FILE.FullName -Algorithm MD5
echo "md5=$($HASH.Hash.ToLower())" >> $env:GITHUB_OUTPUT
echo "filename=$($SETUP_FILE.Name)" >> $env:GITHUB_OUTPUT
echo "filepath=$($SETUP_FILE.FullName)" >> $env:GITHUB_OUTPUT
} else {
echo "No setup file found!"
exit 1
}
- name: Upload build artifacts
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
uses: actions/upload-artifact@v4
with:
name: renderer-build-artifacts
path: |
${{ steps.build_hash.outputs.filepath }}
retention-days: 90
- name: Create Release
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: renderer-build-${{ steps.date.outputs.date }}
name: Renderer Build Release v${{ steps.package_version.outputs.version }}
body: |
Automated renderer build from commit ${{ github.sha }}
**Build Info:**
- Version: ${{ steps.package_version.outputs.version }}
- Commit: ${{ github.sha }}
- Branch: ${{ github.ref_name }}
- Date: ${{ steps.date.outputs.date }}
- Platform: Windows
**Files:**
- `${{ steps.build_hash.outputs.filename }}`: Windows installer executable
**Installation:**
1. Download the `.exe` file
2. Run as administrator if needed
3. Follow the installation wizard
files: |
${{ steps.build_hash.outputs.filepath }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update build meta JSON
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
run: |
if (!(Test-Path "build-meta/latest")) {
New-Item -ItemType Directory -Path "build-meta/latest" -Force
}
$META = @{
tag = "renderer-build-${{ steps.date.outputs.date }}"
version = "${{ steps.package_version.outputs.version }}"
md5 = "${{ steps.build_hash.outputs.md5 }}"
filename = "${{ steps.build_hash.outputs.filename }}"
buildDate = "${{ steps.date.outputs.date }}"
commit = "${{ github.sha }}"
platform = "windows"
}
$META | ConvertTo-Json -Depth 10 | Out-File -FilePath "build-meta/latest/renderer.json" -Encoding UTF8
- name: Commit and push meta file
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && steps.version_check.outputs.version_changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add build-meta/latest/renderer.json
git commit -m "Update renderer build meta: v${{ steps.package_version.outputs.version }} (renderer-build-${{ steps.date.outputs.date }})"
git push