diff --git a/.github/workflows/go.yml b/.github/workflows/check.yml similarity index 55% rename from .github/workflows/go.yml rename to .github/workflows/check.yml index f3f2e79..18ed125 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/check.yml @@ -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: @@ -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 . \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe66eab..3baebee 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eb851e..b1116c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index e0f73eb..7732c63 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/planner.go b/planner.go index c90a85f..6edcb38 100644 --- a/planner.go +++ b/planner.go @@ -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}}}) diff --git a/terraform.go b/terraform.go index bfc23b4..de5d32c 100644 --- a/terraform.go +++ b/terraform.go @@ -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 { @@ -31,7 +32,6 @@ type changeAction string const ( noOp changeAction = "no-op" create changeAction = "create" - read changeAction = "read" update changeAction = "update" del changeAction = "delete" )