Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use script run for running tests and linter. #1410

Closed
wants to merge 6 commits into from
Closed
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
117 changes: 0 additions & 117 deletions .github/workflows/ci.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2024 Terramate GmbH
# SPDX-License-Identifier: MPL-2.0

name: Terramate Deployment
on:
push:
branches:
- main

jobs:
deploy:
name: Run all tests and create a Terramate Cloud Deployment

permissions:
id-token: write
contents: read
pull-requests: read

runs-on: "ubuntu-20.04"

steps:
### Check out the code

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

### Install tooling

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

- name: check cloud info
run: terramate run --tags golang --no-recursive -- ./bin/terramate cloud info || true
env:
TMC_API_HOST: api.stg.terramate.io

### Check for changed stacks

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

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

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

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

- name: check and test all
if: steps.list.outputs.stdout
run: terramate script run --parallel=5 --changed --tags=golang -- test deploy
env:
TMC_API_HOST: api.stg.terramate.io
GITHUB_TOKEN: ${{ github.token }}
166 changes: 166 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Copyright 2023 Terramate GmbH
# SPDX-License-Identifier: MPL-2.0

name: preview

on:
pull_request:
branches:
- main

jobs:
preview:
name: Changed Terramate stacks
runs-on: ${{ matrix.os }}

permissions:
id-token: write
contents: read
pull-requests: write

strategy:
matrix:
os: ["ubuntu-20.04", "macos-12", "macos-13"]
go: ["1.22"]

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

### Create Pull Request comment

- name: Prepare pull request preview comment
if: github.event.pull_request
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: preview
message: |
## Preview of Project changes in ${{ github.event.pull_request.head.sha }}

:warning: preview is being created... please stand by!

### Install tooling

- name: Install Terramate
uses: terramate-io/terramate-action@i4k-fix-macos

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

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

- name: checking go mod tidyness
if: steps.list.outputs.stdout && matrix.os == 'ubuntu-20.04'
run: make mod/check

- name: linting code
if: steps.list.outputs.stdout && matrix.os == 'ubuntu-20.04'
run: make lint

- name: checking license on source code
if: steps.list.outputs.stdout && matrix.os == 'ubuntu-20.04'
run: make license/check

### Run the terramate preview script

- name: check cloud info
if: steps.list.outputs.stdout
run: terramate run --tags golang --no-recursive -- terramate cloud info || true
env:
TMC_API_HOST: api.stg.terramate.io

- name: Golang test preview
if: steps.list.outputs.stdout
run: |
echo >preview_url.txt "https://cloud.stg.terramate.io/o/test/review-requests"
terramate script run --parallel=10 --tags golang --changed -- test preview
env:
TMC_API_HOST: api.stg.terramate.io
GITHUB_TOKEN: ${{ github.token }}

### Update Pull Request comment

- name: Generate preview details
shell: bash
if: steps.list.outputs.stdout
id: comment
run: |
echo >>pr-comment.txt "## Preview of Terramate changes 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: Generate preview when no stacks changed
shell: bash
if: success() && !steps.list.outputs.stdout
run: |
echo >>pr-comment.txt "## Preview of Terramate changes 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: Generate preview when things failed
shell: bash
if: failure()
run: |
echo >>pr-comment.txt "## Preview of Terraform changes 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 in Actions output.'
cat pr-comment.txt >>$GITHUB_STEP_SUMMARY

- name: Publish generated preview as GitHub commnent
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: preview
path: pr-comment.txt

release_dry_run:
name: Release Dry Run

runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0

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

- name: release dry run
run: make release/dry-run

required_checks:
needs:
- preview
runs-on: ubuntu-20.04
steps:
- uses: Kesin11/actions-timeline@v1
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'

Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
terramate 0.4.0
terramate 0.5.0
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 = "deployment"
description = "deployment"
tags = ["golang"]
id = "3705120e-4f6f-42a6-9c45-5a1ff31110da"
}
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 = "drift"
description = "drift"
tags = ["golang"]
id = "8e7c2d56-0a76-42b7-b6c6-a9e85ba3f17e"
}
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 = "cloud"
description = "cloud"
tags = ["golang"]
id = "22a16004-771d-433f-9732-be34e6f3ffbb"
}
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 = "stack"
description = "stack"
tags = ["golang"]
id = "8b514d12-9d03-4fbd-8c1b-4c43207abc0f"
}
Loading
Loading