-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·96 lines (78 loc) · 3.31 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·96 lines (78 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
# Points this example at your own bit.cloud scope.
# Usage: ./setup.sh <your-org>.<your-scope>
set -eu
PLACEHOLDER='CHANGE-ME.CHANGE-ME'
COMPONENT_DIR='components/greeting'
COMPONENT_ID='greeting'
cd "$(dirname "$0")"
SCOPE="${1:-}"
if [ -z "$SCOPE" ]; then
echo 'Error: the scope id is missing.' >&2
echo 'Usage: ./setup.sh <your-org>.<your-scope>' >&2
echo 'Example: ./setup.sh acme.shop' >&2
exit 1
fi
# A scope id has two parts and one dot. Reject every other shape.
if ! printf '%s\n' "$SCOPE" | grep -Eq '^[A-Za-z0-9][A-Za-z0-9_-]*\.[A-Za-z0-9][A-Za-z0-9_-]*$'; then
echo "Error: '$SCOPE' is not a scope id." >&2
echo 'A scope id is <your-org>.<your-scope>, for example acme.shop.' >&2
exit 1
fi
if ! command -v bit > /dev/null 2>&1; then
echo 'Error: the bit command is not on your PATH.' >&2
echo 'Install Bit first: npx @teambit/bvm install' >&2
exit 1
fi
echo "==> Step 1 of 5: write the default scope"
if grep -q "\"defaultScope\": \"$PLACEHOLDER\"" workspace.jsonc; then
sed "s|\"defaultScope\": \"$PLACEHOLDER\"|\"defaultScope\": \"$SCOPE\"|" workspace.jsonc > workspace.jsonc.new
mv workspace.jsonc.new workspace.jsonc
echo "workspace.jsonc now uses the scope $SCOPE."
else
echo 'The placeholder is absent. workspace.jsonc keeps its current scope.'
fi
echo "==> Step 2 of 5: initialize the workspace"
if [ -f .bitmap ]; then
echo 'The workspace has a .bitmap file already. The step is not necessary.'
else
# A fresh clone has workspace.jsonc, but no .bitmap and no local scope.
# `bit install` refuses to run before `bit init` creates them.
bit init
fi
echo "==> Step 3 of 5: install the dependencies"
bit install
echo "==> Step 4 of 5: track the component"
if [ -f .bitmap ] && grep -q "\"$COMPONENT_ID\"" .bitmap; then
echo "Bit tracks $COMPONENT_ID already."
else
bit add "$COMPONENT_DIR" --id "$COMPONENT_ID"
echo "Bit now tracks $COMPONENT_ID."
fi
echo "==> Step 5 of 5: show the workspace status"
bit status
cat <<'CHECKLIST'
==> The workspace is ready. Four manual steps remain.
1. Create the repository secret BIT_CONFIG_ACCESS_TOKEN.
Go to Settings > Secrets and variables > Actions > New repository secret.
The value is a bit.cloud token of a service account.
The account must have write permission on your scope.
Get the token with: bit login --machine-name ci
Never commit the token, and never print it in a workflow.
2. Permit the workflows to open a pull request.
Go to Settings > Actions > General > Workflow permissions.
Select "Allow GitHub Actions to create and approve pull requests".
If this setting is off, the sync run fails when it opens the pull request.
3. Create the bit.cloud webhook.
Go to your bit.cloud organization: Settings > Webhooks > Create webhook.
Event: Components > Export succeeded
URL: https://api.github.com/repos/<owner>/<repo>/dispatches
Headers: Authorization: Bearer <GitHub token with repo scope>
Accept: application/vnd.github+json
Template: Custom, with the body that the README gives.
A correct delivery returns 204.
4. Export the component one time, so the scope has content.
Run: bit lane create hello && bit snap -m "first snap" && bit export
The bit-sync workflow then opens the branch and the pull request.
The README explains each step, and it lists the four flows to test.
CHECKLIST