-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from buildpulse/tags
Support for adding tags to builds
- Loading branch information
Showing
7 changed files
with
173 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ func TestNewMetadata(t *testing.T) { | |
tests := []struct { | ||
name string | ||
envs map[string]string | ||
tags []string | ||
fixture string | ||
}{ | ||
{ | ||
|
@@ -192,7 +193,7 @@ func TestNewMetadata(t *testing.T) { | |
) | ||
|
||
version := &Version{Number: "v1.2.3", GoOS: "linux"} | ||
meta, err := NewMetadata(version, tt.envs, commitResolver, now, logger.New()) | ||
meta, err := NewMetadata(version, tt.envs, tt.tags, commitResolver, now, logger.New()) | ||
assert.NoError(t, err) | ||
|
||
yaml, err := meta.MarshalYAML() | ||
|
@@ -203,7 +204,7 @@ func TestNewMetadata(t *testing.T) { | |
} | ||
|
||
func TestNewMetadata_unsupportedProvider(t *testing.T) { | ||
_, err := NewMetadata(&Version{}, map[string]string{}, newCommitResolverStub(), time.Now, logger.New()) | ||
_, err := NewMetadata(&Version{}, map[string]string{}, []string{}, newCommitResolverStub(), time.Now, logger.New()) | ||
if assert.Error(t, err) { | ||
assert.Contains(t, err.Error(), "missing required environment variables") | ||
} | ||
|
@@ -241,7 +242,7 @@ func TestNewMetadata_customCheckName(t *testing.T) { | |
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
meta, err := NewMetadata(&Version{}, tt.envs, newCommitResolverStub(), time.Now, logger.New()) | ||
meta, err := NewMetadata(&Version{}, tt.envs, []string{}, newCommitResolverStub(), time.Now, logger.New()) | ||
assert.NoError(t, err) | ||
|
||
yaml, err := meta.MarshalYAML() | ||
|
@@ -254,3 +255,71 @@ func TestNewMetadata_customCheckName(t *testing.T) { | |
func newCommitResolverStub() CommitResolver { | ||
return NewStaticCommitResolver(&Commit{}, logger.New()) | ||
} | ||
|
||
func TestNewMetadata_appliesTags(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
envs map[string]string | ||
tags []string | ||
fixture string | ||
}{ | ||
{ | ||
name: "GitHubActions", | ||
envs: map[string]string{ | ||
"GITHUB_ACTIONS": "true", | ||
"GITHUB_ACTOR": "some-user", | ||
"GITHUB_BASE_REF": "refs/heads/main", | ||
"GITHUB_EVENT_NAME": "push", | ||
"GITHUB_HEAD_REF": "refs/heads/some-feature", | ||
"GITHUB_REF": "refs/heads/some-feature", | ||
"GITHUB_REPOSITORY": "some-owner/some-repo", | ||
"GITHUB_RUN_ATTEMPT": "1", | ||
"GITHUB_RUN_ID": "8675309", | ||
"GITHUB_RUN_NUMBER": "42", | ||
"GITHUB_SERVER_URL": "https://github.com", | ||
"GITHUB_SHA": "1f192ff735f887dd7a25229b2ece0422d17931f5", | ||
"GITHUB_WORKFLOW": "build", | ||
}, | ||
fixture: "./testdata/github_tags.yml", | ||
tags: []string{"tag1", "tag2"}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
now := func() time.Time { | ||
return time.Date(2020, 7, 11, 1, 2, 3, 0, time.UTC) | ||
} | ||
|
||
expected, err := os.ReadFile(tt.fixture) | ||
require.NoError(t, err) | ||
|
||
authoredAt, err := time.Parse(time.RFC3339, "2020-07-09T04:05:06-05:00") | ||
require.NoError(t, err) | ||
|
||
committedAt, err := time.Parse(time.RFC3339, "2020-07-10T07:08:09+13:00") | ||
require.NoError(t, err) | ||
|
||
commitResolver := NewStaticCommitResolver( | ||
&Commit{ | ||
AuthoredAt: authoredAt, | ||
AuthorEmail: "[email protected]", | ||
AuthorName: "Some Author", | ||
CommittedAt: committedAt, | ||
CommitterEmail: "[email protected]", | ||
CommitterName: "Some Committer", | ||
Message: "Some message", | ||
TreeSHA: "0da9df599c02da5e7f5058b7108dcd5e1929a0fe", | ||
}, | ||
logger.New(), | ||
) | ||
|
||
version := &Version{Number: "v1.2.3", GoOS: "linux"} | ||
meta, err := NewMetadata(version, tt.envs, tt.tags, commitResolver, now, logger.New()) | ||
assert.NoError(t, err) | ||
|
||
yaml, err := meta.MarshalYAML() | ||
assert.NoError(t, err) | ||
assert.Equal(t, string(expected), string(yaml)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
:authored_at: 2020-07-09T04:05:06-05:00 | ||
:author_email: [email protected] | ||
:author_name: Some Author | ||
:branch: some-feature | ||
:build_url: https://github.com/some-owner/some-repo/actions/runs/8675309/attempts/1 | ||
:check: github-actions | ||
:ci_provider: github-actions | ||
:commit_message: Some message | ||
:commit_metadata_source: Static | ||
:commit: 1f192ff735f887dd7a25229b2ece0422d17931f5 | ||
:committed_at: 2020-07-10T07:08:09+13:00 | ||
:committer_email: [email protected] | ||
:committer_name: Some Committer | ||
:repo_name_with_owner: some-owner/some-repo | ||
:reporter_os: linux | ||
:reporter_version: v1.2.3 | ||
:tags: | ||
- tag1 | ||
- tag2 | ||
:timestamp: 2020-07-11T01:02:03Z | ||
:tree: 0da9df599c02da5e7f5058b7108dcd5e1929a0fe | ||
:github_actor: some-user | ||
:github_base_ref: refs/heads/main | ||
:github_event_name: push | ||
:github_head_ref: refs/heads/some-feature | ||
:github_ref: refs/heads/some-feature | ||
:github_repo_url: https://github.com/some-owner/some-repo | ||
:github_run_attempt: 1 | ||
:github_run_id: 8675309 | ||
:github_run_number: 42 | ||
:github_workflow: build |