Skip to content

Commit

Permalink
chore: ci changes
Browse files Browse the repository at this point in the history
Signed-off-by: i4k <[email protected]>
  • Loading branch information
i4ki committed Sep 14, 2024
1 parent 2885121 commit cd06f35
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 39 deletions.
136 changes: 104 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,38 @@ 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 }}

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:
matrix:
os: ["ubuntu-20.04", "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 }}-go-${{matrix.go}}
message: |
## Preview of ${{ matrix.os }}/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 +53,103 @@ jobs:
tofu_wrapper: false
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Terramate
uses: terramate-io/terramate-action@v1

- 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 --parallel 20 --continue-on-error --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 }}/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 }}/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 }}/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 }}-go-${{matrix.go}}
path: pr-comment.txt

gh_integration_test:
name: GHA Integration Test
Expand All @@ -98,7 +171,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 +231,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
2 changes: 1 addition & 1 deletion makefiles/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fmt:
## lint code
.PHONY: lint
lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run ./...
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run .

## tidy up go modules
.PHONY: mod
Expand Down
10 changes: 4 additions & 6 deletions terramate.tm
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// Copyright 2023 Terramate GmbH
// SPDX-License-Identifier: MPL-2.0

# This file is here just to e2etest on Windows if the `terramate run` respects
# the `terramate.config.run.env.PATH` environment variable.
# This behavior is not tested in Go because it requires a lot of "unsafe"
# non-portable code.
# It's used by the `make test` implemented for Windows at ./makefiles/windows.mk

terramate {
config {
experiments = ["toml-functions", "scripts"]
Expand All @@ -21,6 +15,10 @@ terramate {
check_uncommitted = false
check_remote = false
}

cloud {
organization = "test"
}
}
}

Expand Down

0 comments on commit cd06f35

Please sign in to comment.