Publish OTA Update #10
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: Publish OTA Update | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| linux_run_id: | |
| description: "Linux build workflow run ID" | |
| type: string | |
| required: false | |
| windows_run_id: | |
| description: "Windows build workflow run ID" | |
| type: string | |
| required: false | |
| mac_run_id: | |
| description: "macOS build workflow run ID" | |
| type: string | |
| required: false | |
| run_id: | |
| description: "Fallback run ID to download OTA artifacts from" | |
| type: string | |
| required: false | |
| workflow_call: | |
| inputs: | |
| linux_run_id: | |
| description: "Linux build workflow run ID" | |
| type: string | |
| required: false | |
| windows_run_id: | |
| description: "Windows build workflow run ID" | |
| type: string | |
| required: false | |
| mac_run_id: | |
| description: "macOS build workflow run ID" | |
| type: string | |
| required: false | |
| run_id: | |
| description: "Fallback run ID to download OTA artifacts from" | |
| type: string | |
| required: false | |
| jobs: | |
| publish: | |
| name: Publish OTA | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| with: | |
| sparse-checkout: | | |
| Telegram/build/version | |
| - name: Read version info | |
| id: version | |
| run: | | |
| VERSION_FILE="Telegram/build/version" | |
| APP_VERSION=$(grep 'AppVersion ' "$VERSION_FILE" | awk '{print $2}') | |
| BETA=$(grep 'BetaChannel' "$VERSION_FILE" | awk '{print $2}') | |
| echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV | |
| echo "IS_BETA=$BETA" >> $GITHUB_ENV | |
| - name: Download Windows OTA artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: ota-win64 | |
| path: ota-artifacts/win64 | |
| run-id: ${{ inputs.windows_run_id || inputs.run_id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download Linux OTA artifact | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: ota-linux | |
| path: ota-artifacts/linux | |
| run-id: ${{ inputs.linux_run_id || inputs.run_id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Download macOS OTA artifact | |
| if: ${{ inputs.mac_run_id != '' || inputs.run_id != '' }} | |
| uses: actions/download-artifact@v8 | |
| with: | |
| name: ota-macos | |
| path: ota-artifacts/macos | |
| run-id: ${{ inputs.mac_run_id || inputs.run_id }} | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| continue-on-error: true | |
| - name: Clone OTA repo | |
| run: | | |
| mkdir ota-repo && cd ota-repo | |
| git init | |
| git remote add origin https://x-access-token:${{ secrets.PAT }}@github.com/fagramdesktop/ota.git | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| OTA_BRANCH=$(git ls-remote --symref origin HEAD | sed -n 's#^ref: refs/heads/\([^[:space:]]*\)[[:space:]]\+HEAD$#\1#p') | |
| if [ -z "$OTA_BRANCH" ]; then | |
| OTA_BRANCH="main" | |
| fi | |
| git fetch --depth=1 origin "$OTA_BRANCH" | |
| git checkout -B "$OTA_BRANCH" FETCH_HEAD | |
| echo "OTA_BRANCH=$OTA_BRANCH" >> $GITHUB_ENV | |
| - name: Publish updates | |
| env: | |
| GH_TOKEN: ${{ secrets.PAT }} | |
| run: | | |
| WIN_FILE=$(find ota-artifacts/win64 -name "tx64upd*" | head -1) | |
| LINUX_FILE=$(find ota-artifacts/linux -name "tlinuxupd*" | head -1) | |
| MAC_FILE=$(find ota-artifacts/macos -name "tmacupd*" 2>/dev/null | head -1 || true) | |
| if [ -z "$WIN_FILE" ]; then | |
| echo "Error: Windows OTA file not found" | |
| exit 1 | |
| fi | |
| if [ -z "$LINUX_FILE" ]; then | |
| echo "Error: Linux OTA file not found" | |
| exit 1 | |
| fi | |
| cp "$WIN_FILE" ota-repo/ | |
| cp "$LINUX_FILE" ota-repo/ | |
| [ -n "$MAC_FILE" ] && cp "$MAC_FILE" ota-repo/ | |
| WIN_NAME=$(basename "$WIN_FILE") | |
| LINUX_NAME=$(basename "$LINUX_FILE") | |
| MAC_NAME=$([ -n "$MAC_FILE" ] && basename "$MAC_FILE" || true) | |
| CHANNEL="stable" | |
| if [ "$IS_BETA" = "1" ]; then | |
| CHANNEL="beta" | |
| fi | |
| RELEASE_REPO="fagramdesktop/ota" | |
| RELEASE_TAG="ota-v${APP_VERSION}" | |
| if [ "$CHANNEL" = "beta" ]; then | |
| RELEASE_TAG="${RELEASE_TAG}-beta" | |
| fi | |
| if ! gh release view "$RELEASE_TAG" --repo "$RELEASE_REPO" >/dev/null 2>&1; then | |
| gh release create "$RELEASE_TAG" \ | |
| --repo "$RELEASE_REPO" \ | |
| --title "OTA ${APP_VERSION} (${CHANNEL})" \ | |
| --notes "Automated OTA artifacts for version ${APP_VERSION} (${CHANNEL})." | |
| fi | |
| if [ -n "$MAC_FILE" ]; then | |
| gh release upload "$RELEASE_TAG" \ | |
| "$WIN_FILE" \ | |
| "$LINUX_FILE" \ | |
| "$MAC_FILE" \ | |
| --repo "$RELEASE_REPO" \ | |
| --clobber | |
| else | |
| gh release upload "$RELEASE_TAG" \ | |
| "$WIN_FILE" \ | |
| "$LINUX_FILE" \ | |
| --repo "$RELEASE_REPO" \ | |
| --clobber | |
| fi | |
| cd ota-repo | |
| export APP_VERSION CHANNEL RELEASE_TAG WIN_NAME LINUX_NAME MAC_NAME | |
| python3 - <<'PY' | |
| import json | |
| import os | |
| from pathlib import Path | |
| manifest_path = 'current4' | |
| version = os.environ['APP_VERSION'] | |
| channel = os.environ['CHANNEL'] | |
| release_tag = os.environ['RELEASE_TAG'] | |
| win_name = os.environ['WIN_NAME'] | |
| linux_name = os.environ['LINUX_NAME'] | |
| mac_name = os.environ.get('MAC_NAME', '') | |
| base = f"https://github.com/fagramdesktop/ota/releases/download/{release_tag}" | |
| manifest = {} | |
| existing = Path('current4') | |
| if existing.exists(): | |
| try: | |
| loaded = json.loads(existing.read_text()) | |
| if isinstance(loaded, dict): | |
| manifest = loaded | |
| except Exception: | |
| manifest = {} | |
| manifest.setdefault('win64', {})[channel] = { | |
| 'released': version, | |
| 'link': f'{base}/{win_name}', | |
| } | |
| manifest.setdefault('linux', {})[channel] = { | |
| 'released': version, | |
| 'link': f'{base}/{linux_name}', | |
| } | |
| if mac_name: | |
| mac_entry = { | |
| 'released': version, | |
| 'link': f'{base}/{mac_name}', | |
| } | |
| manifest.setdefault('mac', {})[channel] = mac_entry | |
| manifest.setdefault('armac', {})[channel] = dict(mac_entry) | |
| with open(manifest_path, 'w') as f: | |
| json.dump(manifest, f, indent=2, sort_keys=True) | |
| f.write('\n') | |
| PY | |
| git add current4 | |
| if git diff --cached --quiet; then | |
| echo "No manifest changes to commit." | |
| else | |
| git commit -m "Update OTA manifest for ${APP_VERSION} (${CHANNEL})" | |
| git push origin "$OTA_BRANCH" | |
| fi | |
| - name: Summary | |
| run: | | |
| RELEASE_TAG="ota-v${APP_VERSION}" | |
| if [ "$IS_BETA" = "1" ]; then | |
| RELEASE_TAG="${RELEASE_TAG}-beta" | |
| fi | |
| echo "### OTA Update Published" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version:** ${APP_VERSION}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Release tag:** ${RELEASE_TAG}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Windows:** tx64upd${APP_VERSION}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Linux:** tlinuxupd${APP_VERSION}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **macOS:** tmacupd${APP_VERSION}" >> $GITHUB_STEP_SUMMARY |