Skip to content

Commit 8b16277

Browse files
mvicknrclaude
andauthored
chore: Fix version (#8)
* chore: Fix version * chore: Use a temporary local tag for testing Co-Authored-By: Claude <[email protected]> * chore: Push test tag and cleanup after Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent ec36dd3 commit 8b16277

File tree

5 files changed

+114
-107
lines changed

5 files changed

+114
-107
lines changed

.github/workflows/test_action.yml

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
name: Action Test
22

33
permissions:
4-
contents: read
4+
contents: write
55

66
on:
77
push:
88
branches:
99
- '**'
1010

1111
jobs:
12-
test-agent-flow:
12+
setup-test-tag:
13+
name: Setup Test Tag
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout action repository
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Push temporary tag for testing
22+
run: |
23+
git config user.name "github-actions"
24+
git config user.email "[email protected]"
25+
git tag -f v0.0.0 HEAD
26+
git push -f origin v0.0.0
27+
28+
test-agent-flow-no-v-version:
29+
needs: setup-test-tag
1330
name: Test Agent Repository Flow
1431
runs-on: ubuntu-latest
1532
steps:
1633
- name: Checkout action repository
1734
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
1837

1938
- name: Run Agent Metadata Action (with configs)
2039
uses: ./
@@ -23,6 +42,23 @@ jobs:
2342
version: '0.0.0'
2443
cache: false
2544

45+
test-agent-flow-v-version:
46+
needs: setup-test-tag
47+
name: Test Agent Repository Flow with "v" prefixed version
48+
runs-on: ubuntu-latest
49+
steps:
50+
- name: Checkout action repository
51+
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
55+
- name: Run Agent Metadata Action (with configs)
56+
uses: ./
57+
with:
58+
agent-type: 'myagent'
59+
version: 'v0.0.0'
60+
cache: false
61+
2662
test-docs-flow:
2763
name: Test Documentation Flow (MDX Parsing)
2864
runs-on: ubuntu-latest
@@ -83,3 +119,18 @@ jobs:
83119
run: |
84120
cd ${{ env.TEMP_WORKSPACE }}
85121
${{ github.workspace }}/agent-metadata-action
122+
123+
cleanup-test-tag:
124+
name: Cleanup Test Tag
125+
runs-on: ubuntu-latest
126+
needs: [test-agent-flow-no-v-version, test-agent-flow-v-version, test-docs-flow]
127+
if: always()
128+
steps:
129+
- name: Checkout action repository
130+
uses: actions/checkout@v4
131+
132+
- name: Delete temporary tag
133+
run: |
134+
git config user.name "github-actions"
135+
git config user.email "[email protected]"
136+
git push origin :refs/tags/v0.0.0 || true

action.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ inputs:
66
required: false
77
default: ''
88
version:
9-
description: 'Agent version in strict semver format MAJOR.MINOR.PATCH (ex. 1.2.3)'
9+
description: 'Agent version in semver format (ex. 1.2.3 or v1.2.3). The action will prepend "v" if not present for tag checkout.'
1010
required: false
1111
default: ''
1212
cache:
@@ -16,10 +16,21 @@ inputs:
1616
runs:
1717
using: 'composite'
1818
steps:
19+
- name: Normalize version tag for checkout
20+
id: version
21+
shell: bash
22+
run: |
23+
VERSION="${{ inputs.version }}"
24+
if [[ -n "$VERSION" && ! "$VERSION" =~ ^v ]]; then
25+
echo "ref=v${VERSION}" >> $GITHUB_OUTPUT
26+
else
27+
echo "ref=${VERSION}" >> $GITHUB_OUTPUT
28+
fi
29+
1930
- name: Checkout repository
2031
uses: actions/checkout@v4
2132
with:
22-
ref: ${{ inputs.version }} # When ref is empty (as in docs scenario), this will default to checking out the commit that triggered the action
33+
ref: ${{ steps.version.outputs.ref }} # When ref is empty (as in docs scenario), this will default to checking out the commit that triggered the action
2334

2435
- name: Setup Go
2536
uses: actions/setup-go@v4

cmd/agent-metadata-action/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ func run() error {
3030
}
3131

3232
agentType := os.Getenv("INPUT_AGENT_TYPE")
33-
agentVersion, err := config.LoadVersion()
34-
if err != nil {
35-
return err
36-
}
33+
agentVersion := os.Getenv("INPUT_VERSION")
3734

3835
if agentType != "" && agentVersion != "" { // Scenario 1: Agent repo flow
3936
fmt.Println("::debug::Agent scenario")

internal/config/metadata.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,12 @@ package config
33
import (
44
"fmt"
55
"os"
6-
"regexp"
76

87
"agent-metadata-action/internal/github"
98
"agent-metadata-action/internal/models"
109
"agent-metadata-action/internal/parser"
1110
)
1211

13-
// semverPattern validates strict semantic versioning format: MAJOR.MINOR.PATCH (e.g., 1.2.3)
14-
// Does not allow prerelease identifiers or build metadata
15-
// @todo may need to revisit if tags used by teams don't match semver
16-
var semverPattern = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$`)
17-
1812
// LoadMetadataForAgents loads metadata with only version populated
1913
func LoadMetadataForAgents(version string) models.Metadata {
2014
return models.Metadata{
@@ -39,6 +33,11 @@ func LoadMetadataForDocs() ([]models.Metadata, error) {
3933
return nil, fmt.Errorf("failed to parse MDX file %s: %w", filepath, err)
4034
}
4135

36+
// Validate version is not blank
37+
if frontMatter.Version == "" {
38+
return nil, fmt.Errorf("version is required in metadata for file %s", filepath)
39+
}
40+
4241
metadataArray = append(metadataArray, models.Metadata{
4342
Version: frontMatter.Version,
4443
Features: frontMatter.Features,
@@ -54,16 +53,3 @@ func LoadMetadataForDocs() ([]models.Metadata, error) {
5453
}
5554
return metadataArray, nil
5655
}
57-
58-
// LoadVersion loads the version from INPUT_VERSION
59-
// Returns an error if a version is provided and it is not in valid X.Y.Z format
60-
func LoadVersion() (string, error) {
61-
version := os.Getenv("INPUT_VERSION")
62-
63-
// Validate strict semver format (X.Y.Z only)
64-
if version != "" && !semverPattern.MatchString(version) {
65-
return "", fmt.Errorf("invalid version format: %s (must be X.Y.Z format, e.g., 1.2.3)", version)
66-
}
67-
68-
return version, nil
69-
}

internal/config/metadata_test.go

Lines changed: 42 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,6 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
func TestLoadVersion_ValidFormats(t *testing.T) {
15-
tests := []struct {
16-
name string
17-
version string
18-
}{
19-
{
20-
name: "standard version",
21-
version: "1.2.3",
22-
},
23-
{
24-
name: "simple version",
25-
version: "1.0.0",
26-
},
27-
{
28-
name: "large numbers",
29-
version: "100.200.300",
30-
},
31-
{
32-
name: "zero version",
33-
version: "0.0.0",
34-
},
35-
}
36-
37-
for _, tt := range tests {
38-
t.Run(tt.name, func(t *testing.T) {
39-
t.Setenv("INPUT_VERSION", tt.version)
40-
41-
version, err := LoadVersion()
42-
require.NoError(t, err)
43-
assert.Equal(t, tt.version, version)
44-
})
45-
}
46-
}
47-
48-
func TestLoadVersion_InvalidFormats(t *testing.T) {
49-
tests := []struct {
50-
name string
51-
version string
52-
}{
53-
{
54-
name: "with v prefix",
55-
version: "v1.2.3",
56-
},
57-
{
58-
name: "with prerelease",
59-
version: "1.2.3-alpha",
60-
},
61-
{
62-
name: "with build metadata",
63-
version: "1.2.3+build",
64-
},
65-
{
66-
name: "two components",
67-
version: "1.2",
68-
},
69-
{
70-
name: "four components",
71-
version: "1.2.3.4",
72-
},
73-
{
74-
name: "leading zero",
75-
version: "01.2.3",
76-
},
77-
{
78-
name: "non-numeric",
79-
version: "abc",
80-
},
81-
}
82-
83-
for _, tt := range tests {
84-
t.Run(tt.name, func(t *testing.T) {
85-
t.Setenv("INPUT_VERSION", tt.version)
86-
87-
_, err := LoadVersion()
88-
assert.Error(t, err)
89-
assert.Contains(t, err.Error(), "invalid version format")
90-
})
91-
}
92-
}
93-
9414
func TestLoadMetadataForAgents(t *testing.T) {
9515
t.Setenv("INPUT_AGENT_TYPE", "myagenttype")
9616
t.Setenv("INPUT_VERSION", "1.2.3")
@@ -207,3 +127,45 @@ func TestLoadMetadata_NoMDXFiles_ReturnsEmptyMetadata(t *testing.T) {
207127
require.NoError(t, err)
208128
assert.Nil(t, metadata)
209129
}
130+
131+
func TestLoadMetadata_MDXFileWithBlankVersion_ReturnsError(t *testing.T) {
132+
// Create a temporary workspace
133+
tmpWorkspace := t.TempDir()
134+
135+
// Create the release notes directory structure
136+
releaseNotesDir := filepath.Join(tmpWorkspace, "src/content/docs/release-notes/agent-release-notes")
137+
err := os.MkdirAll(releaseNotesDir, 0755)
138+
require.NoError(t, err)
139+
140+
// Create test MDX file with blank version
141+
mdxContent := `---
142+
subject: Test Agent
143+
releaseDate: '2024-01-15'
144+
version: ""
145+
features:
146+
- New feature
147+
---
148+
149+
# Test Release Notes
150+
`
151+
152+
mdxFile := filepath.Join(releaseNotesDir, "test-agent.mdx")
153+
err = os.WriteFile(mdxFile, []byte(mdxContent), 0644)
154+
require.NoError(t, err)
155+
156+
// Mock GetChangedMDXFiles to return our test file
157+
originalFunc := github.GetChangedMDXFilesFunc
158+
github.GetChangedMDXFilesFunc = func() ([]string, error) {
159+
return []string{mdxFile}, nil
160+
}
161+
defer func() {
162+
github.GetChangedMDXFilesFunc = originalFunc
163+
}()
164+
165+
t.Setenv("GITHUB_WORKSPACE", tmpWorkspace)
166+
167+
// Load metadata - should fail due to blank version
168+
_, err = LoadMetadataForDocs()
169+
assert.Error(t, err)
170+
assert.Contains(t, err.Error(), "version is required")
171+
}

0 commit comments

Comments
 (0)