Skip to content

Commit 1ff0234

Browse files
authored
Merge pull request #2 from netboxlabs/develop
Release: diode-sdk-python
2 parents 30eca2e + 68bf79d commit 1ff0234

29 files changed

+4238
-3
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @mfiedorowicz @natm

.github/pull_request_labeler.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
documentation:
2+
- changed-files:
3+
- any-glob-to-any-file:
4+
- '**/docs/**/*'
5+
6+
github-actions:
7+
- changed-files:
8+
- any-glob-to-any-file:
9+
- '**/.github/workflows/*'
10+
- '**/.github/workflows/**/*'
11+
- '**/.github/dependabot.yaml'
12+
- '**/.github/pull_request_labeler.yaml'
13+
14+
github-templates:
15+
- changed-files:
16+
- any-glob-to-any-file:
17+
- '**/.github/ISSUE_TEMPLATE/*'
18+
- '**/.github/PULL_REQUEST_TEMPLATE.md'
19+
- '**/.github/.chglog/*'
20+
- '**/.github/.chglog/**/*'
21+
22+
internal:
23+
- changed-files:
24+
- any-glob-to-any-file:
25+
- '**/.flake8'
26+
- '**/.bandit.baseline'
27+
- '**/.gitignore'
28+
- '**/.pre-commit-config.yaml'
29+
- '**/MANIFEST.in'
30+
- '**/Makefile'
31+
- '**/CONTRIBUTING.md'
32+
- '**/MAINTAINERS.md'
33+
- '**/CODE_OF_CONDUCT.md'
34+
- '**/LICENSE'
35+
- '**/LICENSE.txt'
36+
- '**/THIRD-PARTY-LICENSES'
37+
- '**/.dockerignore'
38+
- '**/.editorconfig'
39+
- '**/setup.cfg'
40+
41+
dependencies:
42+
- changed-files:
43+
- any-glob-to-any-file:
44+
- '**/pyproject.toml'
45+
- '**/poetry.lock'
46+
- '**/requirements.txt'
47+
48+
markdown:
49+
- changed-files:
50+
- any-glob-to-any-file: '**/*.md'
51+
52+
python:
53+
- changed-files:
54+
- any-glob-to-any-file: '**/*.py'

.github/workflows/labeler.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: PR labeler
2+
on:
3+
- pull_request_target
4+
5+
concurrency:
6+
group: ${{ github.workflow }}
7+
cancel-in-progress: false
8+
9+
jobs:
10+
triage:
11+
permissions:
12+
contents: read
13+
pull-requests: write
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 5
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: actions/labeler@v5
19+
with:
20+
configuration-path: '.github/pull_request_labeler.yaml'

.github/workflows/lint-tests.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Lint and tests
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
push:
6+
branches:
7+
- "!release"
8+
9+
concurrency:
10+
group: ${{ github.workflow }}
11+
cancel-in-progress: false
12+
13+
jobs:
14+
tests:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 5
17+
strategy:
18+
matrix:
19+
python: [ "3.10", "3.11" ]
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ matrix.python }}
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install .
32+
pip install .[dev]
33+
pip install .[test]
34+
35+
- name: Run tests with coverage
36+
run: |
37+
set -o pipefail
38+
pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=netboxlabs.diode.sdk tests/ | tee pytest-coverage.txt
39+
40+
- name: Pytest coverage comment
41+
uses: MishaKav/pytest-coverage-comment@main
42+
with:
43+
pytest-coverage-path: ./pytest-coverage.txt
44+
junitxml-path: ./pytest.xml
45+
46+
- name: Lint with Ruff
47+
run: |
48+
ruff check --output-format=github netboxlabs/ tests/
49+
continue-on-error: true

