Skip to content

Commit ef2b845

Browse files
committed
Merge remote-tracking branch 'origin/develop' into merschformann/generalize-golden-script-tests
2 parents c9c41a3 + d2e8e46 commit ef2b845

File tree

13 files changed

+186
-131
lines changed

13 files changed

+186
-131
lines changed

.github/workflows/go-lint.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
jobs:
77
sdk-go-lint:
88
runs-on: ubuntu-latest
9+
env:
10+
GO_VERSION: 1.24
911
# Use a matrix strategy to test all the modules simultaneously.
1012
strategy:
1113
fail-fast: false
@@ -22,12 +24,6 @@ jobs:
2224
- name: git clone
2325
uses: actions/checkout@v4
2426

25-
- name: determine Go version
26-
run: |
27-
export GO_VERSION=$(cat workflow-configuration.yml | yq '.go-version' -r)
28-
echo "Using Go version $GO_VERSION"
29-
echo "GO_VERSION=${GO_VERSION}" >> $GITHUB_ENV
30-
3127
- name: set up go
3228
uses: actions/setup-go@v5
3329
with:

.github/workflows/go-test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
jobs:
77
sdk-go-build-test:
88
runs-on: ubuntu-latest
9+
env:
10+
GO_VERSION: 1.24
911
# Use a matrix strategy to test all the modules simultaneously.
1012
strategy:
1113
fail-fast: false
@@ -23,13 +25,6 @@ jobs:
2325
- name: git clone
2426
uses: actions/checkout@v4
2527

26-
# Determines the Go version to use.
27-
- name: determine Go version
28-
run: |
29-
export GO_VERSION=$(cat workflow-configuration.yml | yq '.go-version' -r)
30-
echo "Using Go version $GO_VERSION"
31-
echo "GO_VERSION=${GO_VERSION}" >> $GITHUB_ENV
32-
3328
# Sets up Go with the version set before.
3429
- name: set up go
3530
uses: actions/setup-go@v5

.github/workflows/release.yml

Lines changed: 27 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,32 @@
11
name: release
2+
run-name: Release by @${{ github.actor }} from ${{ github.ref_name }}
23

3-
on:
4-
workflow_dispatch:
5-
inputs:
6-
VERSION:
7-
description: "The version to release"
8-
required: true
9-
IS_PRE_RELEASE:
10-
description: "It IS a pre-release"
11-
required: true
12-
default: true
13-
type: boolean
4+
on: [push]
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
149

