Skip to content

Commit

Permalink
Merge branch 'main' into issue-3614
Browse files Browse the repository at this point in the history
  • Loading branch information
840 authored Nov 14, 2024
2 parents abbab65 + 714e78c commit 3f1e078
Show file tree
Hide file tree
Showing 388 changed files with 26,665 additions and 5,564 deletions.
2 changes: 1 addition & 1 deletion .codegen/_openapi_sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3eae49b444cac5a0118a3503e5b7ecef7f96527a
d25296d2f4aa7bd6195c816fdf82e0f960f775da
94 changes: 76 additions & 18 deletions .codegen/model.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,95 @@ import (
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/hashicorp/terraform-plugin-framework/types"
)
{{- $excluded := dict "ShareInfo" (list "CreatedAt" "CreatedBy" "UpdatedAt" "UpdatedBy")
"SharedDataObject" (list "AddedAt" "AddedBy" "Status") -}}
{{range .Types}}
{{- if or .Fields .IsEmpty}}
{{.Comment "// " 80}}
type {{.PascalName}} struct {
{{- $excluded := getOrDefault $excluded .PascalName (list) -}}
{{- range .Fields}}
{{.Comment " // " 80}}
{{.PascalName}} {{if .IsOptionalObject}}*{{end}}{{template "type" .Entity}} `{{template "field-tag" . }}`{{end}}
{{- $data := dict "field" . "excluded" $excluded }}
{{template "field" $data}}{{if and .Entity.IsComputed (not (in $excluded .PascalName))}}{{ $data := dict "field" . "excluded" $excluded "effective" true }}{{printf "\n"}}{{template "field" $data}}{{end}}{{end}}
}

func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringCreateOrUpdate(plan {{.PascalName}}) {
{{- range .Fields -}}
{{- if and .Entity.IsComputed (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum) -}}
{{- if not (in $excluded .PascalName)}}
newState.Effective{{.PascalName}} = newState.{{.PascalName}}
newState.{{.PascalName}} = plan.{{.PascalName}}
{{- end}}
{{- end}}
{{- end}}
}

func (newState *{{.PascalName}}) SyncEffectiveFieldsDuringRead(existingState {{.PascalName}}) {
{{- range .Fields -}}
{{- if and .Entity.IsComputed (or .Entity.IsString .Entity.IsBool .Entity.IsInt64 .Entity.IsFloat64 .Entity.IsInt .Entity.Enum) -}}
{{- if not (in $excluded .PascalName) -}}
{{- $type := "" -}}
{{- if .Entity.IsString}}{{$type = "String"}}{{end}}
{{- if .Entity.IsBool}}{{$type = "Bool"}}{{end}}
{{- if .Entity.IsInt64}}{{$type = "Int64"}}{{end}}
{{- if .Entity.IsFloat64}}{{$type = "Float64"}}{{end}}
{{- if .Entity.IsInt}}{{$type = "Int64"}}{{end}}
{{- if .Entity.Enum}}{{$type = "String"}}{{end}}
newState.Effective{{.PascalName}} = existingState.Effective{{.PascalName}}
if existingState.Effective{{.PascalName}}.Value{{$type}}() == newState.{{.PascalName}}.Value{{$type}}() {
newState.{{.PascalName}} = existingState.{{.PascalName}}
}
{{- end}}
{{- end}}
{{- end}}
}

{{end}}
{{end}}

{{- define "field" -}}
{{if .effective}}Effective{{end}}{{.field.PascalName}} {{template "type" .field.Entity}} `{{template "field-tag" . }}`
{{- end -}}

{{- define "field-tag" -}}
{{if .IsJson}}tfsdk:"{{if and (ne .Entity.Terraform nil) (ne .Entity.Terraform.Alias "") }}{{.Entity.Terraform.Alias}}{{else}}{{.Name}}{{end}}" tf:"{{if not .Required}}optional{{end}}"{{else}}tfsdk:"-"{{end -}}
{{- $annotations := "" -}}
{{- if in .excluded .field.PascalName -}}
{{- $annotations = (printf "%scomputed,optional," $annotations) -}}
{{- else if .effective -}}
{{- $annotations = (printf "%scomputed,optional," $annotations) -}}
{{- else -}}
{{- if not .field.Required -}}
{{- $annotations = (printf "%soptional," $annotations) -}}
{{- end -}}
{{- if .field.Entity.IsObject -}}
{{- $annotations = (printf "%sobject," $annotations) -}}
{{- end -}}
{{- end -}}
{{- if gt (len $annotations) 0 -}}
{{- $annotations = (printf "%s" (trimSuffix "," $annotations)) -}}
{{- end -}}
{{if .field.IsJson}}tfsdk:"{{if and (ne .field.Entity.Terraform nil) (ne .field.Entity.Terraform.Alias "") }}{{.field.Entity.Terraform.Alias}}{{else}}{{if .effective}}effective_{{end}}{{.field.Name}}{{end}}" tf:"{{$annotations}}"{{else}}tfsdk:"-"{{end -}}
{{- end -}}

