Skip to content

Commit 00aedb8

Browse files
Add dev/prod build mode with separate app identities
- Introduce buildinfo app identity vars (AppName, ConfigDirName, KeychainSvc, KeychainKey) with prod defaults - Override identity at startup when buildMode=dev via ldflags, giving dev builds their own binary name, config dir, and keychain entries - Update build-and-deploy workflow to pass buildMode and use dynamic binary names per environment - Replace hardcoded "deepsource" strings with buildinfo vars in config, keychain, and root command - Remove shell completion generation (gen-completions.sh deleted, references stripped from workflows and Homebrew formula) - Add just install step to CI workflow - Rename deploy -> deploy-prod in justfile, add build alias
1 parent 6c7a3df commit 00aedb8

11 files changed

Lines changed: 97 additions & 72 deletions

File tree

.github/workflows/CI.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
fetch-depth: 1
2525
ref: ${{ github.event.pull_request.head.sha }}
2626

27+
- name: Install just
28+
uses: extractions/setup-just@v2
29+
2730
- name: Build the binary
2831
run: just build
2932

.github/workflows/build-and-deploy.yml

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
base_url: ${{ steps.resolve.outputs.base_url }}
2121
bucket: ${{ steps.resolve.outputs.bucket }}
2222
version: ${{ steps.resolve.outputs.version }}
23+
binary_name: ${{ steps.resolve.outputs.binary_name }}
2324
steps:
2425
- name: Resolve environment from tag
2526
id: resolve
@@ -29,10 +30,12 @@ jobs:
2930
echo "environment=prod" >> "$GITHUB_OUTPUT"
3031
echo "base_url=https://deepsource.com/cli" >> "$GITHUB_OUTPUT"
3132
echo "bucket=${{ secrets.R2_PROD_BUCKET_NAME }}" >> "$GITHUB_OUTPUT"
33+
echo "binary_name=deepsource" >> "$GITHUB_OUTPUT"
3234
else
3335
echo "environment=dev" >> "$GITHUB_OUTPUT"
3436
echo "base_url=https://deepsource.one/cli" >> "$GITHUB_OUTPUT"
3537
echo "bucket=${{ secrets.R2_DEV_BUCKET_NAME }}" >> "$GITHUB_OUTPUT"
38+
echo "binary_name=deepsource-dev" >> "$GITHUB_OUTPUT"
3639
fi
3740
echo "version=${TAG}" >> "$GITHUB_OUTPUT"
3841
@@ -58,9 +61,6 @@ jobs:
5861
if: matrix.goarch == 'arm64'
5962
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
6063

61-
- name: Generate completions
62-
run: bash scripts/gen-completions.sh
63-
6464
- name: Build
6565
env:
6666
CGO_ENABLED: '1'
@@ -69,23 +69,25 @@ jobs:
6969
CC: ${{ matrix.cc }}
7070
CXX: ${{ matrix.cxx }}
7171
run: |
72+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
7273
cd cmd/deepsource && go build -tags static_all \
73-
-ldflags "-X 'main.version=${{ needs.resolve-env.outputs.version }}' -X 'main.Date=$(date -u +%Y-%m-%d)' -X 'main.SentryDSN=${{ secrets.SENTRY_DSN }}'" \
74-
-o deepsource .
74+
-ldflags "-X 'main.version=${{ needs.resolve-env.outputs.version }}' -X 'main.Date=$(date -u +%Y-%m-%d)' -X 'main.SentryDSN=${{ secrets.SENTRY_DSN }}' -X 'main.buildMode=${{ needs.resolve-env.outputs.environment }}'" \
75+
-o "$BINARY_NAME" .
7576
7677
- name: Package
7778
run: |
78-
ARCHIVE="deepsource_${{ needs.resolve-env.outputs.version }}_linux_${{ matrix.goarch }}.tar.gz"
79-
tar -czf "$ARCHIVE" -C cmd/deepsource deepsource -C ../../ completions
79+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
80+
ARCHIVE="${BINARY_NAME}_${{ needs.resolve-env.outputs.version }}_linux_${{ matrix.goarch }}.tar.gz"
81+
tar -czf "$ARCHIVE" -C cmd/deepsource "$BINARY_NAME"
8082
sha256sum "$ARCHIVE" > "${ARCHIVE}.sha256"
8183
echo "ARCHIVE=${ARCHIVE}" >> "$GITHUB_ENV"
8284
8385
- uses: actions/upload-artifact@v4
8486
with:
8587
name: build-linux-${{ matrix.goarch }}
8688
path: |
87-
deepsource_*.tar.gz
88-
deepsource_*.tar.gz.sha256
89+
${{ needs.resolve-env.outputs.binary_name }}_*.tar.gz
90+
${{ needs.resolve-env.outputs.binary_name }}_*.tar.gz.sha256
8991
9092
build-darwin:
9193
needs: resolve-env
@@ -99,18 +101,16 @@ jobs:
99101
with:
100102
go-version: ${{ env.GO_VERSION }}
101103

