From 031aeff0e38a96cd7254be9580af5ac9511fccdd Mon Sep 17 00:00:00 2001 From: Hironori Takahashi Date: Wed, 2 Dec 2026 19:27:14 +0900 Subject: [PATCH 1/3] feat: add personal sandbox scripts (init-sandbox.sh, sandbox-push.sh) --- .gitignore | 1 + .templatesyncignore | 2 + scripts/init-sandbox.sh | 133 ++++++++++++++++++++++++++++++++++++++++ scripts/sandbox-push.sh | 54 ++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100755 scripts/init-sandbox.sh create mode 100755 scripts/sandbox-push.sh diff --git a/.gitignore b/.gitignore index 6685d9a..ee776a1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ build/ .clasp.json .clasp-dev.json .clasp-prod.json +.clasp-sandbox.json *.tgz .vscode/ coverage/ diff --git a/.templatesyncignore b/.templatesyncignore index dc169a2..83ae03e 100644 --- a/.templatesyncignore +++ b/.templatesyncignore @@ -32,6 +32,8 @@ # Scripts :!scripts/init.sh +:!scripts/init-sandbox.sh +:!scripts/sandbox-push.sh :!scripts/set-properties.sh :!scripts/gcp-get-secret.sh :!scripts/fetch-clasp-credentials.sh diff --git a/scripts/init-sandbox.sh b/scripts/init-sandbox.sh new file mode 100755 index 0000000..e64bde6 --- /dev/null +++ b/scripts/init-sandbox.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Apps Script Fleet — Personal Sandbox Init +# +# Creates a personal Apps Script project under YOUR OWN Google account and +# writes .clasp-sandbox.json (gitignored). For organizations running CI-only +# mode, this is the standard way to iterate locally without the shared deploy +# identity. It does NOT set CI/CD variables and does NOT bind a GCP project. +# +# Prerequisites: +# - clasp authenticated with your PERSONAL account: +# pnpm exec clasp login +# - Node.js + pnpm installed +# +# Usage: +# ./scripts/init-sandbox.sh [--title "Project Name"] [--type standalone|sheets|docs|slides|forms] +# +# Optional guard: +# FLEET_DEPLOY_ACCOUNT= +# When set, this script refuses to run while clasp is authenticated as the +# shared deploy account (prevents sandbox projects being created under the +# shared identity). + +TITLE="" +SCRIPT_TYPE="standalone" +VALID_TYPES="standalone sheets docs slides forms" + +while [[ $# -gt 0 ]]; do + case $1 in + --title) + TITLE="$2" + shift 2 + ;; + --type) + SCRIPT_TYPE="$2" + shift 2 + ;; + *) + echo "Unknown option: $1" >&2 + exit 1 + ;; + esac +done + +die() { + echo "Error: $*" >&2 + exit 1 +} + +require_cmd() { + command -v "$1" >/dev/null 2>&1 || die "$1 is required but not installed." +} + +validate_type() { + local type="$1" + for valid in $VALID_TYPES; do + [[ "$type" == "$valid" ]] && return 0 + done + die "Invalid --type '${type}'. Must be one of: ${VALID_TYPES}" +} + +json_value() { + node -e "process.stdout.write(String(JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))[process.argv[2]]))" "$1" "$2" +} + +lower() { + tr '[:upper:]' '[:lower:]' +} + +guard_not_shared_account() { + [[ -n "${FLEET_DEPLOY_ACCOUNT:-}" ]] || return 0 + + local info email + if ! info=$(pnpm exec clasp show-authorized-user --json 2>/dev/null); then + echo "Warning: could not determine the current clasp account; FLEET_DEPLOY_ACCOUNT guard skipped." >&2 + return 0 + fi + email=$(printf '%s' "$info" | node -e "const d=JSON.parse(require('fs').readFileSync(0,'utf8'));process.stdout.write(String(d.email||''))") + if [[ -z "$email" ]]; then + echo "Warning: clasp did not report an account email; FLEET_DEPLOY_ACCOUNT guard skipped." >&2 + return 0 + fi + if [[ "$(printf '%s' "$email" | lower)" == "$(printf '%s' "$FLEET_DEPLOY_ACCOUNT" | lower)" ]]; then + die "clasp is authenticated as the shared deploy account (${email}). +Sandbox commands must use your PERSONAL account. Re-authenticate with: + pnpm exec clasp login" + fi +} + +echo "=== Apps Script Fleet — Personal Sandbox Init ===" +echo "" + +require_cmd pnpm +require_cmd node +validate_type "$SCRIPT_TYPE" +[[ -f "$HOME/.clasprc.json" ]] || die "$HOME/.clasprc.json not found. Authenticate with your personal account: pnpm exec clasp login" +[[ -f .clasp-sandbox.json ]] && die ".clasp-sandbox.json already exists. Remove it first if you want to create a new sandbox project." + +guard_not_shared_account + +if [[ -z "$TITLE" ]]; then + TITLE=$(basename "$(pwd)") +fi + +echo "Title: ${TITLE} (sandbox)" +echo "Type: ${SCRIPT_TYPE}" +echo "" + +echo "Creating personal Apps Script project..." +rm -f .clasp.json +pnpm exec clasp create --title "${TITLE} (sandbox)" --type "$SCRIPT_TYPE" --rootDir dist 2>&1 + +[[ -f .clasp.json ]] || die "clasp create failed — .clasp.json not generated." +mv .clasp.json .clasp-sandbox.json + +SCRIPT_ID=$(json_value .clasp-sandbox.json scriptId) +echo " Script ID: ${SCRIPT_ID}" + +mkdir -p dist +cp appsscript.json dist/appsscript.json +echo " Pushing initial manifest..." +pnpm exec clasp -P .clasp-sandbox.json push -f 2>&1 + +echo "" +echo "Done! Personal sandbox is ready (.clasp-sandbox.json, gitignored)." +echo "" +echo " sandbox script: https://script.google.com/d/${SCRIPT_ID}/edit" +echo "" +echo " Push your code: pnpm run sandbox" +echo " Open the editor: pnpm exec clasp -P .clasp-sandbox.json open-script" +echo " Run a function: pnpm exec clasp -P .clasp-sandbox.json run " +echo " Tail logs: pnpm exec clasp -P .clasp-sandbox.json logs" diff --git a/scripts/sandbox-push.sh b/scripts/sandbox-push.sh new file mode 100755 index 0000000..211dd54 --- /dev/null +++ b/scripts/sandbox-push.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Apps Script Fleet — Sandbox Push +# +# Builds and pushes to YOUR personal sandbox project (.clasp-sandbox.json, +# created by ./scripts/init-sandbox.sh). Never touches the shared dev/prod +# projects and never reads .clasp-dev.json / .clasp-prod.json. +# +# Usage: +# pnpm run sandbox (wired in package.json) +# ./scripts/sandbox-push.sh +# +# Optional guard: +# FLEET_DEPLOY_ACCOUNT= +# When set, the push stops if clasp is authenticated as the shared deploy +# account, so experimental code never runs with the shared identity. + +die() { + echo "Error: $*" >&2 + exit 1 +} + +lower() { + tr '[:upper:]' '[:lower:]' +} + +guard_not_shared_account() { + [[ -n "${FLEET_DEPLOY_ACCOUNT:-}" ]] || return 0 + + local info email + if ! info=$(pnpm exec clasp show-authorized-user --json 2>/dev/null); then + echo "Warning: could not determine the current clasp account; FLEET_DEPLOY_ACCOUNT guard skipped." >&2 + return 0 + fi + email=$(printf '%s' "$info" | node -e "const d=JSON.parse(require('fs').readFileSync(0,'utf8'));process.stdout.write(String(d.email||''))") + if [[ -z "$email" ]]; then + echo "Warning: clasp did not report an account email; FLEET_DEPLOY_ACCOUNT guard skipped." >&2 + return 0 + fi + if [[ "$(printf '%s' "$email" | lower)" == "$(printf '%s' "$FLEET_DEPLOY_ACCOUNT" | lower)" ]]; then + die "clasp is authenticated as the shared deploy account (${email}). +Sandbox commands must use your PERSONAL account. Re-authenticate with: + pnpm exec clasp login" + fi +} + +[[ -f .clasp-sandbox.json ]] || die ".clasp-sandbox.json not found. Create your sandbox first: ./scripts/init-sandbox.sh" + +guard_not_shared_account + +pnpm run check +pnpm run build +pnpm exec clasp -P .clasp-sandbox.json push -f From 850639c3c7ea0afbc6ede61d82fb992237577481 Mon Sep 17 00:00:00 2001 From: Hironori Takahashi Date: Wed, 2 Dec 2026 19:27:14 +0900 Subject: [PATCH 2/3] feat: wire pnpm run sandbox to sandbox-push.sh --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 544f0bb..f72cfe4 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lint:css": "stylelint '**/*.{css,scss,html}' --allow-empty-input", "lint:html": "htmlhint --ignore 'coverage/**,dist/**' '**/*.html' || true", "prepare": "husky", + "sandbox": "./scripts/sandbox-push.sh", "test": "jest test/ --passWithNoTests --detectOpenHandles --coverage", "typecheck": "tsc --noEmit" }, From 2be615931e749d027995d0fe88fd243ccfe1912d Mon Sep 17 00:00:00 2001 From: Hironori Takahashi Date: Wed, 2 Dec 2026 19:27:14 +0900 Subject: [PATCH 3/3] docs: document personal sandbox for CI-only mode in README --- README.ja.md | 20 ++++++++++++++++++++ README.md | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/README.ja.md b/README.ja.md index 5cf3dc9..d069b2e 100644 --- a/README.ja.md +++ b/README.ja.md @@ -167,6 +167,26 @@ pnpm run check # lint + 型チェック + テスト clasp の認証と dev へのデプロイは上記セットアップガイドを参照してください。 +#### 個人 sandbox(CI-only モード) + +共有デプロイ ID を CI/CD 専用に制限する組織(「CI-only モード」)では、開発者は自分の Google アカウント配下の **個人 sandbox** プロジェクトで手元開発を行います: + +```bash +pnpm exec clasp login # 自分のアカウントで認証 +./scripts/init-sandbox.sh # sandbox プロジェクトを作成(.clasp-sandbox.json、gitignore 済み) +pnpm run sandbox # check + build + 自分の sandbox に push +``` + +`clasp` のサブコマンドは `-P` で sandbox に対して実行できます: + +```bash +pnpm exec clasp -P .clasp-sandbox.json open-script +pnpm exec clasp -P .clasp-sandbox.json run +pnpm exec clasp -P .clasp-sandbox.json logs +``` + +sandbox は個人の権限で実行されます。デプロイ ID との権限差は再現しないため、最終確認は dev 環境(`dev` への merge)で行ってください。環境変数 `FLEET_DEPLOY_ACCOUNT=<共有アカウントの email>` を設定すると、clasp が共有デプロイアカウントで認証されている間は sandbox コマンドが停止します。 + ## CI/CD パイプライン GitHub Actions と GitLab CI の両方の設定が含まれています。push 先のプラットフォームで同じパイプラインが動きます。CI/CD 変数の設定以外の追加セットアップは不要です。 diff --git a/README.md b/README.md index 437569c..b4fdc22 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,26 @@ pnpm run check # lint + typecheck + test For clasp authentication and deploying to dev, see the setup guides above. +#### Personal Sandbox (CI-only mode) + +In organizations where the shared deploy identity is restricted to CI/CD ("CI-only mode"), developers iterate locally against a **personal sandbox** — an Apps Script project under their own Google account: + +```bash +pnpm exec clasp login # authenticate with YOUR account +./scripts/init-sandbox.sh # create the sandbox project (.clasp-sandbox.json, gitignored) +pnpm run sandbox # check + build + push to YOUR sandbox +``` + +`clasp` subcommands work against the sandbox via `-P`: + +```bash +pnpm exec clasp -P .clasp-sandbox.json open-script +pnpm exec clasp -P .clasp-sandbox.json run +pnpm exec clasp -P .clasp-sandbox.json logs +``` + +The sandbox runs with your personal permissions — it does not reproduce the deploy identity's access, so final verification still happens in the dev environment (merge to `dev`). Optionally set `FLEET_DEPLOY_ACCOUNT=` so sandbox commands refuse to run while clasp is authenticated as the shared deploy account. + ## CI/CD Pipeline Both GitHub Actions and GitLab CI configurations are included. The same pipeline runs on whichever platform you push to — no additional setup needed beyond CI/CD variables.