Skip to content

Commit

Permalink
Merge pull request #20 from netboxlabs/OBS-392-go-servers-semantic-re…
Browse files Browse the repository at this point in the history
…lease

feat: OBS-392 - semantic release bare bones for diode-sdk-go and diode-servers
  • Loading branch information
mfiedorowicz authored Feb 14, 2024
2 parents 1cfe45e + de38984 commit cc6efe8
Show file tree
Hide file tree
Showing 22 changed files with 28,075 additions and 8 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/generate_changed_servers_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

set -e

changed_files=$1
if [ -z "$changed_files" ]; then
echo "Please provide a list of changed files as the first argument."
exit 1
fi

distributor_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/distributor/" "diode-server/distributor/" "diode-server/server/")
ingester_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/ingester" "diode-server/ingester/" "diode-server/server/")
reconciler_deps=("diode-server/go.mod" "diode-server/go.sum" "diode-server/cmd/reconciler/" "diode-server/reconciler/" "diode-server/server/")

repo_root_dir=$(git rev-parse --show-toplevel)

declare -A changed_servers

IFS=';'

check_deps() {
local -n deps=$1
local file_path=$2
file_dir="$( dirname "$file_path" )/"

for dep in "${deps[@]}"; do
if [[ "$dep" == "$file_path" ]]; then
return 0
fi
if [[ "$file_dir" =~ ^$dep ]]; then
return 0
fi
done
return 1
}

read -ra changed_files_arr <<< "$changed_files"

for file in "${changed_files_arr[@]}"; do
if [[ ! -f "$repo_root_dir/$file" ]]; then
echo "File $repo_root_dir/$file does not exist, skipping"
continue
fi

if check_deps distributor_deps "$file" && [[ ! -v changed_servers["distributor"] ]]; then
changed_servers["distributor"]=1
fi

if check_deps ingester_deps "$file" && [[ ! -v changed_servers["ingester"] ]]; then
changed_servers["ingester"]=1
fi

if check_deps reconciler_deps "$file" && [[ ! -v changed_servers["reconciler"] ]]; then
changed_servers["reconciler"]=1
fi
done

changed_servers_num=${#changed_servers[@]}

matrix_json="{\"include\":["

item_num=0
for server in "${!changed_servers[@]}"; do
matrix_json+="{"
matrix_json+="\"server\":\"${server}\""
matrix_json+="}"
if [[ $item_num -lt $changed_servers_num-1 ]]; then
matrix_json+=","
fi
item_num=$((item_num+1))
done

matrix_json+="]}"

echo "matrix=$matrix_json" >> $GITHUB_OUTPUT
53 changes: 53 additions & 0 deletions .github/workflows/go-sdk-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Go SDK - release
on:
workflow_dispatch:
push:
branches: [ release ]
paths:
- "diode-sdk-go/**"
env:
GH_TOKEN: ${{ secrets.ORB_CI_GH_TOKEN }}
SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }}
APP_DIR: diode-sdk-go

jobs:
get-next-version:
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release_get_next_version.yaml@develop
with:
# passed vars need hard coding - https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations
app_name: diode-sdk-go
app_dir: diode-sdk-go
secrets: inherit

build:
name: Build
needs: [ get-next-version ]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ env.APP_DIR }}
env:
BUILD_VERSION: ${{ needs.get-next-version.outputs.new-release-version }}
BUILD_TRACK: release
BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }}
steps:
- uses: actions/checkout@v4
#
# do the build and inject versions here
#
# - name: Upload Github build artifact
# uses: actions/upload-artifact@v4
# with:
# name: build-production.zip
# path: services/controlplane/signup-ui/build-production.zip
# retention-days: 1
# if-no-files-found: error

semantic-release:
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release.yaml@develop
needs: [ build ]
with:
app_dir: diode-sdk-go
secrets: inherit

# upload to Docker hub / GHCR here
2 changes: 1 addition & 1 deletion .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: go-test
name: Go - test
on:
push:
branches:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: golangci-lint
name: Go - lint
on:
push:
branches:
Expand All @@ -18,7 +18,7 @@ jobs:
]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-netbox-plugin-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Python Netbox plugin - lint"
name: Python Netbox plugin - lint
on:
workflow_dispatch:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-netbox-plugin-release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Python Netbox plugin - Release"
name: Python Netbox plugin - release
on:
workflow_dispatch:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-sdk-lint-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Python SDK - lint and tests"
name: Python SDK - lint and tests
on:
workflow_dispatch:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-sdk-release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Python SDK - Release"
name: Python SDK - release
on:
workflow_dispatch:
push:
Expand Down
79 changes: 79 additions & 0 deletions .github/workflows/server-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Server - release
on:
workflow_dispatch:
push:
branches: [ release ]
paths:
- "diode-server/**"
env:
GH_TOKEN: ${{ secrets.ORB_CI_GH_TOKEN }}
SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }}

jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate-matrix.outputs.matrix }}
short_sha: ${{ steps.set-sha.outputs.short_sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set short SHA
id: short-sha
run: |
echo "short_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Get changed dirs
id: get-changed-dirs
run: |
echo "changed-dirs=$(git diff --name-only origin/${{ github.base_ref }} ${{ steps.short-sha.outputs.short_sha }} | sort -u | tr '\n' ';')" >> $GITHUB_OUTPUT
- name: Generate servers matrix
id: generate-matrix
run: .github/workflows/generate_changed_servers_matrix.sh "${{ steps.get-changed-dirs.outputs.changed-dirs }}"
- name: Echo test
run: |
echo "matrix: ${{ steps.generate-matrix.outputs.matrix }}"
get-next-version:
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release_get_next_version.yaml@develop
needs: [ setup ]
with:
# passed vars need hard coding - https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations
app_name: ${{ matrix.server }}
app_dir: diode-server/cmd/${{ matrix.server }}
secrets: inherit

build:
name: Build ${{ matrix.server }}
needs: [ get-next-version ]
runs-on: ubuntu-latest
defaults:
run:
working-directory: diode-server/cmd/${{ matrix.server }}
env:
BUILD_VERSION: ${{ needs.get-next-version.outputs.new-release-version }}
BUILD_TRACK: release
BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }}
steps:
- uses: actions/checkout@v4
#
# do the build and inject versions here
#
# - name: Upload Github build artifact
# uses: actions/upload-artifact@v4
# with:
# name: build-production.zip
# path: services/controlplane/signup-ui/build-production.zip
# retention-days: 1
# if-no-files-found: error

semantic-release:
uses: netboxlabs/diode/.github/workflows/reusable_semantic_release.yaml@develop
needs: [ build ]
with:
app_dir: diode-server/cmd/${{ matrix.server }}
secrets: inherit

# upload to Docker hub / GHCR here
53 changes: 53 additions & 0 deletions diode-sdk-go/.releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"branches": "release",
"repositoryUrl": "https://github.com/netboxlabs/diode",
"debug": "true",
"extends": "semantic-release-monorepo",
"tagFormat": "diode-sdk-go/v${version}",
"plugins": [
[
"semantic-release-export-data"
],
[
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{
"message": "*",
"release": "patch"
},
{
"message": "fix*",
"release": "patch"
},
{
"message": "feat*",
"release": "minor"
},
{
"message": "perf*",
"release": "major"
}
]
}
],
"@semantic-release/release-notes-generator",
[
"@semantic-release/changelog",
{
"changelogFile": "CHANGELOG.md",
"changelogTitle": "# Semantic Versioning Changelog"
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "release/**"
}
]
}
]
]
}
Loading

0 comments on commit cc6efe8

Please sign in to comment.