Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions .github/workflows/app-store.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
name: App Store Connect

on:
workflow_dispatch:
inputs:
version:
description: Formal version to validate (defaults to the workspace version); does not upload
required: false
default: ""
type: string
workflow_call:
inputs:
version:
required: true
type: string

permissions:
contents: read

jobs:
upload:
runs-on: xcode-27
timeout-minutes: 120
concurrency:
group: app-store-${{ inputs.version || github.ref_name }}
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
APP_STORE_APP_IDENTITY: ${{ vars.APP_STORE_APP_IDENTITY }}
APP_STORE_INSTALLER_IDENTITY: ${{ vars.APP_STORE_INSTALLER_IDENTITY }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/macos-sdk
id: macos-sdk
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Validate App Store configuration
env:
APP_STORE_CERTIFICATE: ${{ secrets.APP_STORE_CERTIFICATE }}
APP_STORE_CERTIFICATE_PASSWORD: ${{ secrets.APP_STORE_CERTIFICATE_PASSWORD }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
run: |
python scripts/app-store.py preflight
python - <<'PY'
import os
required = ("APP_STORE_CERTIFICATE", "APP_STORE_CERTIFICATE_PASSWORD", "APPLE_ID", "APPLE_PASSWORD")
missing = [name for name in required if not os.environ.get(name)]
if missing:
raise SystemExit("Missing GitHub Secrets: " + ", ".join(missing))
with open(os.environ["GITHUB_ENV"], "a") as output:
output.write("APP_STORE_KEYCHAIN=" + os.environ["RUNNER_TEMP"] + "/beacon-app-store.keychain-db\n")
PY
- name: Validate App Store Connect authentication
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
run: xcrun altool --list-providers --username "$APPLE_ID" --app-password '@env:APPLE_PASSWORD' > /dev/null
- name: Apply release version
id: version
env:
RELEASE_VERSION: ${{ inputs.version }}
# Encode the attempt too, so an upload rerun never reuses a build number.
run: |
test "$GITHUB_RUN_ATTEMPT" -lt 100
export GITHUB_RUN_NUMBER=$((GITHUB_RUN_NUMBER * 100 + GITHUB_RUN_ATTEMPT))
if [ -z "$RELEASE_VERSION" ]; then
RELEASE_VERSION="$(python -c 'import pathlib, tomllib; print(tomllib.loads(pathlib.Path("Cargo.toml").read_text())["workspace"]["package"]["version"])')"
fi
python scripts/release.py set "$RELEASE_VERSION"
echo "version=$RELEASE_VERSION" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@1.98
with:
targets: aarch64-apple-darwin,x86_64-apple-darwin
- uses: Swatinem/rust-cache@v2
with:
key: app-store${{ steps.macos-sdk.outputs.cache-suffix }}
- name: Install cargo-packager
run: |
if ! cargo packager --version 2>/dev/null | grep -q '0.11.8'; then
cargo install cargo-packager --version 0.11.8 --locked --force
fi
- name: Build sandboxed universal application
run: |
cargo build --locked --release -p beacon --features app-store --target aarch64-apple-darwin
cargo build --locked --release -p beacon --features app-store --target x86_64-apple-darwin
python scripts/check-macos-sdk.py target/aarch64-apple-darwin/release/beacon --sdk-version "$BEACON_MACOS_SDK_VERSION"
python scripts/check-macos-sdk.py target/x86_64-apple-darwin/release/beacon --sdk-version "$BEACON_MACOS_SDK_VERSION"
mkdir -p target/app-store
lipo -create target/aarch64-apple-darwin/release/beacon target/x86_64-apple-darwin/release/beacon -output target/app-store/beacon
- name: Import App Store signing identities
env:
APP_STORE_CERTIFICATE: ${{ secrets.APP_STORE_CERTIFICATE }}
APP_STORE_CERTIFICATE_PASSWORD: ${{ secrets.APP_STORE_CERTIFICATE_PASSWORD }}
APP_STORE_PROVISIONING_PROFILE: ${{ secrets.APP_STORE_PROVISIONING_PROFILE }}
run: |
python - <<'PY'
import base64, json, os, secrets, shlex, subprocess
from pathlib import Path
def run(*args, **kwargs):
return subprocess.run(args, check=True, **kwargs)
directory = Path(os.environ["RUNNER_TEMP"])
previous = shlex.split(run("security", "list-keychains", "-d", "user", capture_output=True, text=True).stdout)
(directory / "beacon-keychains.json").write_text(json.dumps(previous))
password = secrets.token_urlsafe(32)
print("::add-mask::" + password)
keychain = os.environ["APP_STORE_KEYCHAIN"]
certificate = directory / "beacon-app-store.p12"
certificate.write_bytes(base64.b64decode(os.environ["APP_STORE_CERTIFICATE"], validate=True))
certificate.chmod(0o600)
try:
run("security", "create-keychain", "-p", password, keychain)
run("security", "set-keychain-settings", "-lut", "21600", keychain)
run("security", "unlock-keychain", "-p", password, keychain)
run("security", "list-keychains", "-d", "user", "-s", keychain, *previous)
run("security", "import", str(certificate), "-k", keychain, "-P", os.environ["APP_STORE_CERTIFICATE_PASSWORD"], "-T", "/usr/bin/codesign", "-T", "/usr/bin/productbuild", stdout=subprocess.DEVNULL)
run("security", "set-key-partition-list", "-S", "apple-tool:,apple:,codesign:", "-s", "-k", password, keychain, stdout=subprocess.DEVNULL)
identities = run("security", "find-identity", "-v", keychain, capture_output=True, text=True).stdout
for name in ("APP_STORE_APP_IDENTITY", "APP_STORE_INSTALLER_IDENTITY"):
if '"' + os.environ[name] + '"' not in identities:
raise SystemExit(name + " is missing from the imported p12")
finally:
certificate.unlink(missing_ok=True)
profile = os.environ.get("APP_STORE_PROVISIONING_PROFILE")
if profile:
(directory / "beacon-app-store.provisionprofile").write_bytes(base64.b64decode(profile, validate=True))
PY
- name: Sign application and installer
run: |
PROFILE_ARGS=()
if [ -f "$RUNNER_TEMP/beacon-app-store.provisionprofile" ]; then
PROFILE_ARGS=(--profile "$RUNNER_TEMP/beacon-app-store.provisionprofile")
fi
python scripts/app-store.py package --keychain "$APP_STORE_KEYCHAIN" "${PROFILE_ARGS[@]}"
- uses: actions/upload-artifact@v4
with:
name: app-store-${{ steps.version.outputs.version }}
path: target/app-store/*.pkg
if-no-files-found: error
- name: Validate package with App Store Connect
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APP_STORE_PROVIDER_ID: ${{ vars.APP_STORE_PROVIDER_ID }}
run: |
PROVIDER_ARGS=()
if [ -n "$APP_STORE_PROVIDER_ID" ]; then
PROVIDER_ARGS=(--provider-public-id "$APP_STORE_PROVIDER_ID")
fi
xcrun altool --validate-app target/app-store/*.pkg --username "$APPLE_ID" --app-password '@env:APPLE_PASSWORD' "${PROVIDER_ARGS[@]}"
- name: Upload to App Store Connect and wait for processing
if: github.event_name == 'push'
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APP_STORE_PROVIDER_ID: ${{ vars.APP_STORE_PROVIDER_ID }}
run: |
PROVIDER_ARGS=()
if [ -n "$APP_STORE_PROVIDER_ID" ]; then
PROVIDER_ARGS=(--provider-public-id "$APP_STORE_PROVIDER_ID")
fi
xcrun altool --upload-package target/app-store/*.pkg --username "$APPLE_ID" --app-password '@env:APPLE_PASSWORD' --wait "${PROVIDER_ARGS[@]}"
- name: Record validation result
if: github.event_name == 'workflow_dispatch'
env:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: echo "Validated the signed universal package for Beacon $RELEASE_VERSION with App Store Connect. No build was uploaded." >> "$GITHUB_STEP_SUMMARY"
- name: Remove temporary signing material
if: always()
run: |
python - <<'PY'
import json, os, subprocess
from pathlib import Path
directory = Path(os.environ["RUNNER_TEMP"])
previous = directory / "beacon-keychains.json"
if previous.exists():
subprocess.run(["security", "list-keychains", "-d", "user", "-s", *json.loads(previous.read_text())], check=True)
previous.unlink()
keychain = directory / "beacon-app-store.keychain-db"
if keychain.exists():
subprocess.run(["security", "delete-keychain", str(keychain)], check=True)
for name in ("beacon-app-store.p12", "beacon-app-store.provisionprofile"):
(directory / name).unlink(missing_ok=True)
PY
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,9 @@ jobs:
# whole test suite runs on a CI runner without a display.
- name: Test
run: cargo --config .github/ci-profile.toml test --locked --workspace --target ${{ matrix.target }}

- name: Check Mac App Store variant
if: runner.os == 'macOS'
run: |
cargo --config .github/ci-profile.toml clippy --locked -p beacon --features app-store --target ${{ matrix.target }}
cargo --config .github/ci-profile.toml test --locked -p beacon-updater --features app-store --target ${{ matrix.target }}
8 changes: 8 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ jobs:
target/${{ matrix.target }}/release/*.sig
if-no-files-found: error

app-store:
if: needs.prepare.outputs.publish == 'true' && vars.APP_STORE_ENABLED == 'true'
needs: [prepare, release]
uses: ./.github/workflows/app-store.yml
with:
version: ${{ needs.prepare.outputs.version }}
secrets: inherit

release:
if: needs.prepare.outputs.publish == 'true'
needs: [prepare, checks, package]
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions assets/packaging/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
<string>1.4.59</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>NSHumanReadableCopyright</key>
<string>© 2026 Beacon Team</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions assets/packaging/app-store.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.bookmarks.app-scope</key>
<true/>
</dict>
</plist>
5 changes: 5 additions & 0 deletions crates/beacon-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ rust-version.workspace = true
license.workspace = true

[features]
app-store = ["beacon-updater/app-store", "dep:objc2", "dep:objc2-foundation"]
ui-tests = ["gpui-kit/test-support", "beacon-kube/test-support"]

[dependencies]
Expand Down Expand Up @@ -39,3 +40,7 @@ roxmltree = "=0.21.1"

[build-dependencies]
serde_json.workspace = true

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = { version = "0.6.3", optional = true }
objc2-foundation = { version = "0.3.2", default-features = false, features = ["std", "NSArray", "NSData", "NSError", "NSString", "NSURL"], optional = true }
8 changes: 8 additions & 0 deletions crates/beacon-ui/locales/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1099,5 +1099,13 @@
"settings.add_file": {
"en": "Add file",
"zh-CN": "添加文件"
},
"settings.app_store_updates": {
"en": "Updates are managed by the Mac App Store.",
"zh-CN": "更新由 Mac App Store 管理。"
},
"settings.open_app_store": {
"en": "Open App Store",
"zh-CN": "打开 App Store"
}
}
122 changes: 122 additions & 0 deletions crates/beacon-ui/src/app_store.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//! Keep user-selected kubeconfig locations accessible across sandboxed launches.
use gpui_kit::{App, Global};
use objc2::{rc::Retained, runtime::Bool};
use objc2_foundation::{
NSData, NSString, NSURL, NSURLBookmarkCreationOptions, NSURLBookmarkResolutionOptions,
};
use std::{collections::BTreeMap, path::PathBuf};

struct Access(Retained<NSURL>);
impl Drop for Access {
fn drop(&mut self) {
// SAFETY: Access is constructed only after a successful start call.
unsafe { self.0.stopAccessingSecurityScopedResource() };
}
}
struct FileAccess {
path: PathBuf,
bookmarks: BTreeMap<PathBuf, Vec<u8>>,
active: BTreeMap<PathBuf, Access>,
}
impl Global for FileAccess {}

fn bookmark(url: &NSURL) -> Result<Vec<u8>, String> {
url.bookmarkDataWithOptions_includingResourceValuesForKeys_relativeToURL_error(
NSURLBookmarkCreationOptions::WithSecurityScope,
None,
None,
)
.map(|data| data.to_vec())
.map_err(|error| format!("Could not save file access. Choose the location again. {error}"))
}

fn resolve(bytes: &[u8]) -> Result<(Access, bool), String> {
let mut stale = Bool::NO;
// SAFETY: stale points to a live Bool for the duration of this call.
let url = unsafe {
NSURL::URLByResolvingBookmarkData_options_relativeToURL_bookmarkDataIsStale_error(
&NSData::with_bytes(bytes),
NSURLBookmarkResolutionOptions::WithSecurityScope
| NSURLBookmarkResolutionOptions::WithoutUI,
None,
&mut stale,
)
}
.map_err(|error| {
format!("Could not restore file access. Choose the location again. {error}")
})?;
// SAFETY: the URL was resolved with security scope and remains retained.
if !unsafe { url.startAccessingSecurityScopedResource() } {
return Err("Could not access the selected location. Choose it again.".into());
}
Ok((Access(url), stale.as_bool()))
}

pub(crate) fn init(cx: &mut App) {
let path = crate::settings::store(cx)
.read(cx)
.directory
.join("file-access.json");
let bookmarks = match std::fs::read(&path) {
Ok(data) => serde_json::from_slice::<BTreeMap<PathBuf, Vec<u8>>>(&data)
.unwrap_or_else(|error| {
tracing::warn!(%error, "could not read saved file access; reselect kubeconfig locations");
BTreeMap::new()
}),
Err(error) => {
if error.kind() != std::io::ErrorKind::NotFound {
tracing::warn!(%error, "could not read saved file access");
}
BTreeMap::new()
}
};
let mut state = FileAccess {
path,
bookmarks,
active: BTreeMap::new(),
};
let mut refreshed = false;
for (path, bytes) in &mut state.bookmarks {
match resolve(bytes) {
Ok((access, stale)) => {
if stale && let Ok(data) = bookmark(&access.0) {
*bytes = data;
refreshed = true;
}
state.active.insert(path.clone(), access);
}
Err(error) => {
tracing::warn!(%error, path = %path.display(), "file access expired; reselect the kubeconfig location")
}
}
}
if refreshed && let Err(error) = state.save() {
tracing::warn!(%error, "could not refresh saved file access");
}
cx.set_global(state);
}

impl FileAccess {
fn save(&self) -> Result<(), String> {
std::fs::create_dir_all(self.path.parent().ok_or("No settings directory.")?)
.map_err(|error| error.to_string())?;
crate::settings::atomic_write(
&self.path,
&serde_json::to_vec(&self.bookmarks).map_err(|error| error.to_string())?,
)
}
}

/// Call immediately after the native Open panel grants access to these paths.
pub(crate) fn remember(paths: &[PathBuf], cx: &mut App) -> Result<(), String> {
let state = cx.global_mut::<FileAccess>();
for path in paths {
let url = NSURL::fileURLWithPath(&NSString::from_str(&path.to_string_lossy()));
let data = bookmark(&url)?;
// GPUI returns paths. Resolve the bookmark to regain a scoped NSURL.
let (access, _) = resolve(&data)?;
state.bookmarks.insert(path.clone(), data);
state.active.insert(path.clone(), access);
}
state.save()
}
Loading
Loading