Skip to content

Commit

Permalink
Merge branch 'main' into speed-up-github-comments-hide3
Browse files Browse the repository at this point in the history
  • Loading branch information
jamengual authored Jan 19, 2025
2 parents 6b0868f + cfe9df7 commit 76cb5a0
Show file tree
Hide file tree
Showing 11 changed files with 567 additions and 35 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ ARG DEBIAN_TAG=12.8-slim@sha256:d365f4920711a9074c4bcd178e8f457ee59250426441ab2a
ARG GOLANG_TAG=1.23.4-alpine@sha256:c23339199a08b0e12032856908589a6d41a0dab141b8b3b21f156fc571a3f1d3

# renovate: datasource=github-releases depName=hashicorp/terraform versioning=hashicorp
ARG DEFAULT_TERRAFORM_VERSION=1.10.3
ARG DEFAULT_TERRAFORM_VERSION=1.10.4
# renovate: datasource=github-releases depName=opentofu/opentofu versioning=hashicorp
ARG DEFAULT_OPENTOFU_VERSION=1.8.8
# renovate: datasource=github-releases depName=open-policy-agent/conftest
ARG DEFAULT_CONFTEST_VERSION=0.56.0

# Stage 1: build artifact and download deps

FROM golang:${GOLANG_TAG} AS builder
FROM --platform=$BUILDPLATFORM golang:${GOLANG_TAG} AS builder

# These are automatically populated by Docker
ARG TARGETOS
ARG TARGETARCH

ARG ATLANTIS_VERSION=dev
ENV ATLANTIS_VERSION=${ATLANTIS_VERSION}
Expand Down Expand Up @@ -42,7 +46,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
COPY . /app
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X 'main.version=${ATLANTIS_VERSION}' -X 'main.commit=${ATLANTIS_COMMIT}' -X 'main.date=${ATLANTIS_DATE}'" -v -o atlantis .
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath -ldflags "-s -w -X 'main.version=${ATLANTIS_VERSION}' -X 'main.commit=${ATLANTIS_COMMIT}' -X 'main.date=${ATLANTIS_DATE}'" -v -o atlantis .

FROM debian:${DEBIAN_TAG} AS debian-base

Expand Down
36 changes: 33 additions & 3 deletions server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,25 @@ func TestGitHubWorkflowWithPolicyCheck(t *testing.T) {
{"exp-output-merge.txt"},
},
},
{
Description: "1 failing policy and 1 passing policy with --quiet-policy-checks",
RepoDir: "policy-checks-multi-projects",
ModifiedFiles: []string{"dir1/main.tf,", "dir2/main.tf"},
PolicyCheck: true,
ExpAutoplan: true,
ExpPolicyChecks: true,
ExpQuietPolicyChecks: true,
ExpQuietPolicyCheckFailure: true,
Comments: []string{
"atlantis apply",
},
ExpReplies: [][]string{
{"exp-output-autoplan.txt"},
{"exp-output-auto-policy-check-quiet.txt"},
{"exp-output-apply.txt"},
{"exp-output-merge.txt"},
},
},
{
Description: "failing policy without policies passing using extra args",
RepoDir: "policy-checks-extra-args",
Expand Down Expand Up @@ -1183,7 +1202,7 @@ func TestGitHubWorkflowWithPolicyCheck(t *testing.T) {
userConfig.EnablePolicyChecksFlag = c.PolicyCheck
userConfig.QuietPolicyChecks = c.ExpQuietPolicyChecks

ctrl, vcsClient, githubGetter, atlantisWorkspace := setupE2E(t, c.RepoDir, setupOption{})
ctrl, vcsClient, githubGetter, atlantisWorkspace := setupE2E(t, c.RepoDir, setupOption{userConfig: userConfig})

// Set the repo to be cloned through the testing backdoor.
repoDir, headSHA := initializeRepo(t, c.RepoDir)
Expand Down Expand Up @@ -1274,13 +1293,13 @@ type setupOption struct {
allowCommands []command.Name
disableAutoplan bool
disablePreWorkflowHooks bool
userConfig server.UserConfig
}

func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers.VCSEventsController, *vcsmocks.MockClient, *mocks.MockGithubPullGetter, *events.FileWorkspace) {
allowForkPRs := false
discardApprovalOnPlan := true
dataDir, binDir, cacheDir := mkSubDirs(t)

// Mocks.
e2eVCSClient := vcsmocks.NewMockClient()
e2eStatusUpdater := &events.DefaultCommitStatusUpdater{Client: e2eVCSClient}
Expand Down Expand Up @@ -1493,7 +1512,18 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers
pullUpdater := &events.PullUpdater{
HidePrevPlanComments: false,
VCSClient: e2eVCSClient,
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false),
MarkdownRenderer: events.NewMarkdownRenderer(
false, // gitlabSupportsCommonMark
false, // disableApplyAll
false, // disableApply
false, // disableMarkdownFolding
false, // disableRepoLocking
false, // enableDiffMarkdownFormat
"", // markdownTemplateOverridesDir
"atlantis", // executableName
false, // hideUnchangedPlanComments
opt.userConfig.QuietPolicyChecks, // quietPolicyChecks
),
}

autoMerger := &events.AutoMerger{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Ran Policy Check for 2 projects:

1. dir: `dir1` workspace: `default`
1. dir: `dir2` workspace: `default`
---

### 2. dir: `dir2` workspace: `default`
**Policy Check Failed**: Some policy sets did not pass.
#### Policy Set: `test_policy`
```diff
FAIL - <redacted plan file> - main - WARNING: Forbidden Resource creation is prohibited.

1 test, 0 passed, 0 warnings, 1 failure, 0 exceptions

```


#### Policy Approval Status:
```
policy set: test_policy: requires: 1 approval(s), have: 0.
```
* :heavy_check_mark: To **approve** this project, comment:
```shell
atlantis approve_policies -d dir2
```
* :put_litter_in_its_place: To **delete** this plan and lock, click [here](lock-url)
* :repeat: To re-run policies **plan** this project again by commenting:
```shell
atlantis plan -d dir2
```

---
* :heavy_check_mark: To **approve** all unapplied plans from this Pull Request, comment:
```shell
atlantis approve_policies
```
* :put_litter_in_its_place: To **delete** all plans and locks from this Pull Request, comment:
```shell
atlantis unlock
```
* :repeat: To re-run policies **plan** this project again by commenting:
```shell
atlantis plan
```
2 changes: 1 addition & 1 deletion server/events/command_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func setup(t *testing.T, options ...func(testConfig *TestConfig)) *vcsmocks.Mock
pullUpdater = &events.PullUpdater{
HidePrevPlanComments: false,
VCSClient: vcsClient,
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false),
MarkdownRenderer: events.NewMarkdownRenderer(false, false, false, false, false, false, "", "atlantis", false, false),
}

autoMerger = &events.AutoMerger{
Expand Down
23 changes: 15 additions & 8 deletions server/events/markdown_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type MarkdownRenderer struct {
markdownTemplates *template.Template
executableName string
hideUnchangedPlanComments bool
quietPolicyChecks bool
}

// commonData is data that all responses have.
Expand All @@ -72,6 +73,7 @@ type commonData struct {
EnableDiffMarkdownFormat bool
ExecutableName string
HideUnchangedPlanComments bool
QuietPolicyChecks bool
VcsRequestType string
}

Expand Down Expand Up @@ -131,11 +133,12 @@ type policyCheckResultsData struct {
}

type projectResultTmplData struct {
Workspace string
RepoRelDir string
ProjectName string
Rendered string
NoChanges bool
Workspace string
RepoRelDir string
ProjectName string
Rendered string
NoChanges bool
IsSuccessful bool
}

// Initialize templates
Expand All @@ -149,6 +152,7 @@ func NewMarkdownRenderer(
markdownTemplateOverridesDir string,
executableName string,
hideUnchangedPlanComments bool,
quietPolicyChecks bool,
) *MarkdownRenderer {
var templates *template.Template
templates, _ = template.New("").Funcs(sprig.TxtFuncMap()).ParseFS(templatesFS, "templates/*.tmpl")
Expand All @@ -166,6 +170,7 @@ func NewMarkdownRenderer(
markdownTemplates: templates,
executableName: executableName,
hideUnchangedPlanComments: hideUnchangedPlanComments,
quietPolicyChecks: quietPolicyChecks,
}
}

Expand All @@ -192,6 +197,7 @@ func (m *MarkdownRenderer) Render(ctx *command.Context, res command.Result, cmd
EnableDiffMarkdownFormat: m.enableDiffMarkdownFormat,
ExecutableName: m.executableName,
HideUnchangedPlanComments: m.hideUnchangedPlanComments,
QuietPolicyChecks: m.quietPolicyChecks,
VcsRequestType: vcsRequestType,
}

Expand Down Expand Up @@ -224,9 +230,10 @@ func (m *MarkdownRenderer) renderProjectResults(ctx *command.Context, results []

for _, result := range results {
resultData := projectResultTmplData{
Workspace: result.Workspace,
RepoRelDir: result.RepoRelDir,
ProjectName: result.ProjectName,
Workspace: result.Workspace,
RepoRelDir: result.RepoRelDir,
ProjectName: result.ProjectName,
IsSuccessful: result.IsSuccessful(),
}
if result.PlanSuccess != nil {
result.PlanSuccess.TerraformOutput = strings.TrimSpace(result.PlanSuccess.TerraformOutput)
Expand Down
Loading

0 comments on commit 76cb5a0

Please sign in to comment.