1510
jobs:
1611
release:
17-
runs-on: ubuntu-latest
18-
env:
19-
VERSION: ${{ inputs.VERSION }}
20-
GH_TOKEN: ${{ github.token }}
21-
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
22-
permissions:
23-
contents: write
24-
steps:
25-
- name: ensure proper tagging
26-
run: |
27-
echo "If it's a pre-release, the version should contain a hyphen"
28-
if [ ${{ inputs.IS_PRE_RELEASE }} = true ]; then
29-
if [[ $VERSION != *-* ]]; then
30-
echo "Pre-release versions should contain a hyphen"
31-
exit 1
32-
fi
33-
else
34-
if [[ $VERSION == *-* ]]; then
35-
echo "Release versions should not contain a hyphen"
36-
exit 1
37-
fi
38-
fi
39-
40-
- name: configure git and clone
41-
run: |
42-
mkdir -p ~/.ssh
43-
ssh-keyscan github.com >> ~/.ssh/known_hosts
44-
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
45-
ssh-add - <<< "${{ secrets.NEXTMVBOT_SSH_KEY }}"
46-
47-
echo "${{ secrets.NEXTMVBOT_SIGNING_KEY }}" > ~/.ssh/signing.key
48-
chmod 600 ~/.ssh/signing.key
49-
50-
git config --global user.name "nextmv-bot"
51-
git config --global user.email "[email protected]"
52-
git config --global gpg.format ssh
53-
git config --global user.signingkey ~/.ssh/signing.key
54-
55-
git clone [email protected]:nextmv-io/sdk.git
56-
57-
cd sdk
58-
git checkout ${{ github.ref_name }}
59-
60-
git rev-parse --short HEAD
61-
62-
- name: determine Go version
63-
run: |
64-
export GO_VERSION=$(cat workflow-configuration.yml | yq '.go-version' -r)
65-
echo "Using Go version $GO_VERSION"
66-
echo "GO_VERSION=${GO_VERSION}" >> $GITHUB_ENV
67-
working-directory: ./sdk
68-
69-
- name: set up Go
70-
uses: actions/setup-go@v5
71-
with:
72-
go-version: ${{ env.GO_VERSION }}
73-
cache-dependency-path: |
74-
**/go.sum
75-
**/go.mod
76-
77-
- name: push release tag
78-
run: |
79-
git tag -s $VERSION -m "Release $VERSION"
80-
git push origin $VERSION
81-
working-directory: ./sdk
82-
83-
- name: bump and tag nested modules
84-
run: |
85-
export MODULES=$(cat workflow-configuration.yml | yq '.nested_modules[]' -r)
86-
for module in $MODULES; do
87-
echo "Bumping $module to $VERSION"
88-
pushd $module
89-
go get github.com/nextmv-io/sdk@$VERSION
90-
go mod tidy
91-
popd
92-
done
93-
git add --all
94-
git commit -S -m "Bump nested modules to $VERSION"
95-
git push
96-
for module in $MODULES; do
97-
git tag -s $module/$VERSION -m "Release $module/$VERSION"
98-
git push origin $module/$VERSION
99-
done
100-
working-directory: ./sdk
101-
102-
- name: create release
103-
run: |
104-
PRERELEASE_FLAG=""
105-
if [ ${{ inputs.IS_PRE_RELEASE }} = true ]; then
106-
PRERELEASE_FLAG="--prerelease"
107-
fi
108-
109-
gh release create $VERSION \
110-
--verify-tag \
111-
--generate-notes \
112-
--title $VERSION $PRERELEASE_FLAG
113-
working-directory: ./sdk
114-
115-
- name: notify slack
116-
if: ${{ inputs.IS_PRE_RELEASE == false }}
117-
run: |
118-
export DATA="{\"text\":\"Release notification - sdk $VERSION (see <https://github.com/nextmv-io/sdk/releases/$VERSION|release notes>)\"}"
119-
curl -X POST -H 'Content-type: application/json' --data "$DATA" ${{ secrets.SLACK_URL_MISSION_CONTROL }}
12+
if: ${{ github.ref_type == 'branch' }}
13+
uses: nextmv-io/release/.github/workflows/release.yml@develop
14+
with:
15+
BRANCH: ${{ github.ref_name }}
16+
REPOSITORY: sdk
17+
LANGUAGE: go
18+
PACKAGE_NAME: sdk
19+
PACKAGE_LOCATION: ./
20+
VERSION_FILE: VERSION
21+
POST_RELEASE_COMMAND: bash .nextmv/post-release.sh
22+
secrets: inherit
23+
24+
notify:
25+
needs: [release]
26+
if: ${{ needs.release.outputs.RELEASE_NEEDED == 'true' && needs.release.outputs.SHOULD_NOTIFY_SLACK == 'true' }}
27+
uses: nextmv-io/release/.github/workflows/notify-slack.yml@develop
28+
with:
29+
PACKAGE_NAME: sdk
30+
VERSION: ${{ needs.release.outputs.VERSION }}
31+
REPOSITORY: sdk
32+
secrets: inherit

.nextmv/post-release.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export MODULES=$(cat "$(dirname "$0")/workflow-configuration.yml" | yq '.nested_modules[]' -r)
2+
3+
git checkout -b feature/bump-nested-$VERSION
4+
5+
for module in $MODULES; do
6+
echo "Bumping $module to $VERSION"
7+
pushd $module
8+
go get github.com/nextmv-io/sdk@$VERSION
9+
go mod tidy
10+
git add go.mod go.sum
11+
popd
12+
done
13+
14+
git commit -S -m "Bump nested modules after $VERSION release"
15+
git push origin --set-upstream feature/bump-nested-$VERSION
16+
17+
OUTPUT=$(gh pr create --base $BRANCH --title "Bump nested modules after $VERSION release" --body "Automated bump of nested modules to version $VERSION")
18+
19+
echo "# :rocket: PR created" >> $GITHUB_STEP_SUMMARY
20+
echo "" >> $GITHUB_STEP_SUMMARY
21+
echo "Bump nested modules :arrow_right: [PR Link](${OUTPUT})." >> $GITHUB_STEP_SUMMARY
File renamed without changes.

RELEASE.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Release
2+
3+
A reusable workflow is used to release the package. Nextmv team members: please
4+
go to the corresponding repository for more information.
5+
6+
## Stable release
7+
8+
Open a PR against the `develop` branch with the following change:
9+
10+
* Update the version in the `VERSION` file.
11+
12+
After the PR is merged, the `release.yml` workflow will be triggered and it
13+
will automatically create a release.
14+
15+
After the release is created, a new PR will be opened bumping the nested
16+
modules to the new version. Make sure you approve and merge this new PR.
17+
18+
## Pre-release
19+
20+
Update the version in the `VERSION` file to a dev tag. When a commit is pushed,
21+
the `release.yml` workflow will be triggered and it will automatically create a
22+
release.
23+
24+
After the release is created, a new PR will be opened bumping the nested
25+
modules to the new version. Make sure you approve and merge this new PR.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.9.3