{{- define "type" -}}
{{- if not . }}any /* ERROR */
{{- else if .IsExternal }}{{.Package.Name}}.{{.PascalName}}
{{- else if .IsAny}}any
{{- else if .IsEmpty}}{{.PascalName}}
{{- else if .IsString}}types.String
{{- else if .IsBool}}types.Bool
{{- else if .IsInt64}}types.Int64
{{- else if .IsFloat64}}types.Float64
{{- else if .IsInt}}types.Int64
{{- else if .IsByteStream}}io.ReadCloser
{{- else if .ArrayValue }}[]{{template "type" .ArrayValue}}
{{- else if .MapValue }}map[string]{{template "type" .MapValue}}
{{- else if .IsObject }}{{.PascalName}}
{{- else if .Enum }}types.String
{{- else}}any /* MISSING TYPE */
{{- end -}}
{{- if not . }}any /* ERROR */
{{- else if .IsExternal }}{{.Package.Name}}.{{.PascalName}}
{{- else if .IsAny}}any
{{- else if .IsEmpty}}[]{{.PascalName}}
{{- else if .IsString}}types.String
{{- else if .IsBool}}types.Bool
{{- else if .IsInt64}}types.Int64
{{- else if .IsFloat64}}types.Float64
{{- else if .IsInt}}types.Int64
{{- else if .IsByteStream}}io.ReadCloser
{{- else if .ArrayValue }}
{{- if .ArrayValue.IsObject }}{{template "type" .ArrayValue}}
{{- else }}[]{{template "type" .ArrayValue}}
{{- end }}
{{- else if .MapValue }}map[string]{{template "type" .MapValue}}
{{- else if .IsObject }}[]{{.PascalName}}
{{- else if .Enum }}types.String
{{- else}}any /* MISSING TYPE */
{{- end -}}
{{- end -}}
56 changes: 56 additions & 0 deletions .github/workflows/external-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: PR Comment

# WARNING:
# THIS WORKFLOW ALWAYS RUNS FOR EXTERNAL CONTRIBUTORS WITHOUT ANY APPROVAL.
# THIS WORKFLOW RUNS FROM MAIN BRANCH, NOT FROM THE PR BRANCH.
# DO NOT PULL THE PR OR EXECUTE ANY CODE FROM THE PR.

on:
pull_request_target:
types: [opened, reopened, synchronize]
branches:
- main

jobs:
comment-on-pr:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- uses: actions/checkout@v4

- name: Delete old comments
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Delete previous comment if it exists
previous_comment_ids=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
--jq '.[] | select(.body | startswith("<!-- INTEGRATION_TESTS_MANUAL -->")) | .id')
echo "Previous comment IDs: $previous_comment_ids"
# Iterate over each comment ID and delete the comment
if [ ! -z "$previous_comment_ids" ]; then
echo "$previous_comment_ids" | while read -r comment_id; do
echo "Deleting comment with ID: $comment_id"
gh api "repos/${{ github.repository }}/issues/comments/$comment_id" -X DELETE
done
fi
- name: Comment on PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
run: |
gh pr comment ${{ github.event.pull_request.number }} --body \
"<!-- INTEGRATION_TESTS_MANUAL -->
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:
Trigger:
[go/deco-tests-run/terraform](https://go/deco-tests-run/terraform)
Inputs:
* PR number: ${{github.event.pull_request.number}}
* Commit SHA: \`${{ env.COMMIT_SHA }}\`
Checks will be approved automatically on success.
"
80 changes: 80 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Integration Tests

on:

pull_request:
types: [opened, synchronize]

merge_group:


jobs:
check-token:
name: Check secrets access
runs-on: ubuntu-latest
environment: "test-trigger-is"
outputs:
has_token: ${{ steps.set-token-status.outputs.has_token }}
steps:
- name: Check if DECO_WORKFLOW_TRIGGER_APP_ID is set
id: set-token-status
run: |
if [ -z "${{ secrets.DECO_WORKFLOW_TRIGGER_APP_ID }}" ]; then
echo "DECO_WORKFLOW_TRIGGER_APP_ID is empty. User has no access to secrets."
echo "::set-output name=has_token::false"
else
echo "DECO_WORKFLOW_TRIGGER_APP_ID is set. User has access to secrets."
echo "::set-output name=has_token::true"
fi
trigger-tests:
name: Trigger Tests
runs-on: ubuntu-latest
needs: check-token
if: github.event_name == 'pull_request' && needs.check-token.outputs.has_token == 'true'
environment: "test-trigger-is"

steps:
- uses: actions/checkout@v3

- name: Generate GitHub App Token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.DECO_WORKFLOW_TRIGGER_APP_ID }}
private-key: ${{ secrets.DECO_WORKFLOW_TRIGGER_PRIVATE_KEY }}
owner: ${{ secrets.ORG_NAME }}
repositories: ${{secrets.REPO_NAME}}

- name: Trigger Workflow in Another Repo
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
gh workflow run terraform-isolated-pr.yml -R ${{ secrets.ORG_NAME }}/${{secrets.REPO_NAME}} \
--ref main \
-f pull_request_number=${{ github.event.pull_request.number }} \
-f commit_sha=${{ github.event.pull_request.head.sha }}

# Statuses and checks apply to specific commits (by hash).
# Enforcement of required checks is done both at the PR level and the merge queue level.
# In case of multiple commits in a single PR, the hash of the squashed commit
# will not match the one for the latest (approved) commit in the PR.
# We auto approve the check for the merge queue for two reasons:
# * Queue times out due to duration of tests.
# * Avoid running integration tests twice, since it was already run at the tip of the branch before squashing.
auto-approve:
if: github.event_name == 'merge_group'
runs-on: ubuntu-latest
steps:
- name: Mark Check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gh api -X POST -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/${{ github.sha }} \
-f 'state=success' \
-f 'context=Integration Tests Check'
Loading

0 comments on commit 3f1e078

Please sign in to comment.