Skip to content

Commit bc655dd

Browse files
committed
Further cleanup, tests, and docs
Signed-off-by: Ole Herman Schumacher Elgesem <ole.elgesem@northern.tech>
1 parent 6072060 commit bc655dd

File tree

7 files changed

+109
-50
lines changed

7 files changed

+109
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist
77
/.venv
88
__pycache__/
99
**/.DS_STORE
10+
.pytest_cache

HACKING.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Developing / maintaining the CFEngine CLI
2+
3+
This document aims to have relevant information for people contributing to and maintaining the CFEngine CLI.
4+
It is not necessary for users of the tool to know about these processes.
5+
For general user information, see the [README](./README.md).
6+
7+
## Releasing new versions
8+
9+
Releases are [automated using a GH Action](https://github.com/cfengine/cfengine-cli/blob/main/.github/workflows/pypi-publish.yml)
10+
We create tags and releases through the GitHub UI.
11+
Go to the releases section in GitHub:
12+
13+
https://github.com/cfengine/cfengine-cli/releases
14+
15+
Determine the new version number according to SemVer:
16+
17+
- Look at what is the latest released version.
18+
- Increase the first number if you are releasing breaking changes.
19+
- Or, increase the second number if there are new features (but no breaking changes).
20+
- Otherwise, increase the last number (only backwards compatible bugfixes).
21+
22+
Sometimes, it's not 100% clear, so use your best judgement.
23+
24+
Once you know the version number, proceed with making the release:
25+
26+
1. Enter the version number into the **Choose a tag** dropdown.
27+
2. Click the **Create new tag on publish** alternative.
28+
3. Target should say **main**, don't change it.
29+
4. Put exactly the same version number into the **Release title** field.
30+
5. Click **Generate release notes**.
31+
- In general, it's not necessary to edit the release notes.
32+
- Sometimes you might want to add a link to a release blog post.
33+
- Or, if there is a lot of noise, for example changes to docs and tests which don't affect users, you can remove those.
34+
6. Leave the checkboxes below as is (latest release checked, pre-release unchecked).
35+
7. Click **Publish release**.
36+
8. Watch the release happen:
37+
- In GitHub Actions: https://github.com/cfengine/cfengine-cli/actions
38+
- And if all is well, the new version should appear on PyPI: https://pypi.org/project/cfengine/
39+
40+
If it does not work, click the failing GitHub Actions and try to understand what went wrong.
41+
42+
## Rotating secrets
43+
44+
The GH Action shown above requires a PyPI token to have access to publish new versions to PyPI.
45+
Sometimes, this needs to be rotated.
46+
[Log in](https://pypi.org/account/login/) to PyPI (need account access) and go to account settings:
47+
48+
https://pypi.org/manage/account/
49+
50+
Delete the old `cfengine-cli` token and generate a new one with the same name and correct scope (only access to `cfengine` project).
51+
Copy the token and paste it into the GitHub Secret named `PYPI_PASSWORD`.
52+
`PYPI_USERNAME` should be there already, you don't have to edit it, it is simply `__token__`.
53+
Don't store the token anywhere else - we generate new tokens if necessary.
54+
55+
## Code formatting
56+
57+
We use automated code formatters to ensure consistent code style / indentation.
58+
Please format Python code with [black](https://pypi.org/project/black/), and YAML and markdown files with [Prettier](https://prettier.io/).
59+
For simplicity's sake, we don't have a custom configuration, we use the tool's defaults.
60+
61+
If your editor does not do this automatically, you can run these tools from the command line:
62+
63+
```
64+
black . && prettier . --write
65+
```

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# CFEngine CLI
1+
# CFEngine command line interface (CLI)
22

3-
A simple CLI for interacting with various CFEngine tools, such as cf-agent, cf-remote, cf-hub, cf-remote, and cfbs.
3+
A CLI for humans to interact with CFEngine, enabling downloading and installing packages, building policy sets, deploying, and enforcing policy.
4+
It is practically a wrapper around our other tools, like `cf-agent`, `cf-hub`, `cf-remote` and `cfbs`.
5+
6+
**Warning:** This is an early version.
7+
Things might be missing or changed.
8+
Proceed with caution and excitement.
49

510
## Installation
611

@@ -41,3 +46,8 @@ This CLI is entirely intended for humans.
4146
If you put it into scripts and automation, expect it to break in the future.
4247
In order to make the user experience better, we might add, change, or remove commands.
4348
We will also be experimenting with different types of interactive prompts and input.
49+
50+
## Development, maintenance, contributions, and releases
51+
52+
Looking for more information related to contributing code, releasing new versions or otherwise maintaining the CFEngine CLI?
53+
Please see the [HACKING.md](./HACKING.md) file.
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
2+
3+
# This test sets up a docker container running an SSH server,
4+
# where we test ssh based commands
5+
# (such as cf-remote install).
6+
# TODO: Actually install / test something in container
7+
28
set -ex
39
set -o pipefail
410

@@ -10,7 +16,7 @@ error () {
1016
trap error ERR
1117

1218
dir=$(dirname "$0")
13-
name=cf-remote-debian-test-host
19+
name=cfengine-cli-debian-test-host
1420

1521
docker stop "$name" || true
1622
docker rm "$name" || true
@@ -19,8 +25,12 @@ docker run -d -p 8822:22 --name "$name" "$name" >>log 2>&1
1925
ip_addr=$(hostname -i)
2026
ssh -o StrictHostKeyChecking=no -p 8822 root@"$ip_addr" hostname >>log 2>&1
2127
echo "ssh returned exit code $?"
22-
echo "=== cf-remote info ===" | tee -a log
23-
cf-remote --log-level DEBUG info -H root@"$ip_addr":8822 2>&1 | tee -a log
24-
echo "cf-remote info got return code $?"
25-
echo "=== cf-remote install ===" | tee -a log
28+
echo "=== cf-remote --version ===" | tee -a log
29+
cf-remote --version 2>&1 | tee -a log
30+
echo "cf-remote --version got return code $?"
31+
echo "=== cfengine version ===" | tee -a log
32+
cfengine version 2>&1 | tee -a log
33+
echo "=== cfengine --version ===" | tee -a log
34+
cfengine --version 2>&1 | tee -a log
35+
echo "=== cfengine help ===" | tee -a log
2636
cfengine help 2>&1 | tee -a log

tests/shell/001-help.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#!/bin/bash
12
cfengine help

tests/test_cache.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/test_deps.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Just some very basic tests to ensure we can use functions from the
2+
cfbs and cf-remote dependencies"""
3+
4+
from cf_remote.utils import canonify
5+
from cfbs.utils import is_a_commit_hash
6+
7+
8+
def test_cfbs_is_a_commit_hash():
9+
assert is_a_commit_hash("6072060c63c5f6bc74897bf4be2681d3e9d3bf32")
10+
assert not is_a_commit_hash("blah")
11+
12+
13+
def test_cf_remote_canonify():
14+
assert canonify(" CF-REMOTE ") == "cf_remote"

0 commit comments

Comments
 (0)