Skip to content

Commit cc6efe8

Browse files
authored
Merge pull request #20 from netboxlabs/OBS-392-go-servers-semantic-release
feat: OBS-392 - semantic release bare bones for diode-sdk-go and diode-servers
2 parents 1cfe45e + de38984 commit cc6efe8

22 files changed

+28075
-8
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
changed_files=$1
6+
if [ -z "$changed_files" ]; then
7+
echo "Please provide a list of changed files as the first argument."
8+
exit 1
9+
fi
10+
11+
distributor_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/distributor/" "diode-server/distributor/" "diode-server/server/")
12+
ingester_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/ingester" "diode-server/ingester/" "diode-server/server/")
13+
reconciler_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/reconciler/" "diode-server/reconciler/" "diode-server/server/")
14+
15+
repo_root_dir=$(git rev-parse --show-toplevel)
16+
17+
declare -A changed_servers
18+
19+
IFS=';'
20+
21+
check_deps() {
22+
local -n deps=$1
23+
local file_path=$2
24+
file_dir="$( dirname "$file_path" )/"
25+
26+
for dep in "${deps[@]}"; do
27+
if [[ "$dep" == "$file_path" ]]; then
28+
return 0
29+
fi
30+
if [[ "$file_dir" =~ ^$dep ]]; then
31+
return 0
32+
fi
33+
done
34+
return 1
35+
}
36+
37+
read -ra changed_files_arr <<< "$changed_files"
38+
39+
for file in "${changed_files_arr[@]}"; do
40+
if [[ ! -f "$repo_root_dir/$file" ]]; then
41+
echo "File $repo_root_dir/$file does not exist, skipping"
42+
continue
43+
fi
44+
45+
if check_deps distributor_deps "$file" && [[ ! -v changed_servers["distributor"] ]]; then
46+
changed_servers["distributor"]=1
47+
fi
48+
49+
if check_deps ingester_deps "$file" && [[ ! -v changed_servers["ingester"] ]]; then
50+
changed_servers["ingester"]=1
51+
fi
52+
53+
if check_deps reconciler_deps "$file" && [[ ! -v changed_servers["reconciler"] ]]; then
54+
changed_servers["reconciler"]=1
55+
fi
56+
done
57+
58+
changed_servers_num=${#changed_servers[@]}
59+
60+
matrix_json="{\"include\":["
61+
62+
item_num=0
63+
for server in "${!changed_servers[@]}"; do
64+
matrix_json+="{"
65+
matrix_json+="\"server\":\"${server}\""
66+
matrix_json+="}"
67+
if [[ $item_num -lt $changed_servers_num-1 ]]; then
68+
matrix_json+=","
69+
fi
70+
item_num=$((item_num+1))
71+
done
72+
73+
matrix_json+="]}"
74+
75+
echo "matrix=$matrix_json" >> $GITHUB_OUTPUT

.github/workflows/go-sdk-release.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Go SDK - release
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [ release ]
6+
paths:
7+
- "diode-sdk-go/**"
8+
env:
9+
GH_TOKEN: ${{ secrets.ORB_CI_GH_TOKEN }}
10+
SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }}
11+
APP_DIR: diode-sdk-go
12+
13+
jobs:
14+
get-next-version:
15+
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release_get_next_version.yaml@develop
16+
with:
17+
# passed vars need hard coding - https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations
18+
app_name: diode-sdk-go
19+
app_dir: diode-sdk-go
20+
secrets: inherit
21+
22+
build:
23+
name: Build
24+
needs: [ get-next-version ]
25+
runs-on: ubuntu-latest
26+
defaults:
27+
run:
28+
working-directory: ${{ env.APP_DIR }}
29+
env:
30+
BUILD_VERSION: ${{ needs.get-next-version.outputs.new-release-version }}
31+
BUILD_TRACK: release
32+
BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
#
36+
# do the build and inject versions here
37+
#
38+
# - name: Upload Github build artifact
39+
# uses: actions/upload-artifact@v4
40+
# with:
41+
# name: build-production.zip
42+
# path: services/controlplane/signup-ui/build-production.zip
43+
# retention-days: 1
44+
# if-no-files-found: error
45+
46+
semantic-release:
47+
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release.yaml@develop
48+
needs: [ build ]
49+
with:
50+
app_dir: diode-sdk-go
51+
secrets: inherit
52+
53+
# upload to Docker hub / GHCR here

.github/workflows/go-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: go-test
1+
name: Go - test
22
on:
33
push:
44
branches:

.github/workflows/golangci-lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: golangci-lint
1+
name: Go - lint
22
on:
33
push:
44
branches:
@@ -18,7 +18,7 @@ jobs:
1818
]
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
2222
- uses: actions/setup-go@v4
2323
with:
2424
go-version: '1.21'

