Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(update-schemas): commit message description #1903

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .github/workflows/update-schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ jobs:
with:
go-version-file: go.mod
- run: go install golang.org/x/tools/cmd/goimports@latest
- uses: arduino/setup-task@v2
- id: update
run: make schemas-update
- run: make update-schemas
- id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- id: changes
Expand All @@ -33,16 +31,16 @@ jobs:
with:
author: GitHub <noreply@github.com>
body-path: changes.out
branch: update/${{ steps.date.outputs.date }}-${{ github.run_id }}
commit-message: "chore(update): update schemas (${{ steps.date.outputs.date }})"
title: "chore(update): update schemas (${{ steps.date.outputs.date }})"
branch: update-schemas/${{ steps.date.outputs.date }}-${{ github.run_id }}
commit-message: "chore(update-schemas): ${{ steps.date.outputs.date }}"
title: "chore(update-schemas): ${{ steps.date.outputs.date }}"
labels: |
dependencies
- name: Close previous update PRs
- name: Close previous update schemas PRs
if: steps.create_pr.outputs.pull-request-operation == 'created'
run: |
new_pr_number=${{ steps.create_pr.outputs.pull-request-number }}
prs=$(gh pr list --state open --json number,headRefName --jq '.[] | select(.headRefName | startswith("update/")) | .number')
prs=$(gh pr list --state open --json number,headRefName --jq '.[] | select(.headRefName | startswith("update-schemas/")) | .number')
for pr in $prs; do
if [ "$pr" != "$new_pr_number" ]; then
gh pr close $pr --comment "Auto-closing pull request in favor of #$new_pr_number" --delete-branch
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,19 @@ docs: $(TFPLUGINDOCS)

OLD_SCHEMA ?= .oldSchema.json
CHANGELOG := PROVIDER_AIVEN_ENABLE_BETA=1 go run ./changelog/...
schemas-update:
dump-schemas:
$(CHANGELOG) -save -schema=$(OLD_SCHEMA)
go get github.com/aiven/go-client-codegen@latest github.com/aiven/go-api-schemas@latest
go mod tidy
$(MAKE) generate

diff-schemas:
$(CHANGELOG) -diff -schema=$(OLD_SCHEMA) -changelog=CHANGELOG.md
rm $(OLD_SCHEMA)

load-schemas:
go get github.com/aiven/go-client-codegen@latest github.com/aiven/go-api-schemas@latest
go mod tidy

update-schemas: dump-schemas load-schemas generate diff-schemas

#################################################
# CI
#################################################
Expand Down
20 changes: 11 additions & 9 deletions changelog/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type changelogItem struct {
var (
reVersion = regexp.MustCompile(`\w+\.\w+\.\w+`)
reDate = regexp.MustCompile(`\w{4}-\w{2}-\w{2}`)
reSplitEntries = regexp.MustCompile(`(?m)^(\b[^a-z]| *- +)`) // A line that begins with "-" or a non-letter
reSplitEntries = regexp.MustCompile(`(?m)^(\b[^a-z]| *- +)`) // A line that begins with "-" or a non-lowercase letter
reBulletLevel = regexp.MustCompile(`^ *- +`)
reSpaces = regexp.MustCompile(`\s+`)
reTrailingSpace = regexp.MustCompile(`\s+$`)
Expand All @@ -30,7 +30,7 @@ var (
// Soft-wraps lines to the given lineLength
// When reformat is true, reformats the whole given content
func updateChangelog(content string, lineLength int, reformat bool, addLines ...string) (string, error) {
if addLines == nil && !reformat {
if len(addLines) == 0 && !reformat {
return content, nil
}

Expand All @@ -41,13 +41,13 @@ func updateChangelog(content string, lineLength int, reformat bool, addLines ...
if len(items) != 0 && items[0].Version == draftVersion {
// Appends to the current draft
items[0].Content = fmt.Sprintf("%s\n%s", items[0].Content, addText)
} else {
} else if addText != "" {
// The First item is not the draft, so we need to add a new item
items = append(items, &changelogItem{
items = append([]*changelogItem{{
Version: draftVersion,
Date: draftDate,
Content: content,
})
Content: addText,
}}, items...)
}

result := lines[:start]
Expand All @@ -65,8 +65,7 @@ func updateChangelog(content string, lineLength int, reformat bool, addLines ...
}

func parseItems(lines []string) ([]*changelogItem, int, int) {
start := max(0, len(lines)-1)
end := start
var start, end int
var item *changelogItem
items := make([]*changelogItem, 0)
for i, line := range lines {
Expand All @@ -93,7 +92,6 @@ func parseItems(lines []string) ([]*changelogItem, int, int) {
}

func formatContent(content string, lineLength int) string {

// Golang doesn't support regexp "lookarounds", so we need to split the content,
// and then join it to keep what we otherwise would be just ignored by negative lookbehind
seps := reSplitEntries.FindAllStringSubmatchIndex(content, -1)
Expand Down Expand Up @@ -127,6 +125,10 @@ func formatContent(content string, lineLength int) string {
}
}

if len(list) == 0 {
return content
}

return strings.Join(list, "\n")
}

Expand Down
64 changes: 63 additions & 1 deletion changelog/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,74 @@ const testSampleExpected = `# Changelog
for all user config options.
`

func TestFormatChangelog(t *testing.T) {
func TestUpdateChangelog(t *testing.T) {
result, err := updateChangelog(testSample, 60, true, "foo", "bar", "Use TypeSet for ip_filter_object")
require.NoError(t, err)
assert.Empty(t, cmp.Diff(testSampleExpected, result))
}

func TestUpdateChangelog_nothing_to_change(t *testing.T) {
sample := `---
title: Changelog
parent: README
nav_order: 1
---

# Changelog

<!-- Always keep the following header in place: -->
<!--## [MAJOR.MINOR.PATCH] - YYYY-MM-DD -->

## [4.29.0] - 2024-11-14

- Add support for autoscaler service integration
`
result, err := updateChangelog(sample, 60, false)
require.NoError(t, err)
assert.Empty(t, cmp.Diff(sample, result))
}

func TestUpdateChangelog_empty_changelog(t *testing.T) {
sample := `---
title: Changelog
parent: README
nav_order: 1
---

# Changelog

<!-- Always keep the following header in place: -->
<!--## [MAJOR.MINOR.PATCH] - YYYY-MM-DD -->

## [4.29.0] - 2024-11-14

- Add support for autoscaler service integration
`
expect := `---
title: Changelog
parent: README
nav_order: 1
---

# Changelog

<!-- Always keep the following header in place: -->
<!--## [MAJOR.MINOR.PATCH] - YYYY-MM-DD -->

## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

- Foo
- Bar

## [4.29.0] - 2024-11-14

- Add support for autoscaler service integration
`
result, err := updateChangelog(sample, 60, false, "Foo", "Bar")
require.NoError(t, err)
assert.Empty(t, cmp.Diff(expect, result))
}

func TestLineWrapping(t *testing.T) {
input := `Add capability to map external service user with internal aiven user with external_identity data source`
expectList := []string{
Expand Down