Sync Unity Hub Installers #40
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: Sync Unity Hub Installers | |
| on: | |
| schedule: | |
| - cron: '23 16 * * *' # UTC 16:23 daily (00:23 Beijing time) | |
| workflow_dispatch: | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install 7z | |
| run: sudo apt-get update && sudo apt-get install -y p7zip-full | |
| - name: Download installers | |
| id: download | |
| run: | | |
| mkdir -p dist | |
| urls=( | |
| "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup-arm64.dmg" | |
| "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup-x64.deb" | |
| "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup-amd64.deb" | |
| "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup-x86_64.rpm" | |
| "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup-x64.exe" | |
| "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup-arm64.exe" | |
| ) | |
| FAILED=0 | |
| SUCCESS=0 | |
| for url in "${urls[@]}"; do | |
| filename=$(basename "$url") | |
| echo "Downloading $filename ..." | |
| if curl -fSL -o "dist/$filename" "$url" 2>/dev/null; then | |
| echo " OK" | |
| SUCCESS=$((SUCCESS + 1)) | |
| else | |
| echo " FAILED (skipped)" | |
| rm -f "dist/$filename" | |
| FAILED=$((FAILED + 1)) | |
| fi | |
| done | |
| echo "" | |
| echo "Result: $SUCCESS succeeded, $FAILED failed" | |
| echo "### Download summary" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Succeeded: $SUCCESS" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- Failed: $FAILED" >> "$GITHUB_STEP_SUMMARY" | |
| ls -lh dist/ >> "$GITHUB_STEP_SUMMARY" || true | |
| if [ "$SUCCESS" -eq 0 ]; then | |
| echo "### No files downloaded, aborting" | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Compute MD5 and compare with previous release | |
| id: md5 | |
| if: steps.download.outputs.skip != 'true' | |
| run: | | |
| echo "Computing MD5 checksums..." | |
| md5sum dist/* > dist/checksums.md5 | |
| cat dist/checksums.md5 | |
| # Find previous release's hashes.md5 | |
| CHANGED="false" | |
| PREV_TAG=$(gh release list --limit 10 --json tagName,publishedAt \ | |
| --jq 'sort_by(.publishedAt) | reverse | .[0].tagName' 2>/dev/null || echo "") | |
| if [ -n "$PREV_TAG" ]; then | |
| echo "Previous release: $PREV_TAG" | |
| if gh release download "$PREV_TAG" -p "hashes.md5" -D /tmp/prev_hashes 2>/dev/null; then | |
| if ! diff -q <(sort /tmp/prev_hashes/hashes.md5) <(sort dist/checksums.md5) > /dev/null 2>&1; then | |
| CHANGED="true" | |
| echo "### Hash mismatch detected (vs $PREV_TAG)" >> "$GITHUB_STEP_SUMMARY" | |
| diff <(sort /tmp/prev_hashes/hashes.md5) <(sort dist/checksums.md5) >> "$GITHUB_STEP_SUMMARY" || true | |
| else | |
| echo "### All checksums match $PREV_TAG - no update needed" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| else | |
| CHANGED="true" | |
| echo "### No hashes.md5 in $PREV_TAG - first run with hashes" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| else | |
| CHANGED="true" | |
| echo "### No previous releases found" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| echo "changed=$CHANGED" >> "$GITHUB_OUTPUT" | |
| - name: Extract version from exe | |
| id: version | |
| if: steps.md5.outputs.changed == 'true' | |
| run: | | |
| exe_file="" | |
| for f in dist/UnityHubSetup-x64.exe dist/UnityHubSetup-arm64.exe; do | |
| if [ -f "$f" ]; then | |
| exe_file="$f" | |
| break | |
| fi | |
| done | |
| if [ -z "$exe_file" ]; then | |
| echo "No exe file available, using date-based tag" | |
| VERSION="$(date -u +%Y.%m.%d)" | |
| else | |
| echo "Extracting version from $exe_file..." | |
| # Method 1: Read PE version info via 7z list (format: "ProductVersion: 3.19.5") | |
| VERSION=$(7z l "$exe_file" 2>/dev/null | grep -oP 'ProductVersion:\s+\K[0-9]+\.[0-9]+\.[0-9]+' | head -1) | |
| # Method 2: Fallback - search all extracted text for version | |
| if [ -z "$VERSION" ]; then | |
| echo "Fallback: searching for version string..." | |
| VERSION=$(7z l "$exe_file" 2>/dev/null | grep -oP '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | |
| fi | |
| if [ -z "$VERSION" ]; then | |
| echo "Warning: Could not extract version, using date suffix" | |
| VERSION="$(date -u +%Y.%m.%d)" | |
| fi | |
| fi | |
| TAG="v${VERSION}" | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "### Extracted version: $TAG" >> "$GITHUB_STEP_SUMMARY" | |
| - name: Check existing release | |
| id: check | |
| if: steps.md5.outputs.changed == 'true' | |
| run: | | |
| TAG="${{ steps.version.outputs.tag }}" | |
| EXISTS=$(gh release view "$TAG" --json tagName --jq '.tagName' 2>/dev/null || echo "") | |
| if [ -n "$EXISTS" ]; then | |
| echo "exists=true" >> "$GITHUB_OUTPUT" | |
| echo "### Release $TAG already exists, will update" >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| echo "exists=false" >> "$GITHUB_OUTPUT" | |
| echo "### Release $TAG is new" >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Delete existing release | |
| if: steps.md5.outputs.changed == 'true' && steps.check.outputs.exists == 'true' | |
| run: | | |
| gh release delete "${{ steps.version.outputs.tag }}" --yes --cleanup-tag | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create release and upload assets | |
| if: steps.md5.outputs.changed == 'true' | |
| run: | | |
| TAG="${{ steps.version.outputs.tag }}" | |
| # Collect only files that exist | |
| FILES=$(find dist -maxdepth 1 -type f ! -name 'checksums.md5' -printf '%f\n' | sort) | |
| if [ -z "$FILES" ]; then | |
| echo "No files to upload" | |
| exit 1 | |
| fi | |
| echo "Uploading:" | |
| echo "$FILES" | |
| # Create release with hashes.md5 included | |
| gh release create "$TAG" \ | |
| --title "Unity Hub $TAG" \ | |
| --notes "Unity Hub $TAG - Auto-synced on $(date -u '+%Y-%m-%d %H:%M UTC')" \ | |
| dist/checksums.md5 \ | |
| $(echo "$FILES" | sed 's/^/dist\//') | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |