Skip to content

Commit 4f7871e

Browse files
committed
Merge branch 'main' into admin/presleyp/591
2 parents 98ec516 + 17848b3 commit 4f7871e

File tree

26 files changed

+419
-84
lines changed

26 files changed

+419
-84
lines changed

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea to improve coder
4+
title: "Feat: "
5+
labels: "new feature :sparkles:"
6+
---
7+
8+
## What is your suggestion?
9+
10+
## Why do you want this feature?
11+
12+
## Are there any workarounds to get this functionality today?
13+
14+
## Are you interested in submitting a PR for this?

.github/pull_request_template.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Help reviewers by listing the subtasks in this PR
2+
3+
Here's an example:
4+
5+
This PR adds a new feature to the CLI.
6+
7+
## Subtasks
8+
9+
- [x] added a test for feature
10+
11+
Fixes #345
12+
13+
-->

.github/workflows/coder.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ jobs:
177177
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
178178
run: go run scripts/datadog-cireport/main.go gotests.xml
179179

180-
- uses: codecov/codecov-action@v2
180+
- uses: codecov/codecov-action@v3
181181
if: github.actor != 'dependabot[bot]' && github.repository_owner == 'coder'
182182
with:
183183
token: ${{ secrets.CODECOV_TOKEN }}
@@ -262,7 +262,7 @@ jobs:
262262
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
263263
run: go run scripts/datadog-cireport/main.go gotests.xml
264264

265-
- uses: codecov/codecov-action@v2
265+
- uses: codecov/codecov-action@v3
266266
if: github.actor != 'dependabot[bot]' && github.repository_owner == 'coder'
267267
with:
268268
token: ${{ secrets.CODECOV_TOKEN }}
@@ -381,7 +381,7 @@ jobs:
381381
- run: yarn test:coverage
382382
working-directory: site
383383

384-
- uses: codecov/codecov-action@v2
384+
- uses: codecov/codecov-action@v3
385385
if: github.actor != 'dependabot[bot]' && github.repository_owner == 'coder'
386386
with:
387387
token: ${{ secrets.CODECOV_TOKEN }}
File renamed without changes.

cli/buildinfo/buildinfo_test.go renamed to buildinfo/buildinfo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/stretchr/testify/require"
77
"golang.org/x/mod/semver"
88

9-
"github.com/coder/coder/cli/buildinfo"
9+
"github.com/coder/coder/buildinfo"
1010
)
1111

1212
func TestBuildInfo(t *testing.T) {

cli/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/mattn/go-isatty"
1212
"github.com/spf13/cobra"
1313

14-
"github.com/coder/coder/cli/buildinfo"
14+
"github.com/coder/coder/buildinfo"
1515
"github.com/coder/coder/cli/cliui"
1616
"github.com/coder/coder/cli/config"
1717
"github.com/coder/coder/codersdk"

coderd/coderd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@ import (
77
"time"
88

99
"github.com/go-chi/chi/v5"
10+
"github.com/go-chi/render"
1011
"google.golang.org/api/idtoken"
1112

1213
chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
1314

1415
"cdr.dev/slog"
16+
"github.com/coder/coder/buildinfo"
1517
"github.com/coder/coder/coderd/awsidentity"
1618
"github.com/coder/coder/coderd/database"
1719
"github.com/coder/coder/coderd/gitsshkey"
1820
"github.com/coder/coder/coderd/httpapi"
1921
"github.com/coder/coder/coderd/httpmw"
22+
"github.com/coder/coder/codersdk"
2023
"github.com/coder/coder/site"
2124
)
2225

@@ -59,6 +62,15 @@ func New(options *Options) (http.Handler, func()) {
5962
Message: "👋",
6063
})
6164
})
65+
r.Route("/buildinfo", func(r chi.Router) {
66+
r.Get("/", func(rw http.ResponseWriter, r *http.Request) {
67+
render.Status(r, http.StatusOK)
68+
render.JSON(rw, r, codersdk.BuildInfoResponse{
69+
ExternalURL: buildinfo.ExternalURL(),
70+
Version: buildinfo.Version(),
71+
})
72+
})
73+
})
6274
r.Route("/files", func(r chi.Router) {
6375
r.Use(
6476
httpmw.ExtractAPIKey(options.Database, nil),

coderd/coderd_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
package coderd_test
22

33
import (
4+
"context"
45
"testing"
56

67
"go.uber.org/goleak"
8+
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/coder/coder/buildinfo"
12+
"github.com/coder/coder/coderd/coderdtest"
713
)
814

915
func TestMain(m *testing.M) {
1016
goleak.VerifyTestMain(m)
1117
}
18+
19+
func TestBuildInfo(t *testing.T) {
20+
t.Parallel()
21+
client := coderdtest.New(t, nil)
22+
buildInfo, err := client.BuildInfo(context.Background())
23+
require.NoError(t, err)
24+
require.Equal(t, buildinfo.ExternalURL(), buildInfo.ExternalURL, "external URL")
25+
require.Equal(t, buildinfo.Version(), buildInfo.Version, "version")
26+
}

codersdk/buildinfo.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package codersdk
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"net/http"
7+
)
8+
9+
// BuildInfoResponse contains build information for this instance of Coder.
10+
type BuildInfoResponse struct {
11+
// ExternalURL is a URL referencing the current Coder version. For production
12+
// builds, this will link directly to a release. For development builds, this
13+
// will link to a commit.
14+
ExternalURL string `json:"external_url"`
15+
// Version returns the semantic version of the build.
16+
Version string `json:"version"`
17+
}
18+
19+
// BuildInfo returns build information for this instance of Coder.
20+
func (c *Client) BuildInfo(ctx context.Context) (BuildInfoResponse, error) {
21+
res, err := c.request(ctx, http.MethodGet, "/api/v2/buildinfo", nil)
22+
if err != nil {
23+
return BuildInfoResponse{}, err
24+
}
25+
defer res.Body.Close()
26+
27+
if res.StatusCode != http.StatusOK {
28+
return BuildInfoResponse{}, readBodyAsError(res)
29+
}
30+
31+
var buildInfo BuildInfoResponse
32+
return buildInfo, json.NewDecoder(res.Body).Decode(&buildInfo)
33+
}

docs/SECURITY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Security Policy
2+
3+
Keeping your code secure is core to what we do. If you find a vulnerability,
4+
please send an email to security@coder.com, and our team will respond to you.

0 commit comments

Comments
 (0)