.github/workflows/python-netbox-plugin-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Python Netbox plugin - lint"
1+
name: Python Netbox plugin - lint
22
on:
33
workflow_dispatch:
44
push:

.github/workflows/python-netbox-plugin-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Python Netbox plugin - Release"
1+
name: Python Netbox plugin - release
22
on:
33
workflow_dispatch:
44
push:

.github/workflows/python-sdk-lint-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Python SDK - lint and tests"
1+
name: Python SDK - lint and tests
22
on:
33
workflow_dispatch:
44
push:

.github/workflows/python-sdk-release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Python SDK - Release"
1+
name: Python SDK - release
22
on:
33
workflow_dispatch:
44
push:

.github/workflows/server-release.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Server - release
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [ release ]
6+
paths:
7+
- "diode-server/**"
8+
env:
9+
GH_TOKEN: ${{ secrets.ORB_CI_GH_TOKEN }}
10+
SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }}
11+
12+
jobs:
13+
setup:
14+
name: Setup
15+
runs-on: ubuntu-latest
16+
outputs:
17+
matrix: ${{ steps.generate-matrix.outputs.matrix }}
18+
short_sha: ${{ steps.set-sha.outputs.short_sha }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
- name: Set short SHA
25+
id: short-sha
26+
run: |
27+
echo "short_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
28+
- name: Get changed dirs
29+
id: get-changed-dirs
30+
run: |
31+
echo "changed-dirs=$(git diff --name-only origin/${{ github.base_ref }} ${{ steps.short-sha.outputs.short_sha }} | sort -u | tr '\n' ';')" >> $GITHUB_OUTPUT
32+
- name: Generate servers matrix
33+
id: generate-matrix
34+
run: .github/workflows/generate_changed_servers_matrix.sh "${{ steps.get-changed-dirs.outputs.changed-dirs }}"
35+
- name: Echo test
36+
run: |
37+
echo "matrix: ${{ steps.generate-matrix.outputs.matrix }}"
38+
39+
get-next-version:
40+
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release_get_next_version.yaml@develop
41+
needs: [ setup ]
42+
with:
43+
# passed vars need hard coding - https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations
44+
app_name: ${{ matrix.server }}
45+
app_dir: diode-server/cmd/${{ matrix.server }}
46+
secrets: inherit
47+
48+
build:
49+
name: Build ${{ matrix.server }}
50+
needs: [ get-next-version ]
51+
runs-on: ubuntu-latest
52+
defaults:
53+
run:
54+
working-directory: diode-server/cmd/${{ matrix.server }}
55+
env:
56+
BUILD_VERSION: ${{ needs.get-next-version.outputs.new-release-version }}
57+
BUILD_TRACK: release
58+
BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }}
59+
steps:
60+
- uses: actions/checkout@v4
61+
#
62+
# do the build and inject versions here
63+
#
64+
# - name: Upload Github build artifact
65+
# uses: actions/upload-artifact@v4
66+
# with:
67+
# name: build-production.zip
68+
# path: services/controlplane/signup-ui/build-production.zip
69+
# retention-days: 1
70+
# if-no-files-found: error
71+
72+
semantic-release:
73+
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release.yaml@develop
74+
needs: [ build ]
75+
with:
76+
app_dir: diode-server/cmd/${{ matrix.server }}
77+
secrets: inherit
78+
79+
# upload to Docker hub / GHCR here

diode-sdk-go/.releaserc.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"branches": "release",
3+
"repositoryUrl": "https://github.com/netboxlabs/diode",
4+
"debug": "true",
5+
"extends": "semantic-release-monorepo",
6+
"tagFormat": "diode-sdk-go/v${version}",
7+
"plugins": [
8+
[
9+
"semantic-release-export-data"
10+
],
11+
[
12+
"@semantic-release/commit-analyzer",
13+
{
14+
"releaseRules": [
15+
{
16+
"message": "*",
17+
"release": "patch"
18+
},
19+
{
20+
"message": "fix*",
21+
"release": "patch"
22+
},
23+
{
24+
"message": "feat*",
25+
"release": "minor"
26+
},
27+
{
28+
"message": "perf*",
29+
"release": "major"
30+
}
31+
]
32+
}
33+
],
34+
"@semantic-release/release-notes-generator",
35+
[
36+
"@semantic-release/changelog",
37+
{
38+
"changelogFile": "CHANGELOG.md",
39+
"changelogTitle": "# Semantic Versioning Changelog"
40+
}
41+
],
42+
[
43+
"@semantic-release/github",
44+
{
45+
"assets": [
46+
{
47+
"path": "release/**"
48+
}
49+
]
50+
}
51+
]
52+
]
53+
}

0 commit comments

Comments
 (0)