Skip to content

Instantly share code, notes, and snippets.

@hideokamoto
Created June 19, 2026 23:21
Show Gist options
  • Select an option

  • Save hideokamoto/ae9e3c1b3b366e3e97a1de3fd41f265d to your computer and use it in GitHub Desktop.

Select an option

Save hideokamoto/ae9e3c1b3b366e3e97a1de3fd41f265d to your computer and use it in GitHub Desktop.
setup-chunk-cli.sh
#!/bin/bash
set -euo pipefail
# 1. chunk を PATH 通過済みディレクトリに配置(.bashrc非依存)
curl -fL https://github.com/CircleCI-Public/chunk-cli/releases/download/v0.7.88/chunk-cli_Linux_x86_64.tar.gz \
| tar xz -C /tmp
install -m 0755 /tmp/chunk /usr/local/bin/chunk
chunk --version
# 2. CircleCI org id を自動導出して設定
# - CIRCLE_TOKEN は env の環境変数設定から供給される前提
# - リポジトリのオーナー名から org slug (gh/<owner>) を組み立てて照合
cd "$(git rev-parse --show-toplevel)"
OWNER=$(git remote get-url origin | sed -E 's#.*[/:]([^/]+)/[^/]+(\.git)?/?$#\1#')
ORG_ID=$(curl -fsS -H "Circle-Token: ${CIRCLE_TOKEN}" https://circleci.com/api/v2/me/collaborations \
| jq -r --arg slug "gh/${OWNER}" '.[] | select(.slug==$slug) | .id')
if [ -n "${ORG_ID}" ] && [ "${ORG_ID}" != "null" ]; then
chunk config set orgID "${ORG_ID}"
# .chunk/ は gitignore 対象外なので、ローカル限定で git 追跡から除外(誤コミット防止)
grep -qxF '.chunk/' .git/info/exclude 2>/dev/null || echo '.chunk/' >> .git/info/exclude
else
echo "WARN: org id を導出できませんでした (owner=${OWNER})。CIRCLECI_ORG_ID を手動設定してください。" >&2
fi
# 3. 確認
chunk auth status
chunk config show | grep -i orgID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment