Skip to content

Commit

Permalink
chore: use scripts + TMC sync in CI tests.
Browse files Browse the repository at this point in the history
Signed-off-by: i4k <[email protected]>
  • Loading branch information
i4ki committed Sep 15, 2024
1 parent e5c04cd commit 54eba82
Show file tree
Hide file tree
Showing 107 changed files with 975 additions and 61 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.tm linguist-language=HCL
* text=auto
_*.tf text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/ci-experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: make build

- name: make generate
run: make generate
run: make generate && git diff

- name: make test
run: make test
152 changes: 118 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,43 @@ on:
pull_request:

jobs:
checks:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: build Terramate
run: make build

- name: checking go mod tidyness
run: ./bin/terramate run --tags golang --changed -- make mod/check

- name: linting code
run: ./bin/terramate run --tags golang --changed -- make lint

- name: checking license on source code
run: ./bin/terramate run --tags golang --changed -- make license/check

build_test:
name: Build and Test
runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.os.value }}

permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
pull-requests: write
checks: read

strategy:
fail-fast: false
matrix:
os: ["ubuntu-20.04", "macos-13"]
os:
- name: ubuntu-focal
value: "ubuntu-20.04"
- name: macos-ventura
value: "macos-13"
go: ["1.21"]

steps:
- name: Prepare pull request comment
if: github.event.pull_request
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: preview-${{ matrix.os.name }}-go-${{matrix.go}}
message: |
## Preview of ${{ matrix.os.name }}/go${{matrix.go}} tests in ${{ github.event.pull_request.head.sha }}
:warning: being created... please stand by!
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
Expand All @@ -63,20 +58,110 @@ jobs:
tofu_wrapper: false
github_token: ${{ secrets.GITHUB_TOKEN }}

- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.7.5"
terraform_wrapper: false

- name: Install Terramate
uses: terramate-io/terramate-action@i4k-fix-macos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: build Terramate
run: make build
run: make build && cp -v ./bin/terramate /usr/local/bin/terramate-bin

- name: make generate
run: make generate

- name: make test
### Check for changed stacks

- name: List changed stacks
id: list
run: terramate list --tags golang --changed

### Linting

- name: linting code
if: steps.list.outputs.stdout
run: make lint

- name: checking go mod tidyness
if: steps.list.outputs.stdout
run: make mod/check

- name: checking license on source code
if: steps.list.outputs.stdout
run: make license/check

- name: Check Terramate formatting
run: terramate fmt --check

- name: Check Terraform formatting
if: steps.list.outputs.stdout
run: terraform fmt -recursive -check -diff

### Run the Terramate tests and create a Cloud Preview

- name: Temporary PR Preview Link generation
run: echo >preview_url.txt "https://cloud.terramate.io/o/terramate/review-requests"

- name: Run Terraform preview on changed
if: steps.list.outputs.stdout
timeout-minutes: 30
run: ./bin/terramate run --tags golang --changed -- make test
run: terramate script run --tags golang --target ${{ matrix.os.name }} --parallel 12 --changed preview
env:
GITHUB_TOKEN: ${{ github.token }}
TM_TEST_TERRAFORM_REQUIRED_VERSION: "1.7.5"

- name: check cloud info
run: ./bin/terramate run --tags golang --changed -- ./bin/terramate -vv experimental cloud info
### Update Pull Request comment

- name: Generate Preview Comment
if: steps.list.outputs.stdout
id: comment
run: |
echo >>pr-comment.txt "## Preview of ${{ matrix.os.name }}/go${{matrix.go}} tests in ${{ github.event.pull_request.head.sha }}"
echo >>pr-comment.txt
echo >>pr-comment.txt "[:mag: View Details on Terramate Cloud]($(cat preview_url.txt))"
echo >>pr-comment.txt
echo >>pr-comment.txt "### Changed Stacks"
echo >>pr-comment.txt
echo >>pr-comment.txt '```bash'
echo >>pr-comment.txt "${{ steps.list.outputs.stdout }}"
echo >>pr-comment.txt '```'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
- name: Inform about no Changed Stacks
if: success() && !steps.list.outputs.stdout
run: |
echo >>pr-comment.txt "## Preview of ${{ matrix.os.name }}/go${{matrix.go}} tests in ${{ github.event.pull_request.head.sha }}"
echo >>pr-comment.txt
echo >>pr-comment.txt "### Changed Stacks"
echo >>pr-comment.txt
echo >>pr-comment.txt 'No changed stacks, no detailed preview will be generated.'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
- name: Inform about failure
if: failure()
run: |
echo >>pr-comment.txt "## Preview of ${{ matrix.os.name }}/go${{matrix.go}} tests in ${{ github.event.pull_request.head.sha }}"
echo >>pr-comment.txt
echo >>pr-comment.txt "[:mag: View Details on Terramate Cloud]($(cat preview_url.txt))"
echo >>pr-comment.txt
echo >>pr-comment.txt "### Changed Stacks"
echo >>pr-comment.txt
echo >>pr-comment.txt '```bash'
echo >>pr-comment.txt "${{ steps.list.outputs.stdout }}"
echo >>pr-comment.txt '```'
echo >>pr-comment.txt ":boom: Generating preview failed. [Please see details on Terramate Cloud]($(cat preview_url.txt))"
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY
- name: Publish Plans for Changed Stacks
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: preview-${{ matrix.os.name }}-go-${{matrix.go}}
path: pr-comment.txt

gh_integration_test:
name: GHA Integration Test
Expand All @@ -98,7 +183,7 @@ jobs:
run: make build

- name: make test/ci
run: ./bin/terramate run --tags golang --changed -- make test/ci
run: make test/ci

release_dry_run:
name: Release Dry Run
Expand Down Expand Up @@ -158,7 +243,6 @@ jobs:
cosign verify-blob --key cosign.pub --signature ${{ env.SIGNATURE_FILE }} ${{ env.CHECKSUM_FILE }}
ci:
needs:
- checks
- build_test
- gh_integration_test
runs-on: ubuntu-20.04
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coverage.txt
cpu.prof
mem.prof
*.test
*.tfplan
*.plan

# Go Workspaces artifacts
Expand Down
6 changes: 6 additions & 0 deletions _test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "terramate"
filename = "${path.module}/mock.ignore"
}
6 changes: 6 additions & 0 deletions cloud/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package cloud // import \"github.com/terramate-io/terramate/cloud\""
filename = "${path.module}/mock.ignore"
}
6 changes: 6 additions & 0 deletions cloud/deployment/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package deployment // import \"github.com/terramate-io/terramate/cloud/deployment\""
filename = "${path.module}/mock.ignore"
}
9 changes: 9 additions & 0 deletions cloud/deployment/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package deployment // import \"github.com/terramate-io/terramate/cloud/deployment\""
description = "package deployment // import \"github.com/terramate-io/terramate/cloud/deployment\""
tags = ["cloud", "deployment", "golang"]
id = "8f7fced1-1649-4c71-bdb1-5d861141a953"
}
6 changes: 6 additions & 0 deletions cloud/drift/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package drift // import \"github.com/terramate-io/terramate/cloud/drift\""
filename = "${path.module}/mock.ignore"
}
9 changes: 9 additions & 0 deletions cloud/drift/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package drift // import \"github.com/terramate-io/terramate/cloud/drift\""
description = "package drift // import \"github.com/terramate-io/terramate/cloud/drift\""
tags = ["cloud", "drift", "golang"]
id = "feadf9e7-6cee-4f5e-9f75-a91c98ce4679"
}
6 changes: 6 additions & 0 deletions cloud/preview/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package preview // import \"github.com/terramate-io/terramate/cloud/preview\""
filename = "${path.module}/mock.ignore"
}
9 changes: 9 additions & 0 deletions cloud/preview/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package preview // import \"github.com/terramate-io/terramate/cloud/preview\""
description = "package preview // import \"github.com/terramate-io/terramate/cloud/preview\""
tags = ["cloud", "golang", "preview"]
id = "90d86bc8-5cac-4576-9241-cfa9f9adc93d"
}
9 changes: 9 additions & 0 deletions cloud/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package cloud // import \"github.com/terramate-io/terramate/cloud\""
description = "package cloud // import \"github.com/terramate-io/terramate/cloud\""
tags = ["cloud", "golang"]
id = "1d457835-4401-4ed9-bbbf-d4676c0e9b0c"
}
6 changes: 6 additions & 0 deletions cloud/stack/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package stack // import \"github.com/terramate-io/terramate/cloud/stack\""
filename = "${path.module}/mock.ignore"
}
9 changes: 9 additions & 0 deletions cloud/stack/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package stack // import \"github.com/terramate-io/terramate/cloud/stack\""
description = "package stack // import \"github.com/terramate-io/terramate/cloud/stack\""
tags = ["cloud", "golang", "stack"]
id = "6b9cce64-2b44-43ed-bb2c-dc9525dd2585"
}
6 changes: 6 additions & 0 deletions cloud/testserver/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package testserver // import \"github.com/terramate-io/terramate/cloud/testserver\""
filename = "${path.module}/mock.ignore"
}
6 changes: 6 additions & 0 deletions cloud/testserver/cloudstore/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package cloudstore // import \"github.com/terramate-io/terramate/cloud/testserver/cloudstore\""
filename = "${path.module}/mock.ignore"
}
9 changes: 9 additions & 0 deletions cloud/testserver/cloudstore/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package cloudstore // import \"github.com/terramate-io/terramate/cloud/testserver/cloudstore\""
description = "package cloudstore // import \"github.com/terramate-io/terramate/cloud/testserver/cloudstore\""
tags = ["cloud", "cloudstore", "golang", "testserver"]
id = "264e8e28-bddc-4244-a2c9-9dfb4e9cfd33"
}
9 changes: 9 additions & 0 deletions cloud/testserver/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package testserver // import \"github.com/terramate-io/terramate/cloud/testserver\""
description = "package testserver // import \"github.com/terramate-io/terramate/cloud/testserver\""
tags = ["cloud", "golang", "testserver"]
id = "6f6e494b-d500-4024-95ef-b273f459b61c"
}
6 changes: 6 additions & 0 deletions cmd/terramate/cli/cliconfig/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package cliconfig // import \"github.com/terramate-io/terramate/cmd/terramate/cli/cliconfig\""
filename = "${path.module}/mock.ignore"
}
9 changes: 9 additions & 0 deletions cmd/terramate/cli/cliconfig/stack.tm.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright 2024 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

stack {
name = "package cliconfig // import \"github.com/terramate-io/terramate/cmd/terramate/cli/cliconfig\""
description = "package cliconfig // import \"github.com/terramate-io/terramate/cmd/terramate/cli/cliconfig\""
tags = ["cli", "cliconfig", "cmd", "golang", "terramate"]
id = "d9636c0a-f69c-47c7-8657-9ff5cdc454f3"
}
4 changes: 2 additions & 2 deletions cmd/terramate/cli/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const (

// newCloudRequiredError creates an error indicating that a cloud login is required to use requested features.
func newCloudRequiredError(requestedFeatures []string) *errors.DetailedError {
err := errors.D("This command uses Terramate Cloud features and requires you to be logged in.")
err := errors.D(clitest.CloudLoginRequiredMessage)

for _, s := range requestedFeatures {
err = err.WithDetailf(verbosity.V1, "%s", s)
Expand Down Expand Up @@ -195,7 +195,7 @@ func (c *cli) cloudEnabled() bool {
}

func (c *cli) disableCloudFeatures(err error) {
log.Warn().Err(err).Msg(clitest.CloudDisablingMessage)
printer.Stderr.WarnWithDetails(clitest.CloudDisablingMessage, errors.E(err.Error()))

c.cloud.disabled = true
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/terramate/cli/github/_test_mock.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TERRAMATE: GENERATED AUTOMATICALLY DO NOT EDIT

resource "local_file" "foo" {
content = "package github // import \"github.com/terramate-io/terramate/cmd/terramate/cli/github\""
filename = "${path.module}/mock.ignore"
}
Loading

0 comments on commit 54eba82

Please sign in to comment.