diff --git a/.github/actions/setup-version/action.yml b/.github/actions/setup-version/action.yml index a9b040ec1..c790bdd7d 100644 --- a/.github/actions/setup-version/action.yml +++ b/.github/actions/setup-version/action.yml @@ -17,7 +17,13 @@ runs: shell: bash run: | if [ "${{ github.ref_type }}" == "tag" ]; then - APP_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//') + # Handle new tag format: desktop/v1.2.3 or mobile/v1.2.3 + if [[ "${{ github.ref_name }}" =~ ^(desktop|mobile)/v(.*)$ ]]; then + APP_VERSION="${BASH_REMATCH[2]}" + else + # Fallback for old format: v1.2.3 + APP_VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//') + fi else if [ "${{ inputs.type }}" == "desktop" ]; then APP_VERSION=$(node -p "require('./apps/desktop/package.json').version") diff --git a/.github/scripts/extract-release-info.mjs b/.github/scripts/extract-release-info.mjs new file mode 100755 index 000000000..17a24fc28 --- /dev/null +++ b/.github/scripts/extract-release-info.mjs @@ -0,0 +1,111 @@ +#!/usr/bin/env node + +/** + * Extract release version and platform information from git commit messages + * Used by GitHub Actions to determine if a release tag should be created + */ + +import { execSync } from "node:child_process" +import { appendFileSync } from "node:fs" + +// Configuration +const RELEASE_PATTERNS = { + desktop: /release\(desktop\): Release (v\d+\.\d+\.\d+(-[0-9A-Za-z-.]+)?)/, + mobile: /release\(mobile\): Release (v\d+\.\d+\.\d+(-[0-9A-Za-z-.]+)?)/, +} + +const EXIT_CODES = { + SUCCESS: 0, + NO_RELEASE_FOUND: 1, + GIT_ERROR: 2, + ENV_ERROR: 3, +} + +/** + * Write environment variable to GitHub Environment + * @param {string} key - Environment variable key + * @param {string} value - Environment variable value + */ +function setGitHubEnv(key, value) { + try { + if (!process.env.GITHUB_ENV) { + throw new Error("GITHUB_ENV not set - not running in GitHub Actions") + } + appendFileSync(process.env.GITHUB_ENV, `${key}=${value}\n`) + } catch (error) { + console.error(`Failed to set environment variable ${key}:`, error.message) + process.exit(EXIT_CODES.ENV_ERROR) + } +} + +/** + * Get the latest commit message + * @returns {string} Latest commit message + */ +function getLatestCommitMessage() { + try { + return execSync("git log -1 --pretty=%B", { encoding: "utf-8" }).toString().trim() + } catch (error) { + console.error("Failed to get git commit message:", error.message) + process.exit(EXIT_CODES.GIT_ERROR) + } +} + +/** + * Extract release information from commit message + * @param {string} commitMessage - Git commit message + * @returns {Object|null} Release information or null if no release found + */ +function extractReleaseInfo(commitMessage) { + for (const [platform, regex] of Object.entries(RELEASE_PATTERNS)) { + const match = commitMessage.match(regex) + if (match) { + const version = match[1] + const tagName = `${platform}/${version}` + + return { + platform, + version, + tagName, + } + } + } + + return null +} + +/** + * Main execution function + */ +function main() { + try { + console.info("Extracting release information from commit message...") + + const commitMessage = getLatestCommitMessage() + console.info(`Commit message: ${commitMessage}`) + + const releaseInfo = extractReleaseInfo(commitMessage) + + if (!releaseInfo) { + console.info("No desktop or mobile release found in commit message.") + process.exit(EXIT_CODES.NO_RELEASE_FOUND) + } + + const { platform, version, tagName } = releaseInfo + + // Set GitHub Environment variables + setGitHubEnv("tag_version", tagName) + setGitHubEnv("platform", platform) + setGitHubEnv("version", version) + + console.info(`Found ${platform} release: ${version}`) + console.info(`Tag will be created: ${tagName}`) + + process.exit(EXIT_CODES.SUCCESS) + } catch (error) { + console.error("Unexpected error:", error.message) + process.exit(EXIT_CODES.GIT_ERROR) + } +} + +main() diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index c102ba4a7..b8e3126e7 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -92,16 +92,15 @@ jobs: id: version uses: ./.github/actions/setup-version with: - # We don't want to create a new release for mobile - type: "desktop" + type: "mobile" - name: Create Release Draft if: github.event.inputs.release == 'true' uses: softprops/action-gh-release@v2 with: - name: v${{ steps.version.outputs.APP_VERSION }} + name: Mobile v${{ steps.version.outputs.APP_VERSION }} draft: false prerelease: true - tag_name: v${{ steps.version.outputs.APP_VERSION }} + tag_name: mobile/v${{ steps.version.outputs.APP_VERSION }} # .aab cannot be installed directly on your Android Emulator or device. files: ${{ github.workspace }}/build.apk diff --git a/.github/workflows/build-desktop.yml b/.github/workflows/build-desktop.yml index d13502e41..366e458a8 100644 --- a/.github/workflows/build-desktop.yml +++ b/.github/workflows/build-desktop.yml @@ -297,10 +297,10 @@ jobs: if: env.RELEASE == 'true' uses: softprops/action-gh-release@v2 with: - name: v${{ steps.version.outputs.APP_VERSION }} + name: Desktop v${{ steps.version.outputs.APP_VERSION }} draft: false prerelease: true - tag_name: v${{ steps.version.outputs.APP_VERSION }} + tag_name: desktop/v${{ steps.version.outputs.APP_VERSION }} files: | apps/desktop/out/make/**/Folo-*.dmg apps/desktop/out/make/**/Folo-*.zip diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index 24334ea0b..43b76b75e 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -1,4 +1,4 @@ -name: Build iOS +name: 🍎 Build iOS on: push: diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index b2df7f891..57af2153c 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -4,55 +4,95 @@ on: push: branches: - main + env: NODE_OPTIONS: --max-old-space-size=8192 + jobs: create_tag: + name: Create Release Tag runs-on: ubuntu-latest + outputs: + tag_version: ${{ env.tag_version }} + platform: ${{ env.platform }} + version: ${{ env.version }} + steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Use Node.js + with: + fetch-depth: 1 + + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 22 + cache: "npm" - - name: Extract SemVer using Node.js - id: extract_semver - run: | - node -e ' - const execSync = require("child_process").execSync; - const fs = require("fs"); - const commitMessage = execSync("git log -1 --pretty=%B").toString("utf-8"); - const semverRegex = /release\(desktop\): Release (v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-.]+)?)/; - const match = commitMessage.match(semverRegex); - if (match) { - fs.appendFileSync(process.env.GITHUB_ENV, `tag_version=${match[1]}\n`); - } else { - console.log("No SemVer found in commit body."); - process.exit(0); - } - ' + - name: Make script executable + run: chmod +x .github/scripts/extract-release-info.js - - name: Create a new tag - if: ${{ env.tag_version }} - run: | - git tag ${{ env.tag_version }} - git push origin ${{ env.tag_version }} - - name: Trigger Build Desktop Workflow - if: ${{ env.tag_version }} - run: | - curl -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github+json" \ - https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-desktop.yml/dispatches \ - -d '{"ref":"main", "inputs": {"tag_version": "true"}}' + - name: Extract release information + id: extract_info + run: ./.github/scripts/extract-release-info.mjs + continue-on-error: false - - name: Trigger Build Android Workflow - if: ${{ env.tag_version }} + - name: Validate git configuration + if: env.tag_version run: | - curl -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github+json" \ - https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-android.yml/dispatches \ - -d '{"ref":"main", "inputs": {"release": "true"}}' + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + + - name: Create and push tag + if: env.tag_version + run: | + echo "Creating tag: ${{ env.tag_version }}" + if git rev-parse "${{ env.tag_version }}" >/dev/null 2>&1; then + echo "Tag ${{ env.tag_version }} already exists, skipping creation" + exit 0 + fi + + git tag "${{ env.tag_version }}" + git push origin "${{ env.tag_version }}" + echo "Successfully created and pushed tag: ${{ env.tag_version }}" + + trigger_builds: + name: Trigger Platform Builds + needs: create_tag + if: needs.create_tag.outputs.tag_version + runs-on: ubuntu-latest + + steps: + - name: Trigger Desktop Build + if: needs.create_tag.outputs.platform == 'desktop' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const response = await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'build-desktop.yml', + ref: 'main', + inputs: { + tag_version: 'true' + } + }); + console.log('Desktop build triggered successfully'); + + - name: Trigger Mobile Build + if: needs.create_tag.outputs.platform == 'mobile' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const response = await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'build-android.yml', + ref: 'main', + inputs: { + release: 'true' + } + }); + console.log('Mobile build triggered successfully'); diff --git a/apps/desktop/layer/main/src/updater/custom-github-provider.ts b/apps/desktop/layer/main/src/updater/custom-github-provider.ts index 567b9dfb0..04d5eca6b 100644 --- a/apps/desktop/layer/main/src/updater/custom-github-provider.ts +++ b/apps/desktop/layer/main/src/updater/custom-github-provider.ts @@ -89,8 +89,19 @@ export class CustomGitHubProvider extends BaseGitHubProvider { // This Release's Tag const hrefTag = hrefElement[1]! // Get Channel from this release's tag - // If it is null, we believe it is stable version - const hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || "stable" + // Handle new format: desktop/v1.2.3 or mobile/v1.2.3 + let hrefChannel = "stable" + if (hrefTag.startsWith("desktop/")) { + // For desktop tags, extract the version and check if it's a prerelease + const version = hrefTag.replace("desktop/", "") + hrefChannel = (semver.prerelease(version)?.[0] as string) || "stable" + } else if (hrefTag.startsWith("mobile/")) { + // Skip mobile releases for desktop updater + continue + } else { + // Legacy format: check for prerelease directly + hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || "stable" + } let isNextPreRelease = false if (releaseTag) { @@ -210,7 +221,21 @@ export class CustomGitHubProvider extends BaseGitHubProvider { } const releaseTag = release.tag_name - const releaseChannel = (semver.prerelease(releaseTag)?.[0] as string) || "stable" + + // Handle new format: desktop/v1.2.3 or mobile/v1.2.3 + let releaseChannel = "stable" + if (releaseTag.startsWith("desktop/")) { + // For desktop tags, extract the version and check if it's a prerelease + const version = releaseTag.replace("desktop/", "") + releaseChannel = (semver.prerelease(version)?.[0] as string) || "stable" + } else if (releaseTag.startsWith("mobile/")) { + // Skip mobile releases for desktop updater + continue + } else { + // Legacy format: check for prerelease directly + releaseChannel = (semver.prerelease(releaseTag)?.[0] as string) || "stable" + } + if (releaseChannel === currentChannel) { return release.tag_name } diff --git a/apps/desktop/layer/main/src/updater/hot-updater.ts b/apps/desktop/layer/main/src/updater/hot-updater.ts index 8703209c2..3d3de2919 100644 --- a/apps/desktop/layer/main/src/updater/hot-updater.ts +++ b/apps/desktop/layer/main/src/updater/hot-updater.ts @@ -25,10 +25,21 @@ const releasesUrl = `${url}/releases` const releaseApiUrl = `https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases` const getLatestReleaseTag = async () => { - const res = await fetch(`${releaseApiUrl}/latest`) - const json = await res.json() + // Get all releases and filter for desktop releases only + const res = await fetch(releaseApiUrl) + const releases = await res.json() - return json.tag_name + // Filter for desktop releases and find the latest one + const desktopReleases = releases.filter( + (release: any) => release.tag_name.startsWith("desktop/") && !release.draft, + ) + + if (desktopReleases.length === 0) { + throw new Error("No desktop releases found") + } + + // Return the most recent desktop release (GitHub orders by created_at desc) + return desktopReleases[0].tag_name } const getFileDownloadUrl = async (filename: string) => {