.github/workflows/release.yaml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [ release ]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}
9+
cancel-in-progress: false
10+
11+
env:
12+
GH_TOKEN: ${{ secrets.ORB_CI_GH_TOKEN }}
13+
SEMANTIC_RELEASE_PACKAGE: ${{ github.repository }}
14+
PYTHON_RUNTIME_VERSION: "3.11"
15+
APP_NAME: diode-sdk-python
16+
PYTHON_PACKAGE_NAME: netboxlabs-diode-sdk
17+
18+
jobs:
19+
get-next-version:
20+
name: Semantic release get next version
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 5
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: "lts/*"
28+
- name: Write package.json
29+
uses: DamianReeves/write-file-action@master
30+
with:
31+
path: ./package.json
32+
write-mode: overwrite
33+
contents: |
34+
{
35+
"name": "${{ env.APP_NAME }}",
36+
"version": "1.0.0",
37+
"devDependencies": {
38+
"semantic-release-export-data": "^1.0.1",
39+
"@semantic-release/changelog": "^6.0.3"
40+
}
41+
}
42+
- name: Write .releaserc.json
43+
uses: DamianReeves/write-file-action@master
44+
with:
45+
path: ./.releaserc.json
46+
write-mode: overwrite
47+
contents: |
48+
{
49+
"branches": "release",
50+
"repositoryUrl": "https://github.com/netboxlabs/diode-sdk-python",
51+
"debug": "true",
52+
"tagFormat": "v${version}",
53+
"plugins": [
54+
["semantic-release-export-data"],
55+
["@semantic-release/commit-analyzer", {
56+
"releaseRules": [
57+
{ "message": "*", "release": "patch"},
58+
{ "message": "fix*", "release": "patch" },
59+
{ "message": "feat*", "release": "minor" },
60+
{ "message": "perf*", "release": "major" }
61+
]
62+
}],
63+
"@semantic-release/release-notes-generator",
64+
[
65+
"@semantic-release/changelog",
66+
{
67+
"changelogFile": "CHANGELOG.md",
68+
"changelogTitle": "# Semantic Versioning Changelog"
69+
}
70+
],
71+
[
72+
"@semantic-release/github",
73+
{
74+
"assets": [
75+
{
76+
"path": "release/**"
77+
}
78+
]
79+
}
80+
]
81+
]
82+
}
83+
- name: setup semantic-release
84+
run: npm i
85+
- name: release dry-run
86+
env:
87+
SLACK_WEBHOOK: ${{ secrets.SLACK_SEMANTIC_RELEASE_WEBHOOK }}
88+
run: npx semantic-release --debug --dry-run
89+
id: get-next-version
90+
- name: Set short sha output
91+
id: short-sha
92+
run: echo "::set-output name=short-sha::${GITHUB_SHA::7}"
93+
- name: Set release version
94+
id: release-version
95+
run: |
96+
echo "::set-output name=release-version::`echo ${{ steps.get-next-version.outputs.new-release-version }} | sed 's/v//g'`"
97+
outputs:
98+
new-release-published: ${{ steps.get-next-version.outputs.new-release-published }}
99+
new-release-version: ${{ steps.release-version.outputs.release-version }}
100+
short-sha: ${{ steps.short-sha.outputs.short-sha }}
101+
102+
confirm-version:
103+
name: Next version ${{ needs.get-next-version.outputs.new-release-version }}
104+
runs-on: ubuntu-latest
105+
timeout-minutes: 5
106+
needs: get-next-version
107+
if: needs.get-next-version.outputs.new-release-published == 'true'
108+
steps:
109+
- uses: actions/checkout@v4
110+
- run: echo "The new release version is ${{ needs.get-next-version.outputs.new-release-version }} commit ${{ needs.get-next-version.outputs.short-sha }}"
111+
112+
build:
113+
name: Build
114+
needs: [ get-next-version ]
115+
runs-on: ubuntu-latest
116+
timeout-minutes: 5
117+
permissions:
118+
id-token: write
119+
contents: read
120+
env:
121+
BUILD_VERSION: ${{ needs.get-next-version.outputs.new-release-version }}
122+
BUILD_TRACK: release
123+
BUILD_COMMIT: ${{ needs.get-next-version.outputs.short-sha }}
124+
steps:
125+
- uses: actions/checkout@v3
126+
- uses: actions/setup-python@v5
127+
with:
128+
python-version: ${{ env.PYTHON_RUNTIME_VERSION }}
129+
- name: Insert version variables into Python
130+
run: |
131+
sed -i "s/__commit_hash__ = .*/__commit_hash__ = \"${BUILD_COMMIT}\"/" netboxlabs/diode/sdk/version.py
132+
sed -i "s/__track__ = .*/__track__ = \"${BUILD_TRACK}\"/" netboxlabs/diode/sdk/version.py
133+
sed -i "s/__version__ = .*/__version__ = \"${BUILD_VERSION}\"/" netboxlabs/diode/sdk/version.py
134+
- name: Display contents of version.py
135+
run: cat netboxlabs/diode/sdk/version.py
136+
- name: Build sdist package
137+
run: |
138+
pip install toml-cli
139+
toml set --toml-path pyproject.toml project.version ${{ env.BUILD_VERSION }}
140+
cat pyproject.toml | grep version
141+
python3 -m pip install --upgrade build
142+
python3 -m build --sdist --outdir dist/
143+
- name: Upload artifact
144+
uses: actions/upload-artifact@v4
145+
with:
146+
name: ${{ env.PYTHON_PACKAGE_NAME }}-${{ env.BUILD_VERSION }}.tar.gz
147+
path: ./dist/${{ env.PYTHON_PACKAGE_NAME }}-${{ env.BUILD_VERSION }}.tar.gz
148+
retention-days: 30
149+
if-no-files-found: error
150+
- name: Publish release distributions to PyPI
151+
uses: pypa/gh-action-pypi-publish@release/v1
152+
with:
153+
packages-dir: ./dist
154+
155+
semantic-release:
156+
name: Semantic release
157+
needs: [ build ]
158+
runs-on: ubuntu-latest
159+
timeout-minutes: 5
160+
steps:
161+
- uses: actions/checkout@v4
162+
- uses: actions/setup-node@v4
163+
with:
164+
node-version: "21.4.0"
165+
- name: setup semantic-release
166+
run: npm i
167+
- name: Release
168+
env:
169+
SLACK_WEBHOOK: ${{ secrets.SLACK_OBSERVABILITY_RELEASE_WEBHOOK }}
170+
run: npx semantic-release --debug

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# IntelliJ
2+
.idea/
3+
4+
# VS Code
5+
.vscode
6+
7+
# Environments
8+
.env
9+
.venv
10+
env/
11+
venv/
12+
ENV/
13+
env.bak/
14+
venv.bak/
15+
16+
# macOS
17+
.DS_Store
18+
19+
# Python
20+
__pycache__/
21+
*.py[cod]
22+
*$py.class
23+
.Python
24+
build/
25+
dist/
26+
.eggs/
27+
*.egg-info

LICENSE renamed to LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2024 NetBox Labs, Inc.
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)