Skip to content

Commit e3f10c1

Browse files
authored
add gh action workflow to mirror circle ci (#468)
Migrate the circle ci workflow to gh actions
1 parent 4413d04 commit e3f10c1

File tree

9 files changed

+131
-121
lines changed

9 files changed

+131
-121
lines changed

.circleci/config.yml

Lines changed: 0 additions & 102 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish JUnit Tests
2+
description: Publishes JUnit tests to one or more sources
3+
inputs:
4+
files:
5+
required: true
6+
description: The JUnit files to upload
7+
name:
8+
required: true
9+
description: The name of the suite
10+
datadog:
11+
required: false
12+
description: Upload to Datadog
13+
default: 'true'
14+
github:
15+
required: false
16+
description: Upload to GitHub
17+
default: 'true'
18+
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Report Tests to Datadog
23+
shell: bash
24+
if: ${{ inputs.datadog }} == 'true'
25+
run: datadog-ci junit upload --service ${{ inputs.name }} ${{ inputs.files }}
26+
27+
- name: Test Publish
28+
uses: phoenix-actions/test-reporting@f957cd93fc2d848d556fa0d03c57bc79127b6b5e # v15
29+
if: ${{ inputs.github }} == 'true'
30+
with:
31+
name: ${{ inputs.name }}
32+
output-to: step-summary
33+
path: ${{ inputs.files }}
34+
reporter: java-junit
35+
fail-on-error: 'false'

.github/workflows/main.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Test and Generate Docs
2+
3+
on: pull_request
4+
5+
jobs:
6+
go-tests:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout Code
11+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
12+
13+
- name: Set up Go
14+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
15+
with:
16+
go-version-file: go.mod
17+
18+
- name: Install datadog-ci
19+
run: npm install -g @datadog/datadog-ci
20+
21+
- name: Install Dependencies
22+
run: |
23+
go install github.com/jstemmer/go-junit-report@v1.0.0
24+
go install github.com/kyoh86/richgo@v0.3.10
25+
go install gotest.tools/gotestsum@latest
26+
27+
- name: Install golangci-lint
28+
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
29+
with:
30+
version: v1.62.2
31+
32+
- name: Run tests with gotestsum
33+
run: |
34+
mkdir -p ${{ github.workspace }}/artifacts
35+
mkdir -p ${{ github.workspace }}/reports
36+
gotestsum --packages="./..." \
37+
--junitfile ${{ github.workspace }}/reports/go-test_go_tests.xml \
38+
--jsonfile ${{ github.workspace }}/artifacts/go-test_go_tests.json \
39+
--rerun-fails=2 \
40+
--rerun-fails-max-failures=10 \
41+
--rerun-fails-report ${{ github.workspace }}/artifacts/rerun_tests_go_tests.txt
42+
43+
- name: Publish JUnit Tests
44+
uses: ./.github/actions/publish-junit
45+
env:
46+
DD_API_KEY: ${{ secrets.DATADOG_API_KEY }}
47+
with:
48+
files: ${{ github.workspace }}/reports/go-test_go_tests.xml
49+
name: find-code-references-in-pull-request
50+
datadog: 'true'
51+
github: 'true'
52+
53+
github-actions-docs:
54+
runs-on: ubuntu-latest
55+
steps:
56+
- name: Checkout Code
57+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
58+
59+
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
60+
with:
61+
node-version: 20
62+
63+
- name: Install action-docs
64+
run: npm install action-docs
65+
66+
- uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
67+
with:
68+
extra_args: github-action-docs --all-files

build/package/github-actions/github-actions.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
o "github.com/launchdarkly/ld-find-code-refs/v2/options"
1515
)
1616

