Skip to content

Commit

Permalink
Refine GitHub action
Browse files Browse the repository at this point in the history
* Update go report card upon release

* Run check action on pull requests

* Use golangci-lint in GitHub action

* Add separate job for Terraform version compatibility check

* Fix lint hints

- remove unused read changeAction
- use raw string in regexp.MustCompile

* Factor in test coverage for tf 0.11 version in github action
  • Loading branch information
mbode committed Dec 21, 2020
1 parent 30474f0 commit 73d38be
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 21 deletions.
77 changes: 68 additions & 9 deletions .github/workflows/go.yml → .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,74 @@
name: Go
on: [push]
name: Check
on: [push, pull_request]
jobs:


build:
name: Build
runs-on: ubuntu-latest

steps:

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go

- name: Install terraform
run: wget https://releases.hashicorp.com/terraform/0.13.5/terraform_0.13.5_linux_amd64.zip -O /tmp/terraform.zip && sudo unzip -o -d /usr/local/bin/ /tmp/terraform.zip

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: golangci-lint
uses: golangci/golangci-lint-action@v2.3.0
with:
version: v1.33

- name: Get dependencies
run: go get -v -t -d ./...

- name: Test
run: go test -v -cover -coverprofile=coverage.txt ./...

- name: Coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.txt

pre012:
name: pre012
runs-on: ubuntu-latest

steps:

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go

- name: Install terraform
run: wget https://releases.hashicorp.com/terraform/0.11.14/terraform_0.11.14_linux_amd64.zip -O /tmp/terraform.zip && sudo unzip -o -d /usr/local/bin/ /tmp/terraform.zip

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: go get -v -t -d ./...

- name: Test
run: go test -v -cover -coverprofile=coverage.txt ./...

- name: Coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.txt

terraform_version_compatibility:
name: Terraform compatibility
runs-on: ubuntu-latest
strategy:
matrix:
terraform:
Expand Down Expand Up @@ -85,12 +149,7 @@ jobs:
run: go get -v -t -d ./...

- name: Test
run: go test -v -cover -coverprofile=coverage.txt ./...
run: go test -v ./...

- name: Build
run: go build -v .

- name: Coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
run: go build -v .
14 changes: 8 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
-
name: Run GoReleaser

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

- name: Update Go report card
uses: creekorful/goreportcard-action@v1.0
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.3.0] - 2020-10-04
### Added
- Delay flag to prevent hitting rate limits with remote state (contributed by [@xanonid](https://github.com/xanonid))
- Flags for verbose output and dry-run mode (contributed by [@xanonid](https://github.com/xanonid)
- Flags for verbose output and dry-run mode (contributed by [@xanonid](https://github.com/xanonid))

## [0.2.0] - 2020-09-30
### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/mbode/terraform-state-mover)](https://goreportcard.com/report/github.com/mbode/terraform-state-mover)
[![Actions Status](https://github.com/mbode/terraform-state-mover/workflows/Go/badge.svg)](https://github.com/mbode/terraform-state-mover/actions)
[![Actions Status](https://github.com/mbode/terraform-state-mover/workflows/Check/badge.svg)](https://github.com/mbode/terraform-state-mover/actions)
[![codecov](https://codecov.io/gh/mbode/terraform-state-mover/branch/master/graph/badge.svg)](https://codecov.io/gh/mbode/terraform-state-mover)
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=mbode/terraform-state-mover)](https://dependabot.com)
[![License](https://img.shields.io/github/license/mbode/terraform-state-mover)](https://github.com/mbode/terraform-state-mover/blob/master/LICENSE)
Expand Down
4 changes: 2 additions & 2 deletions planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func changes(cfg config, args []string) ([]ResChange, error) {
}
stdoutBytes := stdout.Bytes()
var changes []ResChange
for _, res := range regexp.MustCompile("(?m)\\+ (.*)$").FindAllSubmatch(stdoutBytes, -1) {
for _, res := range regexp.MustCompile(`(?m)\+ (.*)$`).FindAllSubmatch(stdoutBytes, -1) {
address := string(res[1])
parts := strings.Split(address, ".")
changes = append(changes, ResChange{address, parts[len(parts)-2], Change{[]changeAction{create}}})
}
for _, res := range regexp.MustCompile("(?m)- (.*)$").FindAllSubmatch(stdoutBytes, -1) {
for _, res := range regexp.MustCompile(`(?m)- (.*)$`).FindAllSubmatch(stdoutBytes, -1) {
address := string(res[1])
parts := strings.Split(address, ".")
changes = append(changes, ResChange{address, parts[len(parts)-2], Change{[]changeAction{del}}})
Expand Down
4 changes: 2 additions & 2 deletions terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"bytes"
"fmt"
go_version "github.com/hashicorp/go-version"
"os"
"os/exec"
"regexp"
"strings"

go_version "github.com/hashicorp/go-version"
)

type resChanges struct {
Expand All @@ -31,7 +32,6 @@ type changeAction string
const (
noOp changeAction = "no-op"
create changeAction = "create"
read changeAction = "read"
update changeAction = "update"
del changeAction = "delete"
)
Expand Down

0 comments on commit 73d38be

Please sign in to comment.