Skip to content

Commit c24feca

Browse files
Just trying to keep the starter pack up to parity with the ecosystem (#2)
* Just trying to keep the starter pack up to parity with the ecosystem * Address PR feedback on factoring workflows more conventionally, good tip * Remove release.yaml - external connectors won't have required secrets The shared release workflow needs RELENG_GITHUB_TOKEN, Apple signing creds, and other secrets that external connector repos won't have. Better to omit it than ship something broken. * Modernize setup-ci.yaml: go 1.23, current action versions - Bump actions/checkout v2->v4, setup-python v2->v5, setup-go v4->v5 - Go version 1.20->1.23 to match go.mod - Remove go mod init since template already has go.mod * Makefile: add config generation and Lambda build support Matches patterns from baton-google-workspace and other production connectors. Build now depends on generated config, and BATON_LAMBDA_SUPPORT env var enables the lambda build tag when needed. * Switch to go:generate config pattern used by current connectors The old inline Config struct is out. Now config fields live in pkg/config/config.go with go:generate directive, and the SDK generates the typed struct in conf.gen.go. Matches baton-gitlab, baton-google-workspace, and other production connectors. * setup-ci.yaml: sync with baton-template improvements - permissions block for contents/actions write - change-string-case-action for dynamic repo name - derive config_name/display_name from cookiecutter.json - go mod init with dynamic lowercase repo name - go get baton-sdk@latest instead of static go.mod - generate config schema step - gofmt generated code - fetch latest .golangci.yml from github-workflows * sync template with internal baton-template patterns * restore verify.yaml and simple ci.yaml - sorry!
1 parent e85b142 commit c24feca

File tree

19 files changed

+775
-67
lines changed

19 files changed

+775
-67
lines changed

.github/workflows/setup-ci.yaml

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ on:
33
push:
44
paths:
55
- cookiecutter.json
6+
permissions:
7+
contents: write
8+
actions: write
69
jobs:
710
setup:
811
name: Reinitialize repository
912
runs-on: ubuntu-latest
1013
env:
1114
REPO_SETUP_TOKEN: ${{ secrets.REPO_SETUP_TOKEN }}
15+
GITHUB_TOKEN: ${{ secrets.REPO_SETUP_TOKEN }}
1216
steps:
1317
- name: Do not run scaffolding on template repository
1418
shell: bash
@@ -25,7 +29,12 @@ jobs:
2529
https://api.github.com/repos/$GITHUB_REPOSITORY \
2630
| jq --exit-status '.is_template == false';
2731
28-
- uses: actions/checkout@v2
32+
- id: string
33+
uses: ASzc/change-string-case-action@v6
34+
with:
35+
string: ${{ github.repository }}
36+
37+
- uses: actions/checkout@v4
2938
with:
3039
# Committing workflow files using the regular GITHUB_TOKEN will fail with
3140
# `Git Error: Refusing to allow a GitHub App to create or update workflow without workflows permission`.
@@ -35,13 +44,34 @@ jobs:
3544
# Checkout my blog post https://stefanbuck.com/blog for alternative options
3645
token: ${{ env.REPO_SETUP_TOKEN || secrets.GITHUB_TOKEN }}
3746

38-
- uses: actions/setup-python@v2
47+
- uses: actions/setup-python@v5
3948
with:
40-
python-version: '3.x'
49+
python-version: "3.x"
4150

4251
- name: Install dependencies
4352
run: pip install cookiecutter
4453

54+
- name: Derive config_name and display_name from name
55+
id: name_parts
56+
run: |
57+
raw_name=$(jq -r '.name' cookiecutter.json)
58+
59+
# Strip "baton-" prefix if present
60+
name_no_prefix="${raw_name#baton-}"
61+
62+
# PascalCase for config_name
63+
config_name=$(echo "$name_no_prefix" | sed -E 's/(^|-)([a-z])/\U\2/g')
64+
65+
# Title Case for display_name
66+
display_name=$(echo "$name_no_prefix" | sed 's/[-_]/ /g' | sed 's/\b\w/\U&/g')
67+
68+
# Overwrite cookiecutter.json with new fields
69+
jq --arg config_name "$config_name" \
70+
--arg display_name "$display_name" \
71+
--arg name_no_prefix "$name_no_prefix" \
72+
'.config_name = $config_name | .display_name = $display_name | .name_no_prefix = $name_no_prefix' \
73+
cookiecutter.json > tmp.json && mv tmp.json cookiecutter.json
74+
4575
- name: Scaffolding repository
4676
# cookiecutter is command-line utility to create projects from templates
4777
# https://github.com/cookiecutter/cookiecutter
@@ -71,17 +101,30 @@ jobs:
71101
rm -rf ./cookiecutter-temp/
72102
73103
- name: Install Go
74-
uses: actions/setup-go@v4
104+
uses: actions/setup-go@v5
75105
with:
76-
go-version: 1.20.x
106+
go-version: "1.23"
77107

78108
- name: go mod init
79109
shell: bash
80110
run: |
81-
go mod init github.com/$GITHUB_REPOSITORY && \
111+
go mod init "github.com/${{ steps.string.outputs.lowercase }}" && \
112+
go get github.com/conductorone/baton-sdk@latest && \
82113
go mod tidy && \
83114
go mod vendor
84115
116+
- name: Generate config schema
117+
run: go generate -tags=generate ./pkg/config
118+
119+
- name: gofmt
120+
run: gofmt -w .
121+
122+
- name: Get latest lint config
123+
run: |
124+
LATEST_TAG=$(curl -sSfL https://api.github.com/repos/ConductorOne/github-workflows/releases/latest | jq -r '.tag_name')
125+
curl -sSfL "https://raw.githubusercontent.com/ConductorOne/github-workflows/${LATEST_TAG}/.golangci.yml" -o .golangci.yml
126+
echo "Successfully updated .golangci.yml from release ${LATEST_TAG}"
127+
85128
- name: Reinitialize git repository
86129
shell: bash
87130
# Reinitialize git after scaffolding this repository.
@@ -93,4 +136,4 @@ jobs:
93136
git checkout --orphan temp-branch && \
94137
git add . && \
95138
git commit -m 'Initial commit' && \
96-
git push origin temp-branch:main -f
139+
git push origin temp-branch:main -f
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
allow:
8+
- dependency-name: "github.com/conductorone/baton-sdk"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
- name: Install Go
17+
uses: actions/setup-go@v5
18+
with:
19+
go-version-file: 'go.mod'
20+
- name: Build connector
21+
run: go build -o {{ cookiecutter.name }} ./cmd/{{ cookiecutter.name }}
22+
- name: Verify binary runs
23+
run: ./{{ cookiecutter.name }} --help
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Verify
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
push:
7+
branches:
8+
- main
9+
10+
jobs:
11+
verify:
12+
uses: ConductorOne/github-workflows/.github/workflows/verify.yaml@v4
13+
with:
14+
ref: ${{ github.event.pull_request.head.sha || github.sha }}

{{cookiecutter.name}}/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build stage
2+
FROM golang:1.23-alpine AS builder
3+
WORKDIR /app
4+
5+
COPY go.mod go.sum ./
6+
RUN go mod download
7+
8+
COPY . .
9+
RUN CGO_ENABLED=0 GOOS=linux go build -o /build/{{ cookiecutter.name }} ./cmd/{{ cookiecutter.name }}
10+
11+
# Runtime stage - distroless for security
12+
FROM gcr.io/distroless/static-debian11:nonroot
13+
COPY --from=builder /build/{{ cookiecutter.name }} /
14+
USER 65534
15+
ENTRYPOINT ["/{{ cookiecutter.name }}"]
16+
17+
LABEL org.opencontainers.image.title="{{ cookiecutter.name }}"
18+
LABEL org.opencontainers.image.source="https://github.com/{{ cookiecutter.repo_owner }}/{{ cookiecutter.repo_name }}"

{{cookiecutter.name}}/Makefile

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
GOOS = $(shell go env GOOS)
22
GOARCH = $(shell go env GOARCH)
33
BUILD_DIR = dist/${GOOS}_${GOARCH}
4+
GENERATED_CONF := pkg/config/conf.gen.go
45

56
ifeq ($(GOOS),windows)
67
OUTPUT_PATH = ${BUILD_DIR}/{{ cookiecutter.name }}.exe
78
else
89
OUTPUT_PATH = ${BUILD_DIR}/{{ cookiecutter.name }}
910
endif
1011

12+
# Set the build tag conditionally based on BATON_LAMBDA_SUPPORT
13+
ifdef BATON_LAMBDA_SUPPORT
14+
BUILD_TAGS=-tags baton_lambda_support
15+
else
16+
BUILD_TAGS=
17+
endif
18+
1119
.PHONY: build
12-
build:
13-
go build -o ${OUTPUT_PATH} ./cmd/{{ cookiecutter.name }}
14-
go build -o ${OUTPUT_PATH} ./cmd/{{ cookiecutter.name }}
20+
build: $(GENERATED_CONF)
21+
go build ${BUILD_TAGS} -o ${OUTPUT_PATH} ./cmd/{{ cookiecutter.name }}
22+
23+
$(GENERATED_CONF): pkg/config/config.go go.mod
24+
@echo "Generating $(GENERATED_CONF)..."
25+
go generate -tags=generate ./pkg/config
26+
27+
.PHONY: generate
28+
generate: $(GENERATED_CONF)
29+
30+
.PHONY: test
31+
test:
32+
go test -v ./...
33+
34+
.PHONY: lint
35+
lint:
36+
golangci-lint run --timeout=3m
1537

1638
.PHONY: update-deps
1739
update-deps:
@@ -24,6 +46,15 @@ add-dep:
2446
go mod tidy -v
2547
go mod vendor
2648

27-
.PHONY: lint
28-
lint:
29-
golangci-lint run
49+
.PHONY: update-baton-sdk-deps
50+
update-baton-sdk-deps:
51+
go get -u github.com/conductorone/baton-sdk
52+
go mod tidy -v
53+
go mod vendor
54+
55+
.PHONY: clean
56+
clean:
57+
rm -rf dist/
58+
rm -f $(GENERATED_CONF)
59+
60+
.DEFAULT_GOAL := build

{{cookiecutter.name}}/cmd/{{cookiecutter.name}}/config.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

{{cookiecutter.name}}/cmd/{{cookiecutter.name}}/main.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1+
//go:build !generate
2+
13
package main
24

35
import (
46
"context"
57
"fmt"
68
"os"
79

8-
"github.com/conductorone/baton-sdk/pkg/cli"
10+
cfg "github.com/{{ cookiecutter.repo_owner }}/{{ cookiecutter.repo_name }}/pkg/config"
11+
"github.com/{{ cookiecutter.repo_owner }}/{{ cookiecutter.repo_name }}/pkg/connector"
12+
"github.com/conductorone/baton-sdk/pkg/config"
913
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
14+
"github.com/conductorone/baton-sdk/pkg/field"
1015
"github.com/conductorone/baton-sdk/pkg/types"
1116
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1217
"go.uber.org/zap"
13-
14-
"github.com/{{ cookiecutter.repo_owner }}/{{ cookiecutter.repo_name }}/pkg/connector"
1518
)
1619

1720
var version = "dev"
1821

1922
func main() {
2023
ctx := context.Background()
2124

22-
cfg := &config{}
23-
cmd, err := cli.NewCmd(ctx, "{{ cookiecutter.name }}", cfg, validateConfig, getConnector)
25+
_, cmd, err := config.DefineConfiguration(
26+
ctx,
27+
"{{ cookiecutter.name }}",
28+
getConnector,
29+
cfg.Config,
30+
)
2431
if err != nil {
2532
fmt.Fprintln(os.Stderr, err.Error())
2633
os.Exit(1)
@@ -35,19 +42,24 @@ func main() {
3542
}
3643
}
3744

38-
func getConnector(ctx context.Context, cfg *config) (types.ConnectorServer, error) {
45+
func getConnector(ctx context.Context, cc *cfg.Connector) (types.ConnectorServer, error) {
3946
l := ctxzap.Extract(ctx)
4047

41-
cb, err := connector.New(ctx)
48+
err := field.Validate(cfg.Config, cc)
4249
if err != nil {
43-
l.Error("error creating connector", zap.Error(err))
4450
return nil, err
4551
}
4652

53+
cb, err := connector.New(ctx)
54+
if err != nil {
55+
l.Error("{{ cookiecutter.name }}: error creating connector", zap.Error(err))
56+
return nil, fmt.Errorf("{{ cookiecutter.name }}: failed to create connector: %w", err)
57+
}
58+
4759
c, err := connectorbuilder.NewConnector(ctx, cb)
4860
if err != nil {
49-
l.Error("error creating connector", zap.Error(err))
50-
return nil, err
61+
l.Error("{{ cookiecutter.name }}: error wrapping connector", zap.Error(err))
62+
return nil, fmt.Errorf("{{ cookiecutter.name }}: failed to initialize connector: %w", err)
5163
}
5264

5365
return c, nil

{{cookiecutter.name}}/go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/{{ cookiecutter.repo_owner }}/{{ cookiecutter.repo_name }}
2+
3+
go 1.23
4+
5+
require (
6+
github.com/conductorone/baton-sdk v0.7.1
7+
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
8+
go.uber.org/zap v1.27.0
9+
google.golang.org/protobuf v1.36.3
10+
)

0 commit comments

Comments
 (0)