golden/dag.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package golden
33
import (
44
"fmt"
55
"path/filepath"
6+
7+
"strings"
68
"sync"
79
"testing"
810
)
@@ -44,6 +46,13 @@ func DagTest(t *testing.T, cases []DagTestCase) {
4446
t.Fatal(err)
4547
}
4648

49+
// Print the DAG as a Mermaid diagram for visualization.
50+
mermaid, err := dagToMermaid(cases)
51+
if err != nil {
52+
t.Fatal("error converting DAG to Mermaid format: ", err)
53+
}
54+
t.Logf("DAG diagram (mermaid):\n%s", mermaid)
55+
4756
open := cases
4857
done := make(map[string]bool)
4958

@@ -152,3 +161,57 @@ func validate(cases []DagTestCase) error {
152161

153162
return nil
154163
}
164+
165+
type mermaidNode struct {
166+
ID string
167+
Name string
168+
Needs []string
169+
}
170+
171+
// dagToMermaid converts a set of DAG test cases to a Mermaid diagram format.
172+
// This is useful for visualizing the dependencies between test cases.
173+
func dagToMermaid(cases []DagTestCase) (string, error) {
174+
// Convert each test case to a Mermaid node.
175+
nodesByName := make(map[string]mermaidNode)
176+
ct := 0
177+
for _, c := range cases {
178+
nodesByName[c.Name] = mermaidNode{
179+
ID: fmt.Sprintf("node%d", ct),
180+
Name: c.Name,
181+
}
182+
ct++
183+
}
184+
for _, c := range cases {
185+
n, ok := nodesByName[c.Name]
186+
if !ok {
187+
return "", fmt.Errorf("case %s not found in nodes", c.Name)
188+
}
189+
n.Needs = make([]string, 0, len(c.Needs))
190+
for _, need := range c.Needs {
191+
needNode, ok := nodesByName[need]
192+
if !ok {
193+
return "", fmt.Errorf("dependency %s not found for case %s", need, c.Name)
194+
}
195+
n.Needs = append(n.Needs, needNode.ID)
196+
}
197+
nodesByName[c.Name] = n
198+
}
199+
200+
// Init.
201+
sb := &strings.Builder{}
202+
sb.WriteString("graph TD\n")
203+
204+
// Add nodes themselves.
205+
for _, n := range nodesByName {
206+
fmt.Fprintf(sb, " %s[%s]\n", n.ID, n.Name)
207+
}
208+
209+
// Add dependency relationships.
210+
for _, n := range nodesByName {
211+
for _, needID := range n.Needs {
212+
fmt.Fprintf(sb, " %s --> %s\n", needID, n.ID)
213+
}
214+
}
215+
216+
return sb.String(), nil
217+
}

golden/dag_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Package testing holds tools for testing documentation code.
2+
package golden
3+
4+
import (
5+
"testing"
6+
)
7+
8+
func Test_dagToMermaid(t *testing.T) {
9+
tests := []struct {
10+
dagCases []DagTestCase
11+
name string
12+
}{
13+
{
14+
dagCases: []DagTestCase{
15+
{
16+
Name: "Case 1",
17+
Needs: []string{},
18+
},
19+
{
20+
Name: "Case 2",
21+
Needs: []string{"Case 1"},
22+
},
23+
{
24+
Name: "Case 3",
25+
Needs: []string{"Case 1", "Case 2"},
26+
},
27+
},
28+
name: "valid DAG",
29+
},
30+
}
31+
for _, tt := range tests {
32+
t.Run(tt.name, func(t *testing.T) {
33+
mermaid, err := dagToMermaid(tt.dagCases)
34+
if err != nil {
35+
t.Errorf("dagToMermaid() error = %v", err)
36+
return
37+
}
38+
t.Logf("DAG diagram (mermaid):\n%s", mermaid)
39+
})
40+
}
41+
}

measure/google/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
replace github.com/nextmv-io/sdk => ../../.
66

77
require (
8-
github.com/nextmv-io/sdk v1.9.1
8+
github.com/nextmv-io/sdk v1.9.3
99
googlemaps.github.io/maps v1.4.0
1010
)
1111

0 commit comments

Comments
 (0)