re-write build script with go so windows machine can run e2e test as long asmake and go have been installed.

This commit is contained in:
zjhe 2022-09-21 13:44:18 +08:00
Родитель c283b54e07
Коммит f3cf8747a6
5 изменённых файлов: 109 добавлений и 29 удалений

2
.github/workflows/build.yml поставляемый
Просмотреть файл

@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v3

7
.github/workflows/e2e.yaml поставляемый
Просмотреть файл

@ -11,16 +11,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v2
name: Checkout source code
- uses: actions/cache@v2
name: Cache plugin dir
with:
path: ~/.tflint.d/plugins
key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }}
- uses: terraform-linters/setup-tflint@v2
name: Setup TFLint
with:

Просмотреть файл

@ -7,18 +7,13 @@ e2e:
cd integration && go test && cd ../
prepare:clean
git clone https://github.com/hashicorp/terraform-provider-azurerm.git
rm -rf terraform-provider-azurerm/.git
sh scripts/inject.sh
go mod tidy
go mod vendor
go run install/main.go prepare
build: prepare
go build
install:build
mkdir -p ~/.tflint.d/plugins
mv ./tflint-ruleset-azurerm-ext ~/.tflint.d/plugins
install: prepare
go run install/main.go install
lint:
golint --set_exit_status $$(go list ./...)
@ -28,6 +23,6 @@ tools:
go install golang.org/x/lint/golint@latest
clean:
rm -rf ./terraform-provider-azurerm ./vendor
go run install/main.go clean
.PHONY: test e2e build install lint tools updateSubmodule
.PHONY: test e2e build install lint tools

102
install/main.go Normal file
Просмотреть файл

@ -0,0 +1,102 @@
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
func main() {
var cmds map[string]func() = map[string]func(){
"install": install,
"clean": clean,
"prepare": prepare,
}
cmd := os.Args[1]
cmds[cmd]()
}
func prepare() {
clean()
if err := exec.Command("git", "clone", "--depth", "1", "https://github.com/hashicorp/terraform-provider-azurerm.git").Run(); err != nil {
panic(err)
}
os.RemoveAll("./terraform-provider-azurerm/.git")
injectProviderCode()
if err := exec.Command("go", "mod", "tidy").Run(); err != nil {
panic(err.Error())
}
if err := exec.Command("go", "mod", "vendor").Run(); err != nil {
panic(err.Error())
}
}
func injectProviderCode() {
exist, err := exists("terraform-provider-azurerm/provider")
if err != nil {
panic(err)
}
if !exist {
copyInjectionCode()
}
}
func copyInjectionCode() {
_ = os.MkdirAll(filepath.Join("terraform-provider-azurerm", "provider"), os.ModePerm)
dir, err := os.ReadDir("provider")
if err != nil {
panic(err)
}
for _, file := range dir {
copyFile(filepath.Join("provider", file.Name()), filepath.Join("terraform-provider-azurerm", "provider", strings.TrimSuffix(file.Name(), ".tmp")))
}
}
func copyFile(src, dst string) {
bytesRead, err := os.ReadFile(src)
if err != nil {
panic(err)
}
err = os.WriteFile(dst, bytesRead, 0644)
if err != nil {
panic(err)
}
}
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
func clean() {
err := os.RemoveAll("./terraform-provider-azurerm")
if err != nil {
panic(err)
}
err = os.RemoveAll("./vendor")
if err != nil {
panic(err)
}
}
func install() {
outputDir := fmt.Sprintf("%s/.tflint.d/plugins", os.Getenv("HOME"))
if runtime.GOOS == "windows" {
baseDir := os.Getenv("USERPROFILE")
outputDir = fmt.Sprintf(`%s\.tflint.d\plugins`, baseDir)
}
_ = os.MkdirAll(outputDir, os.ModePerm)
cmd := exec.Command("go", "build", "-o", outputDir)
if err := cmd.Run(); err != nil {
panic(err)
}
}

Просмотреть файл

@ -1,12 +0,0 @@
package provider
import (
"fmt"
"testing"
)
func Test_Lun(t *testing.T) {
blockNameSeq := []string{"resource", "azurerm_container_group"}
schemaMap := GetArgSchema(blockNameSeq)
fmt.Println(schemaMap)
}