Skip to content

Commit

Permalink
Create releases suitable for publication to the Terraform Registry (#39)
Browse files Browse the repository at this point in the history
* fix panic when running unit tests

* add goreleaser config

* remove go mod tidy hook

* add release workfow

* restore website

* simplify makefile

* newlines
  • Loading branch information
bendrucker committed Oct 23, 2020
1 parent d19992e commit 718843f
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 83 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,47 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release
on:
push:
tags:
- 'v*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
-
name: Import GPG key
id: import_gpg
uses: paultyng/ghaction-import-gpg@v2.1.0
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48 changes: 48 additions & 0 deletions .goreleaser.yml
@@ -0,0 +1,48 @@
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
# usage by users in CI/CD systems like Terraform Cloud where
# they are unable to install libraries.
- CGO_ENABLED=0
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
ldflags:
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
goos:
- freebsd
- windows
- linux
- darwin
goarch:
- amd64
- '386'
- arm
- arm64
ignore:
- goos: darwin
goarch: '386'
binary: '{{ .ProjectName }}_v{{ .Version }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
checksum:
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
# if you are using this is a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
release:
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
49 changes: 5 additions & 44 deletions GNUmakefile
@@ -1,45 +1,6 @@
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
PKG_NAME=circleci
default: testacc

default: build

build: fmtcheck
go install

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 30m

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

fmt:
gofmt -s -w $(GOFMT_FILES)

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)


.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile
# Run acceptance tests
.PHONY: testacc
testacc:
TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m
Expand Up @@ -122,7 +122,7 @@ func TestAccCircleCIContextEnvironmentVariable_import_name(t *testing.T) {
ResourceName: "circleci_context_environment_variable.foo",
ImportStateId: fmt.Sprintf(
"%s/%s/%s",
testAccOrgProvider.Meta().(*Client).organization,
os.Getenv("CIRCLECI_ORGANIZATION"),
"terraform-test",
"VAR",
),
Expand Down
3 changes: 2 additions & 1 deletion circleci/resource_circleci_context_test.go
Expand Up @@ -2,6 +2,7 @@ package circleci

import (
"fmt"
"os"
"testing"

"github.com/CircleCI-Public/circleci-cli/api"
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestAccCircleCIContext_import_name(t *testing.T) {
ResourceName: "circleci_context.foo",
ImportStateId: fmt.Sprintf(
"%s/%s",
testAccOrgProvider.Meta().(*Client).organization,
os.Getenv("CIRCLECI_ORGANIZATION"),
"terraform-test",
),
ImportState: true,
Expand Down
24 changes: 0 additions & 24 deletions scripts/errcheck.sh

This file was deleted.

13 changes: 0 additions & 13 deletions scripts/gofmtcheck.sh

This file was deleted.

34 changes: 34 additions & 0 deletions website/docs/d/context.html.markdown
@@ -0,0 +1,34 @@
---
layout: "circleci"
page_title: "CircleCI: circleci_context"
sidebar_current: "docs-datasource-circleci-context"
description: |-
Get information about a CircleCI context.
---

# Data Source: circleci_context

Use this data source to get information about a CircleCI context.

~> **Note** This resource uses the CircleCI GraphQL API, which is not officially supported.

## Example Usage

```hcl
data "circleci_context" "build" {
name = "build"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Name of the context.
* `organization` - (Optional) Organization where the context is defined.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the context.
39 changes: 39 additions & 0 deletions website/docs/index.html.markdown
@@ -0,0 +1,39 @@
---
layout: "circleci"
page_title: "Provider: CircleCI"
sidebar_current: "docs-circleci-index"
description: |-
The CircleCI provider is used to to interact with the CircleCI API.
---

# CircleCI Provider

The CircleCI provider is used to interact with CircleCI API.

## Authentication

This provider requires a CircleCI API token in order to manage
resources.

## Example Usage

```hcl
provider "circleci" {
api_token = "${file("circleci_token")}"
vcs_type = "github"
organization = "my_org"
}
# Create a context
resource "circleci_context" "build" {
# ...
}
```

## Argument Reference

The following arguments are supported:

* `vcs_type` - (Required) The version control system, either "github" or "bitbucket".
* `api_token` - (Required) A CircleCI API token. This can also be set via the `CIRCLECI_TOKEN` environment variable.
* `organization` - (Optional) The organization where resources will be created. If unset, an organization must be provided with each resource.
46 changes: 46 additions & 0 deletions website/docs/r/context.html.markdown
@@ -0,0 +1,46 @@
---
layout: "circleci"
page_title: "CircleCI: circleci_context"
sidebar_current: "docs-resource-circleci-context"
description: |-
Manages CircleCI contexts.
---

# circleci_context

A CircleCI context is a named collection of environment variables that can be referenced in the configuration for workflows.

~> **Note** This resource uses the CircleCI GraphQL API, which is not officially supported.

## Example Usage

Basic usage:

```hcl
resource "circleci_context" "build" {
name = "build"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Name of the context.
* `organization` - (Optional) Organization where the context will be defined.

## Attributes Reference

* `id` - The ID of the context.

## Import

Contexts can be imported as `$organization/$context`, where "context" can be either a context name or ID. For example:

```shell
# name
terraform import circleci_context.build hashicorp/build

# id
terraform import circleci_context.build hashicorp/6d87b798-5edb-4d99-b424-ce73b43affb9
```

0 comments on commit 718843f

Please sign in to comment.