diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..455da6d --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,7 @@ +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +* @NebraLtd/developers + +# See example for more details: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-code-owners#example-of-a-codeowners-file diff --git a/.github/contributing.md b/.github/contributing.md new file mode 100644 index 0000000..3560acf --- /dev/null +++ b/.github/contributing.md @@ -0,0 +1,35 @@ +# How to contriubte + +Thanks for your interest in contributing to Nebra. We enforce certain rules on commits with the following goals in mind: + +- Be able to reliably auto-generate the `CHANGELOG.md` *without* any human intervention. +- Be able to automatically and correctly increment the semver version number based on what was done since the last release. +- Be able to get a quick overview of what happened to the project by glancing over the commit history. +- Be able to automatically reference relevant changes from a dependency upgrade. + +Our CI will run checks to ensure this guidelines are followed and won't allow merging contributions that don't adhere to them. Version number and changelog are automatically handled by the CI build flow after a pull request is merged. You only need to worry about the commit itself. + +## Commit structure + +Each commit message should consist of a header a body and a footer, structured in the following format: + +``` +: +--BLANK LINE-- +(optional) +--BLANK LINE-- +(optional) Connects-to: #issue-number +(optional) Closes: #issue-number +(mandatory) Change-type: major | minor | patch +(optional) Signed-off-by: Foo Bar +``` + +Note that: +- Blank lines are required to separate header from body and body from footer. You don't need to add two blank lines if you don't add a body. +- `scope`: If your commit touches a well defined component/part/service please addthe scope tag to clarify. Some examples: `docs`, `images`, `typos`. +- `subject`: The subject should contain a short description of the change. Use the imperative, present tense. +- `body`: A detailed description of changes being made and reasoning if necessary. This may contain several paragraphs. +- `Connects-to`: If your commit is connected to an existing issue, link it by adding this tag with `#issue-number`. Example: `Connects-to: #123` +- `Closes`: If your commit fixes an existing issue, link it by adding this tag with `#issue-number`. Example: `Closes: #123` +- `Change-type`: At least one of your commits on a PR needs to have this tag. You have the flexibility, and it's good practise, to use this tag in as many commits as you see fit; in the end, the resulting change type for the scope of the PR will be folded down to the biggest one as marked in the commits (`major>minor>patch`). Our version numbering adheres to [Semantic Versioning](http://semver.org/). +- `Signed-off-by`: Sign your commits by providing your full name and email address in the format: `Name Surname `. *This is an optional tag.* diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..f9195bc --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,9 @@ +**Why** + + +**How** + + + +**References** + diff --git a/.github/workflows/publish-to-pypi-test.yml b/.github/workflows/publish-to-pypi-test.yml index 9963ef8..3a4af5e 100644 --- a/.github/workflows/publish-to-pypi-test.yml +++ b/.github/workflows/publish-to-pypi-test.yml @@ -14,12 +14,12 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable - target: aarch64-unknown-linux-musl + target: arm-unknown-linux-gnueabihf override: true - name: Clone repo run: | - git clone --branch v0.1.3 https://github.com/helium/gateway-mfr-rs.git . + git clone --branch v0.1.5 https://github.com/helium/gateway-mfr-rs.git . - name: Run cargo check uses: actions-rs/cargo@v1 @@ -32,11 +32,11 @@ jobs: with: use-cross: true command: build - args: --target aarch64-unknown-linux-musl --release + args: --target arm-unknown-linux-gnueabihf --release - name: Copy release file run: | - cp ./target/aarch64-unknown-linux-musl/release/gateway_mfr gateway_mfr + cp ./target/arm-unknown-linux-gnueabihf/release/gateway_mfr gateway_mfr - uses: actions/upload-artifact@v2 with: @@ -82,7 +82,12 @@ jobs: name: wheels path: ./dist/* + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v2.1 + - name: Publish distribution 📦 to Test PyPI + if: contains(steps.changed-files.outputs.modified_files, 'setup.py') uses: pypa/gh-action-pypi-publish@master with: password: ${{ secrets.TEST_PYPI_API_TOKEN }} diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 34624d6..a674e06 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -14,12 +14,12 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable - target: aarch64-unknown-linux-musl + target: arm-unknown-linux-gnueabihf override: true - name: Clone repo run: | - git clone --branch v0.1.3 https://github.com/helium/gateway-mfr-rs.git . + git clone --branch v0.1.5 https://github.com/helium/gateway-mfr-rs.git . - name: Run cargo check uses: actions-rs/cargo@v1 @@ -32,11 +32,11 @@ jobs: with: use-cross: true command: build - args: --target aarch64-unknown-linux-musl --release + args: --target arm-unknown-linux-gnueabihf --release - name: Copy release file run: | - cp ./target/aarch64-unknown-linux-musl/release/gateway_mfr gateway_mfr + cp ./target/arm-unknown-linux-gnueabihf/release/gateway_mfr gateway_mfr - uses: actions/upload-artifact@v2 with: diff --git a/README.md b/README.md index 7fdef9f..c916af3 100644 --- a/README.md +++ b/README.md @@ -107,4 +107,24 @@ project's Dockerfile. ```Dockerfile RUN pip3 install setuptools wheel RUN pip3 install --target="$OUTPUTS_DIR" git+https://github.com/NebraLtd/hm-pyhelper@BRANCH_NAME -`````` \ No newline at end of file +`````` + +## Releasing + +To release, use the [Github new release flow](https://github.com/NebraLtd/hm-pyhelper/releases/new). + +1. Create a new tag in format `vX.Y.Z`. You can use a previously tagged commit, but this is not necessary. +2. Make sure the tag you created matches the value in setup.py. +3. Select `master` as the target branch. If you do not select the master branch, the tag should be in format `vX.Y.Z-rc.N`. +4. Title: `Release vX.Y.Z`. +5. Body: + +**Note: you can create the release notes automatically by selecting the "Auto-generate release notes" option on the releases page.** + +``` +## What's Changed +* Foo +* Bar + +**Full Changelog**: https://github.com/NebraLtd/hm-pyhelper/compare/v0.0.A...v0.0.Z +``` diff --git a/hm_pyhelper/miner_json_rpc/client.py b/hm_pyhelper/miner_json_rpc/client.py index e9bc622..d29c331 100644 --- a/hm_pyhelper/miner_json_rpc/client.py +++ b/hm_pyhelper/miner_json_rpc/client.py @@ -44,3 +44,7 @@ def get_peer_addr(self): def get_peer_book(self): return self.__fetch_data('peer_book', addr='self') + + def get_firmware_version(self): + summary = self.get_summary() + return summary.get('firmware_version') diff --git a/hm_pyhelper/tests/test_miner_json_rpc.py b/hm_pyhelper/tests/test_miner_json_rpc.py index dc54ed7..96d65fd 100644 --- a/hm_pyhelper/tests/test_miner_json_rpc.py +++ b/hm_pyhelper/tests/test_miner_json_rpc.py @@ -171,3 +171,37 @@ def test_get_peer_book(self, mock_json_rpc_client): addr='self' ) self.assertEqual(result, []) + + @mock.patch('hm_pyhelper.miner_json_rpc.client.request') + def test_get_firmware_version(self, mock_json_rpc_client): + firmware_version = '2021.10.18.0' + summary = { + 'block_age': 1136610, + 'epoch': 25612, + 'firmware_version': firmware_version, + 'gateway_details': 'undefined', + 'height': 993640, + 'mac_addresses': [ + {'eth0': '0242AC110002'}, + {'ip6tnl0': '00000000000000000000000000000000'}, + {'tunl0': '00000000'}, + {'lo': '000000000000'} + ], + 'name': 'scruffy-chocolate-shell', + 'peer_book_entry_count': 3, + 'sync_height': 993640, + 'uptime': 144, + 'version': 10010005 + } + mock_json_rpc_client.return_value = Response( + data=Result( + result=summary + ) + ) + client = MinerClient() + result = client.get_firmware_version() + mock_json_rpc_client.assert_called_with( + BASE_URL, + 'info_summary' + ) + self.assertEqual(result, firmware_version)