102-
- name: Generate completions
103-
run: bash scripts/gen-completions.sh
104-
105104
- name: Build
106105
env:
107106
CGO_ENABLED: '1'
108107
GOOS: darwin
109108
GOARCH: ${{ matrix.goarch }}
110109
run: |
110+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
111111
cd cmd/deepsource && go build -tags static_all \
112-
-ldflags "-X 'main.version=${{ needs.resolve-env.outputs.version }}' -X 'main.Date=$(date -u +%Y-%m-%d)' -X 'main.SentryDSN=${{ secrets.SENTRY_DSN }}'" \
113-
-o deepsource .
112+
-ldflags "-X 'main.version=${{ needs.resolve-env.outputs.version }}' -X 'main.Date=$(date -u +%Y-%m-%d)' -X 'main.SentryDSN=${{ secrets.SENTRY_DSN }}' -X 'main.buildMode=${{ needs.resolve-env.outputs.environment }}'" \
113+
-o "$BINARY_NAME" .
114114
115115
- name: Codesign
116116
env:
@@ -131,19 +131,23 @@ jobs:
131131
security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
132132
security list-keychains -d user -s "$KEYCHAIN_PATH" login.keychain
133133
134+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
135+
134136
# Sign the binary
135137
codesign --force --options runtime \
136138
--sign "Developer ID Application: DeepSource Corp" \
137-
cmd/deepsource/deepsource
139+
"cmd/deepsource/${BINARY_NAME}"
138140
139141
- name: Notarize
140142
env:
141143
APPLE_ID: ${{ secrets.APPLE_ID }}
142144
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
143145
APPLE_APP_PASSWORD: ${{ secrets.APPLE_APP_PASSWORD }}
144146
run: |
147+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
148+
145149
# Create zip for notarization
146-
ditto -c -k cmd/deepsource/deepsource notarize.zip
150+
ditto -c -k "cmd/deepsource/${BINARY_NAME}" notarize.zip
147151
xcrun notarytool submit notarize.zip \
148152
--apple-id "$APPLE_ID" \
149153
--team-id "$APPLE_TEAM_ID" \
@@ -152,21 +156,23 @@ jobs:
152156
153157
- name: Verify signing
154158
run: |
155-
codesign --verify --verbose cmd/deepsource/deepsource
156-
spctl --assess --type execute cmd/deepsource/deepsource || true
159+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
160+
codesign --verify --verbose "cmd/deepsource/${BINARY_NAME}"
161+
spctl --assess --type execute "cmd/deepsource/${BINARY_NAME}" || true
157162
158163
- name: Package
159164
run: |
160-
ARCHIVE="deepsource_${{ needs.resolve-env.outputs.version }}_darwin_${{ matrix.goarch }}.tar.gz"
161-
tar -czf "$ARCHIVE" -C cmd/deepsource deepsource -C ../../ completions
165+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
166+
ARCHIVE="${BINARY_NAME}_${{ needs.resolve-env.outputs.version }}_darwin_${{ matrix.goarch }}.tar.gz"
167+
tar -czf "$ARCHIVE" -C cmd/deepsource "$BINARY_NAME"
162168
shasum -a 256 "$ARCHIVE" > "${ARCHIVE}.sha256"
163169
164170
- uses: actions/upload-artifact@v4
165171
with:
166172
name: build-darwin-${{ matrix.goarch }}
167173
path: |
168-
deepsource_*.tar.gz
169-
deepsource_*.tar.gz.sha256
174+
${{ needs.resolve-env.outputs.binary_name }}_*.tar.gz
175+
${{ needs.resolve-env.outputs.binary_name }}_*.tar.gz.sha256
170176
171177
build-windows:
172178
needs: resolve-env
@@ -188,22 +194,24 @@ jobs:
188194
CC: x86_64-w64-mingw32-gcc
189195
CXX: x86_64-w64-mingw32-g++
190196
run: |
197+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
191198
cd cmd/deepsource && go build -tags static_all \
192-
-ldflags "-X 'main.version=${{ needs.resolve-env.outputs.version }}' -X 'main.Date=$(date -u +%Y-%m-%d)' -X 'main.SentryDSN=${{ secrets.SENTRY_DSN }}'" \
193-
-o deepsource.exe .
199+
-ldflags "-X 'main.version=${{ needs.resolve-env.outputs.version }}' -X 'main.Date=$(date -u +%Y-%m-%d)' -X 'main.SentryDSN=${{ secrets.SENTRY_DSN }}' -X 'main.buildMode=${{ needs.resolve-env.outputs.environment }}'" \
200+
-o "${BINARY_NAME}.exe" .
194201
195202
- name: Package
196203
run: |
197-
ARCHIVE="deepsource_${{ needs.resolve-env.outputs.version }}_windows_amd64.zip"
198-
zip "$ARCHIVE" -j cmd/deepsource/deepsource.exe
204+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
205+
ARCHIVE="${BINARY_NAME}_${{ needs.resolve-env.outputs.version }}_windows_amd64.zip"
206+
zip "$ARCHIVE" -j "cmd/deepsource/${BINARY_NAME}.exe"
199207
sha256sum "$ARCHIVE" > "${ARCHIVE}.sha256"
200208
201209
- uses: actions/upload-artifact@v4
202210
with:
203211
name: build-windows-amd64
204212
path: |
205-
deepsource_*.zip
206-
deepsource_*.zip.sha256
213+
${{ needs.resolve-env.outputs.binary_name }}_*.zip
214+
${{ needs.resolve-env.outputs.binary_name }}_*.zip.sha256
207215
208216
deploy:
209217
needs: [resolve-env, build-linux, build-darwin, build-windows]
@@ -219,6 +227,7 @@ jobs:
219227
- name: Generate manifest
220228
run: |
221229
VERSION="${{ needs.resolve-env.outputs.version }}"
230+
BINARY_NAME="${{ needs.resolve-env.outputs.binary_name }}"
222231
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
223232
224233
get_sha() {
@@ -231,32 +240,33 @@ jobs:
231240
"buildTime": "${BUILD_TIME}",
232241
"platforms": {
233242
"darwin_amd64": {
234-
"archive": "deepsource_${VERSION}_darwin_amd64.tar.gz",
235-
"sha256": "$(get_sha "deepsource_${VERSION}_darwin_amd64.tar.gz")"
243+
"archive": "${BINARY_NAME}_${VERSION}_darwin_amd64.tar.gz",
244+
"sha256": "$(get_sha "${BINARY_NAME}_${VERSION}_darwin_amd64.tar.gz")"
236245
},
237246
"darwin_arm64": {
238-
"archive": "deepsource_${VERSION}_darwin_arm64.tar.gz",
239-
"sha256": "$(get_sha "deepsource_${VERSION}_darwin_arm64.tar.gz")"
247+
"archive": "${BINARY_NAME}_${VERSION}_darwin_arm64.tar.gz",
248+
"sha256": "$(get_sha "${BINARY_NAME}_${VERSION}_darwin_arm64.tar.gz")"
240249
},
241250
"linux_amd64": {
242-
"archive": "deepsource_${VERSION}_linux_amd64.tar.gz",
243-
"sha256": "$(get_sha "deepsource_${VERSION}_linux_amd64.tar.gz")"
251+
"archive": "${BINARY_NAME}_${VERSION}_linux_amd64.tar.gz",
252+
"sha256": "$(get_sha "${BINARY_NAME}_${VERSION}_linux_amd64.tar.gz")"
244253
},
245254
"linux_arm64": {
246-
"archive": "deepsource_${VERSION}_linux_arm64.tar.gz",
247-
"sha256": "$(get_sha "deepsource_${VERSION}_linux_arm64.tar.gz")"
255+
"archive": "${BINARY_NAME}_${VERSION}_linux_arm64.tar.gz",
256+
"sha256": "$(get_sha "${BINARY_NAME}_${VERSION}_linux_arm64.tar.gz")"
248257
},
249258
"windows_amd64": {
250-
"archive": "deepsource_${VERSION}_windows_amd64.zip",
251-
"sha256": "$(get_sha "deepsource_${VERSION}_windows_amd64.zip")"
259+
"archive": "${BINARY_NAME}_${VERSION}_windows_amd64.zip",
260+
"sha256": "$(get_sha "${BINARY_NAME}_${VERSION}_windows_amd64.zip")"
252261
}
253262
}
254263
}
255264
EOF
256265
257266
- name: Generate install script
258267
run: |
259-
sed "s|__BASE_URL__|${{ needs.resolve-env.outputs.base_url }}|g" \
268+
sed -e "s|__BASE_URL__|${{ needs.resolve-env.outputs.base_url }}|g" \
269+
-e "s|__BINARY_NAME__|${{ needs.resolve-env.outputs.binary_name }}|g" \
260270
scripts/install.sh.template > artifacts/install.sh
261271
262272
- name: Upload to R2
@@ -269,7 +279,7 @@ jobs:
269279
BUCKET="${{ needs.resolve-env.outputs.bucket }}"
270280
271281
# Upload archives and checksums (immutable)
272-
for f in artifacts/deepsource_*; do
282+
for f in artifacts/${{ needs.resolve-env.outputs.binary_name }}_*; do
273283
aws s3 cp "$f" "s3://${BUCKET}/cli/build/$(basename "$f")" \
274284
--endpoint-url "$ENDPOINT" \
275285
--cache-control "public, max-age=31536000, immutable"
@@ -333,9 +343,6 @@ jobs:
333343
334344
def install
335345
bin.install "deepsource"
336-
bash_completion.install "completions/deepsource.bash" => "deepsource"
337-
zsh_completion.install "completions/deepsource.zsh" => "_deepsource"
338-
fish_completion.install "completions/deepsource.fish"
339346
end
340347
end
341348
FORMULA