17+
const (
18+
millisecondsInSecond = 1000 // Descriptive constant for milliseconds conversion
19+
)
20+
1721
func main() {
1822
log.Init(false)
1923
dir := os.Getenv("GITHUB_WORKSPACE")
@@ -55,7 +59,7 @@ func mergeGithubOptions(opts o.Options) (o.Options, error) {
5559
if event != nil {
5660
repoUrl = event.Repo.Url
5761
defaultBranch = event.Repo.DefaultBranch
58-
updateSequenceId = int(time.Now().Unix() * 1000) // seconds to ms
62+
updateSequenceId = int(time.Now().Unix() * millisecondsInSecond) // seconds to ms
5963
}
6064

6165
opts.RepoType = "github"

internal/git/git.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ import (
2121
"github.com/launchdarkly/ld-find-code-refs/v2/internal/log"
2222
)
2323

24+
const (
25+
// ... other constants ...
26+
millisecondsInSecond = 1000 // Descriptive constant for milliseconds conversion
27+
)
28+
2429
type Client struct {
2530
workspace string
2631
GitBranch string
@@ -227,7 +232,7 @@ type CommitData struct {
227232
}
228233

229234
// FindExtinctions searches commit history for flags that had references removed recently
230-
func (c Client) FindExtinctions(project options.Project, flags []string, matcher search.Matcher, lookback int) ([]ld.ExtinctionRep, error) {
235+
func (c *Client) FindExtinctions(project options.Project, flags []string, matcher search.Matcher, lookback int) ([]ld.ExtinctionRep, error) {
231236
commits, err := getCommits(c.workspace, lookback)
232237
if err != nil {
233238
return nil, err
@@ -327,7 +332,7 @@ func makeExtinctionRepFromCommit(projectKey, flagKey string, commit *object.Comm
327332
return ld.ExtinctionRep{
328333
Revision: commit.Hash.String(),
329334
Message: commit.Message,
330-
Time: commit.Author.When.Unix() * 1000,
335+
Time: commit.Author.When.Unix() * millisecondsInSecond,
331336
ProjKey: projectKey,
332337
FlagKey: flagKey,
333338
}
@@ -342,9 +347,8 @@ func getCommits(workspace string, lookback int) ([]CommitData, error) {
342347
if err != nil {
343348
return nil, err
344349
}
345-
346350
commits := []CommitData{}
347-
for i := 0; i < lookback; i++ {
351+
for range make([]struct{}, lookback) {
348352
commit, err := logResult.Next()
349353
if err != nil {
350354
// reached end of commit tree

internal/ld/ld.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
apiVersionHeader = "LD-API-Version"
4545
v2ApiPath = "/api/v2"
4646
reposPath = "/code-refs/repositories"
47+
shortShaLength = 7 // Descriptive constant for SHA length
4748
)
4849

4950
type ConfigurationError struct {
@@ -76,8 +77,8 @@ func IsTransient(err error) bool {
7677
// Fallback to default backoff if header can't be parsed
7778
// https://apidocs.launchdarkly.com/#section/Overview/Rate-limiting
7879
// Method is curried in order to avoid stubbing the time package and fallback Backoff in unit tests
79-
func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(time.Duration, time.Duration, int, *http.Response) time.Duration {
80-
return func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
80+
func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(minDuration, _ time.Duration, attemptNum int, resp *http.Response) time.Duration {
81+
return func(minDuration, max2 time.Duration, attemptNum int, resp *http.Response) time.Duration {
8182
if resp != nil {
8283
if resp.StatusCode == http.StatusTooManyRequests {
8384
if s, ok := resp.Header["X-Ratelimit-Reset"]; ok {
@@ -95,7 +96,7 @@ func RateLimitBackoff(now func() time.Time, fallbackBackoff h.Backoff) func(time
9596
}
9697
}
9798

98-
return fallbackBackoff(min, max, attemptNum, resp)
99+
return fallbackBackoff(minDuration, max2, attemptNum, resp)
99100
}
100101
}
101102

@@ -108,7 +109,7 @@ func InitApiClient(options ApiOptions) ApiClient {
108109
if options.RetryMax != nil && *options.RetryMax >= 0 {
109110
client.RetryMax = *options.RetryMax
110111
}
111-
client.Backoff = RateLimitBackoff(time.Now, h.LinearJitterBackoff)
112+
client.Backoff = RateLimitBackoff(time.Now, h.LinearJitterBackoff) //nolint:bodyclose
112113

113114
return ApiClient{
114115
httpClient: client,
@@ -192,7 +193,7 @@ func (c ApiClient) getProjectEnvironment(projKey string) (*ldapi.Environment, er
192193
}
193194

194195
func (c ApiClient) getFlags(projKey string, params url.Values) ([]ldapi.FeatureFlag, error) {
195-
url := c.getPath(fmt.Sprintf("/flags/%s", projKey))
196+
url := c.getPath(fmt.Sprintf("/flags/%s", projKey)) //nolint:perfsprint
196197
req, err := h.NewRequest(http.MethodGet, url, nil)
197198
if err != nil {
198199
return nil, err
@@ -441,7 +442,7 @@ type ldErrorResponse struct {
441442

442443
func (c ApiClient) do(req *h.Request) (*http.Response, error) {
443444
req.Header.Set("Authorization", c.Options.ApiKey)
444-
req.Header.Set(apiVersionHeader, apiVersion)
445+
req.Header.Set(apiVersionHeader, apiVersion) //nolint:canonicalheader
445446
req.Header.Set("User-Agent", c.Options.UserAgent)
446447
req.Header.Set("Content-Type", "application/json")
447448
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
@@ -550,8 +551,8 @@ func (b BranchRep) TotalHunkCount() int {
550551
func (b BranchRep) WriteToCSV(outDir, projKey, repo, sha string) (path string, err error) {
551552
// Try to create a filename with a shortened sha, but if the sha is too short for some unexpected reason, use the branch name instead
552553
var tag string
553-
if len(sha) >= 7 {
554-
tag = sha[:7]
554+
if len(sha) >= shortShaLength {
555+
tag = sha[:shortShaLength]
555556
} else {
556557
tag = b.Name
557558
}
@@ -577,7 +578,7 @@ func (b BranchRep) WriteToCSV(outDir, projKey, repo, sha string) (path string, e
577578
// sort csv by flag key
578579
sort.Slice(records, func(i, j int) bool {
579580
// sort by flagKey -> path -> startingLineNumber
580-
for k := 0; k < 3; k++ {
581+
for k := range [3]int{} {
581582
if records[i][k] != records[j][k] {
582583
return records[i][k] < records[j][k]
583584
}

options/flags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Allowed template variables: 'branchName', 'sha'. If "commitUrlTemplate" is not p
4545
{
4646
name: "contextLines",
4747
short: "C",
48-
defaultValue: 2,
48+
defaultValue: 2, //nolint:mnd
4949
usage: `The number of context lines to send to LaunchDarkly. If < 0, no
5050
source code will be sent to LaunchDarkly. If 0, only the lines containing
5151
flag references will be sent. If > 0, will send that number of context
@@ -94,7 +94,7 @@ LaunchDarkly API is unreachable or returns an unexpected response.`,
9494
{
9595
name: "lookback",
9696
short: "l",
97-
defaultValue: 10,
97+
defaultValue: 10, //nolint:mnd
9898
usage: `Sets the number of git commits to search in history for
9999
whether a feature flag was removed from code. May be set to 0 to disabled this feature. Setting this option to a high value will increase search time.`,
100100
},

options/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (o Options) ValidateRequired() error {
195195
}
196196

197197
if len(o.ProjKey) > 0 && len(o.Projects) > 0 {
198-
return fmt.Errorf("`--projKey` cannot be combined with `projects` in configuration")
198+
return errors.New("`--projKey` cannot be combined with `projects` in configuration")
199199
}
200200

201201
if len(o.ProjKey) > maxProjKeyLength {
@@ -263,7 +263,7 @@ func (o Options) Validate() error {
263263
}
264264

265265
if o.Revision != "" && o.Branch == "" {
266-
return fmt.Errorf(`"branch" option is required when "revision" option is set`)
266+
return errors.New(`"branch" option is required when "revision" option is set`)
267267
}
268268

269269
if len(o.Projects) > 0 {

search/matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func buildElementPatterns(flags []string, delimiters string) map[string][]string
8383
for _, left := range delimiters {
8484
for _, right := range delimiters {
8585
var sb strings.Builder
86-
sb.Grow(len(flag) + 2)
86+
sb.Grow(len(flag) + 2) //nolint:mnd
8787
sb.WriteRune(left)
8888
sb.WriteString(flag)
8989
sb.WriteRune(right)

0 commit comments

Comments
 (0)