diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b2ac510 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,41 @@ +on: + push: + tags: + - "*" +name: Release + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.16.x + + - name: Cache golang artifacts + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..cb176a8 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,36 @@ +on: [push] +name: Test + +jobs: + run-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Install Go + uses: actions/setup-go@v3 + with: + go-version: 1.16.x + + - name: Cache golang artifacts + uses: actions/cache@v3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Ensure up to date deps + run: go mod tidy && git diff --no-patch --exit-code + + - name: Setup environment + run: make install + + - name: Test + run: make test + + - name: Build + run: make build diff --git a/.gitignore b/.gitignore index 46174b1..48a1c2b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /terraform-provider-sql + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..de59eb6 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,39 @@ +before: + hooks: + - go mod tidy +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + ignore: + - goos: windows + goarch: arm64 + +archives: + - format: gz + name_template: >- + {{ .ProjectName }}_{{- .Os }}_{{ .Arch }} + format_overrides: + - goos: windows + format: zip + # https://goreleaser.com/customization/archive/#packaging-only-the-binaries + # we have to package the binaries only to maintain backwards compatibility with + # the old release system + files: + - none* +checksum: + name_template: "checksums.txt" +snapshot: + name_template: "{{ incpatch .Version }}-next" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index aec9b23..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -os: linux -dist: bionic -language: go -go: - - "1.16" - -cache: - directories: - - "$GOPATH/pkg/mod" - -install: - - make install - -script: - - make test - - make build - -before_deploy: - - make build-release - -deploy: - provider: releases - api_key: - secure: Fn1MdiXY2fi5jPwQMjp9T/oxW6slwaM1OkHifYFjEN1EoX5J5IZcNB74YGEyJpxNtbX9Mr1yxMbmr2LEVluCaQ29CRiVvauTE5qsdKOTzlTc8QX4D+cJY5xFchfAbmLAZ287RkH8JaFLjjk0rV3ZmJ+WyWNXYhTuOloZmeXmwJyZ/ZiJ0f70K3x641JkL5mIOvpDbNG93tVu2rXsKd5LALNmbtr3wPNOr2zqmYc9pF9GpfznGQugIyvCDqmfuXZrNHixBQXs6yZYCTn3jsiZcbfeHRj4Bpoy5AHudDrsRf0hfB5NUEDyP2vgoOt4LpygrmvpAUxL5jI8sZc03BjnkDguth0NZyJXMYVmU02wYHYYswzLIfwYpGZWAiVdYBz9lnLKrif2PwMAzhb/QRsvDKM3Hpv6/cHofCYptFHL0pzrMENTFICgnWnzKYdedUnlX4a2I0VWFqpGZv9IXhjxWqzZk2+DSMHR2i1G1g4tdoeDT9UabNaTfwPdwedXoXq7yn11gk2CVUjiTe5+yeOQ2HlNYyK44cqB9kyRJQSVNkm3cSm+NrSAJc6/G9YRJTngrY5jKcxQ8m7ZByYl6Gh/xVj/Vf+DikI5ILLMaqwRz16oWEI2RBMaVa7Vve4Xq0S8t0DWeLtR2DUvFGJWSIiwzJhJqj+pZNgl4pYhyP1hifo= - file_glob: true - file: pkg/* - skip_cleanup: true - on: - tags: true diff --git a/Makefile b/Makefile index 6405424..7592be1 100644 --- a/Makefile +++ b/Makefile @@ -30,20 +30,6 @@ help: build: go build -build-release-file: - @GOOS=$(OS) GOARCH=$(ARCH) go build -o $(PKGDIR)/terraform-provider-sql_$(OS)_$(ARCH) . - @gzip $(PKGDIR)/terraform-provider-sql_$(OS)_$(ARCH) - -build-release: - @rm -rf $(PKGDIR) - @mkdir $(PKGDIR) - @for os in windows darwin linux ; do \ - make build-release-file OS=$$os ARCH=amd64 ; \ - done - @for os in darwin linux ; do \ - make build-release-file OS=$$os ARCH=arm64 ; \ - done - test: go test $(TEST) -v $(TESTARGS) diff --git a/sql/resource_sql_schema_test.go b/sql/resource_sql_schema_test.go index 46ddb95..66966c6 100644 --- a/sql/resource_sql_schema_test.go +++ b/sql/resource_sql_schema_test.go @@ -9,22 +9,24 @@ import ( _sql "database/sql" + _ "github.com/snowflakedb/gosnowflake" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" "github.com/stretchr/testify/assert" ) func TestIdFromDataSource(t *testing.T) { - if result, err := idFromDataSource("dialict", "dialect://username:password@host?parameters"); assert.NoError(t, err) { + if result, err := idFromDataSource("dialect", "dialect://username:password@host?parameters"); assert.NoError(t, err) { assert.Equal(t, "dialect://@host", result) } - if result, err := idFromDataSource("dialict", "dialect://username:password@host"); assert.NoError(t, err) { + if result, err := idFromDataSource("dialect", "dialect://username:password@host"); assert.NoError(t, err) { assert.Equal(t, "dialect://@host", result) } - if result, err := idFromDataSource("dialict", "dialect://username:@host"); assert.NoError(t, err) { + if result, err := idFromDataSource("dialect", "dialect://username:@host"); assert.NoError(t, err) { assert.Equal(t, "dialect://@host", result) } - if result, err := idFromDataSource("dialict", "dialect://@host"); assert.NoError(t, err) { + if result, err := idFromDataSource("dialect", "dialect://@host"); assert.NoError(t, err) { assert.Equal(t, "dialect://@host", result) } if result, err := idFromDataSource("dialect", "not connection string"); assert.NoError(t, err) {