buildinfo/version.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import (
77

88
var buildInfo *BuildInfo
99

10+
// App identity variables. Defaults are prod values; overridden in main.go for dev builds.
11+
var (
12+
AppName = "deepsource" // binary name / display name
13+
ConfigDirName = ".deepsource" // ~/<this>/
14+
KeychainSvc = "deepsource-cli" // macOS keychain service
15+
KeychainKey = "deepsource-cli-token" // macOS keychain account
16+
)
17+
1018
// BuildInfo describes the compile time information.
1119
type BuildInfo struct {
1220
// Version is the current semver.

cmd/deepsource/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ var (
2424

2525
// DSN used for sentry
2626
SentryDSN string
27+
28+
// buildMode is "dev" or "prod" (default). Set via ldflags -X.
29+
buildMode string
2730
)
2831

2932
func sentryEnvironment(ver string) string {
@@ -36,10 +39,18 @@ func sentryEnvironment(ver string) string {
3639
func main() {
3740
log.SetFlags(log.LstdFlags | log.Lshortfile)
3841

42+
// Override app identity for dev builds
43+
if buildMode == "dev" {
44+
v.AppName = "deepsource-dev"
45+
v.ConfigDirName = ".deepsource-dev"
46+
v.KeychainSvc = "deepsource-dev-cli"
47+
v.KeychainKey = "deepsource-dev-cli-token"
48+
}
49+
3950
// Init sentry
4051
err := sentry.Init(sentry.ClientOptions{
4152
Dsn: SentryDSN,
42-
Release: "deepsource-cli@" + version,
53+
Release: v.AppName + "-cli@" + version,
4354
Environment: sentryEnvironment(version),
4455
})
4556
if err != nil {

command/root.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ import (
1717

1818
func NewCmdRoot() *cobra.Command {
1919
cmd := &cobra.Command{
20-
Use: "deepsource <command> [flags]",
20+
Use: buildinfo.AppName + " <command> [flags]",
2121
Short: "DeepSource CLI",
22-
Long: `DeepSource CLI - Ship good code from the command line.
23-
24-
To get started, run: deepsource auth login`,
22+
Long: "DeepSource CLI - Ship good code from the command line.\n\nTo get started, run: " + buildinfo.AppName + " auth login",
2523
SilenceErrors: true,
2624
SilenceUsage: true,
2725
}

config/config.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package config
22

33
import (
4-
"errors"
4+
"fmt"
55
"time"
6+
7+
"github.com/deepsourcelabs/cli/buildinfo"
68
)
79

810
const (
9-
ConfigDirName = "/.deepsource/"
1011
ConfigFileName = "/config.toml"
1112
DefaultHostName = "deepsource.com"
1213
)
@@ -35,7 +36,7 @@ func (cfg CLIConfig) IsExpired() bool {
3536

3637
func (cfg *CLIConfig) VerifyAuthentication() error {
3738
if cfg.Token == "" {
38-
return errors.New("You are not logged into DeepSource. Run \"deepsource auth login\" to authenticate.")
39+
return fmt.Errorf("You are not logged into DeepSource. Run \"%s auth login\" to authenticate.", buildinfo.AppName)
3940
}
4041
return nil
4142
}

config/manager.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/deepsourcelabs/cli/buildinfo"
89
"github.com/deepsourcelabs/cli/internal/adapters"
910
"github.com/deepsourcelabs/cli/internal/interfaces"
1011
"github.com/deepsourcelabs/cli/internal/secrets"
@@ -27,7 +28,7 @@ func NewManager(fs interfaces.FileSystem, homeDir func() (string, error)) *Manag
2728
// NewManagerWithSecrets creates a config manager with a secrets store.
2829
func NewManagerWithSecrets(fs interfaces.FileSystem, homeDir func() (string, error), store secrets.Store, key string) *Manager {
2930
if key == "" {
30-
key = "deepsource-cli-token"
31+
key = buildinfo.KeychainKey
3132
}
3233
if store == nil {
3334
store = secrets.NoopStore{}
@@ -45,7 +46,7 @@ func (m *Manager) configDir() (string, error) {
4546
if err != nil {
4647
return "", err
4748
}
48-
return filepath.Join(home, ConfigDirName), nil
49+
return filepath.Join(home, buildinfo.ConfigDirName), nil
4950
}
5051

5152
func (m *Manager) configPath() (string, error) {

internal/secrets/keychain_darwin.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"bytes"
77
"os/exec"
88
"strings"
9+
10+
"github.com/deepsourcelabs/cli/buildinfo"
911
)
1012

1113
type keychainStore struct {
@@ -14,7 +16,7 @@ type keychainStore struct {
1416

1517
// NewKeychainStore returns a macOS keychain-backed store.
1618
func NewKeychainStore() Store {
17-
return &keychainStore{service: "deepsource-cli"}
19+
return &keychainStore{service: buildinfo.KeychainSvc}
1820
}
1921

2022
func (k *keychainStore) Get(key string) (string, error) {

0 commit comments

Comments
 (0)