Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Claude Code Review

on:
pull_request:
types: [opened, synchronize, ready_for_review, reopened]
# Optional: Only run on specific file changes
# paths:
# - "src/**/*.ts"
# - "src/**/*.tsx"
# - "src/**/*.js"
# - "src/**/*.jsx"

jobs:
claude-review:
# Optional: Filter by PR author
# if: |
# github.event.pull_request.user.login == 'external-contributor' ||
# github.event.pull_request.user.login == 'new-developer' ||
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'

runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
plugin_marketplaces: 'https://github.com/anthropics/claude-code.git'
plugins: 'code-review@claude-code-plugins'
prompt: '/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}'
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://code.claude.com/docs/en/cli-reference for available options
49 changes: 49 additions & 0 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Claude Code

on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]

jobs:
claude:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
issues: read
id-token: write
actions: read # Required for Claude to read CI results on PRs
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

# This is an optional setting that allows Claude to read CI results on PRs
additional_permissions: |
actions: read

# Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
# prompt: 'Update the pull request description to include a summary of changes.'

# Optional: Add claude_args to customize behavior and configuration
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
# or https://code.claude.com/docs/en/cli-reference for available options
# claude_args: '--allowed-tools Bash(gh pr:*)'
4 changes: 3 additions & 1 deletion src/massdriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ type Specification struct {
Action string `envconfig:"ACTION"`
BundleName string `envconfig:"BUNDLE_NAME"`
DeploymentID string `envconfig:"DEPLOYMENT_ID" required:"true"`
// TODO: make this required once PACKAGE_NAME is fully deprecated
InstanceID string `envconfig:"INSTANCE_ID"`
OrganizationID string `envconfig:"ORGANIZATION_ID" required:"true"`
PackageName string `envconfig:"PACKAGE_NAME" required:"true"`
PackageName string `envconfig:"PACKAGE_NAME"`
Token string `envconfig:"TOKEN" required:"true"`
URL string `envconfig:"URL"`
}
Expand Down
7 changes: 6 additions & 1 deletion src/provisioners/terraform/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ func GenerateBackendHTTPFile(ctx context.Context, output string, spec *massdrive
func GenerateJSONBackendHTTPConfig(spec *massdriver.Specification, bundleStep string) ([]byte, error) {
httpbb := new(HTTPBackendBlock)

instanceId := spec.InstanceID
if instanceId == "" {
instanceId = getPackageNameShort(spec.PackageName)
}

httpbb.Username = spec.DeploymentID
httpbb.Password = spec.Token
httpbb.Address = fmt.Sprintf("%s/state/%s/%s", spec.URL, getPackageNameShort(spec.PackageName), bundleStep)
httpbb.Address = fmt.Sprintf("%s/state/%s/%s", spec.URL, instanceId, bundleStep)
httpbb.LockAddress = httpbb.Address
httpbb.UnlockAddress = httpbb.Address

Expand Down
77 changes: 56 additions & 21 deletions src/provisioners/terraform/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,63 @@ import (
)

func TestGenerateJSONBackendHTTPConfig(t *testing.T) {
spec := massdriver.Specification{
DeploymentID: "depId",
Token: "token",
PackageName: "pkg-id-long-0000",
URL: "https://foo.massdriver.cloud",
}
got, _ := GenerateJSONBackendHTTPConfig(&spec, "step")
want := `
{
"terraform": {
"backend": {
"http": {
"username": "depId",
"password": "token",
"address": "https://foo.massdriver.cloud/state/pkg-id-long/step",
"lock_address": "https://foo.massdriver.cloud/state/pkg-id-long/step",
"unlock_address": "https://foo.massdriver.cloud/state/pkg-id-long/step"
tests := []struct {
name string
spec massdriver.Specification
step string
want string
}{
{
name: "generates backend from Package Name",
spec: massdriver.Specification{
DeploymentID: "depId",
Token: "token",
PackageName: "pkg-id-long-0000",
URL: "https://foo.massdriver.cloud",
},
step: "step",
want: `{
"terraform": {
"backend": {
"http": {
"username": "depId",
"password": "token",
"address": "https://foo.massdriver.cloud/state/pkg-id-long/step",
"lock_address": "https://foo.massdriver.cloud/state/pkg-id-long/step",
"unlock_address": "https://foo.massdriver.cloud/state/pkg-id-long/step"
}
}
}
}`,
}, {
name: "generates backend config from Instance ID",
spec: massdriver.Specification{
DeploymentID: "depId",
Token: "token",
InstanceID: "inst-ance-id",
URL: "https://foo.massdriver.cloud",
},
step: "step",
want: `{
"terraform": {
"backend": {
"http": {
"username": "depId",
"password": "token",
"address": "https://foo.massdriver.cloud/state/inst-ance-id/step",
"lock_address": "https://foo.massdriver.cloud/state/inst-ance-id/step",
"unlock_address": "https://foo.massdriver.cloud/state/inst-ance-id/step"
}
}
}
}
}
}`,
},
}
`

require.JSONEq(t, string(got), want)
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _ := GenerateJSONBackendHTTPConfig(&tt.spec, tt.step)
require.JSONEq(t, string(got), tt.want)
})
}
}
Loading