Skip to content

Commit 580f764

Browse files
committed
ci: run on a NodeRings self-hosted runner when NODERINGS_RUNNER is set
Jobs ask for [self-hosted, noderings] when the repository variable NODERINGS_RUNNER is true and fall back to ubuntu-latest otherwise. Pull requests from forks always use GitHub-hosted runners. CI now runs the template's pre-commit hooks, the nox unit test session across Salt 3006 to 3008, the template docs session (linkcheck, coverage, HTML), and a package check: build, twine check, then install the wheel and confirm that salt-call loads the execution and state modules. A single "CI result" job collects the results for branch protection. Actions are pinned to commit SHAs. .github/self-hosted-runner.md explains the recommended runner (a dedicated NodeRings VM, registered at the repository level) and how to switch over. Signed-off-by: NodeRings <17057583+shaygun@users.noreply.github.com>
1 parent 4a9121f commit 580f764

3 files changed

Lines changed: 268 additions & 50 deletions

File tree

‎.github/self-hosted-runner.md‎

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Running CI on a NodeRings self-hosted runner
2+
3+
CI runs on GitHub-hosted runners by default. It moves to our own runner when
4+
both of these are true:
5+
6+
1. A runner with the labels `self-hosted` and `noderings` is online.
7+
2. The repository variable `NODERINGS_RUNNER` is `true`.
8+
9+
Clear the variable (or set it to anything else) to go back to GitHub-hosted
10+
runners at once, for example while the runner is down.
11+
12+
These always stay on GitHub-hosted runners, whatever the variable says:
13+
14+
- pull requests from forks (their code is untrusted)
15+
- the `CI result` summary job
16+
- building and publishing releases (`release.yml`)
17+
- the GitHub Pages deploy job
18+
19+
## Recommended setup: one dedicated NodeRings VM, repository-level runner
20+
21+
Use a small Ubuntu 24.04 (x64) virtual machine ordered on NodeRings, used for
22+
nothing else, with the GitHub Actions runner installed as a service.
23+
24+
Why this option:
25+
26+
- **A dedicated VM, not the production Kubernetes cluster.** CI runs code from
27+
pull requests. Keep it away from production workloads, cluster credentials
28+
and Argo CD. actions-runner-controller on the prod cluster would put CI
29+
pods next to production.
30+
- **The GitHub Actions runner, not Woodpecker or Forgejo.** The code, pull
31+
requests and branch protection live on GitHub. The native runner reports
32+
ordinary check runs, so branch protection, approvals and logs work
33+
unchanged. Woodpecker or a Forgejo runner would need a separate CI server,
34+
webhooks and mirroring for the same result.
35+
- **Repository-level, not organization-level.** The noderings organization
36+
is on the Free plan, which only has the Default runner group. An
37+
organization runner there would serve every public repository in the
38+
organization. A repository runner only takes jobs from this repository.
39+
Register one per repository (one VM can host several runner services, each
40+
in its own directory and user), or move to an organization runner group
41+
limited to selected repositories once the organization is on a paid plan.
42+
43+
### 1. Lock down fork pull requests first
44+
45+
GitHub warns that self-hosted runners on public repositories can run code
46+
from anyone who can open a pull request. A fork can edit the workflow files in
47+
its own pull request, so the `runs-on` guard in our workflows is not enough by
48+
itself.
49+
50+
- Repository → Settings → Actions → General → *Approval for running fork pull
51+
request workflows from contributors* → **Require approval for all external
52+
contributors**. (This repository already has this setting.)
53+
- Before approving a fork run, read every change under `.github/`. Never
54+
approve a run that changes `runs-on` or adds `self-hosted`.
55+
- Never use `pull_request_target` together with a checkout of the pull
56+
request's code.
57+
58+
### 2. Prepare the VM
59+
60+
As root on the new VM:
61+
62+
```bash
63+
apt-get update
64+
apt-get install -y --no-install-recommends \
65+
git curl ca-certificates jq make build-essential \
66+
libenchant-2-2 python3-dev python3-venv
67+
# An unprivileged user for the runner, without sudo.
68+
useradd --create-home --shell /bin/bash runner
69+
# Tool cache for actions/setup-python.
70+
install -d -o runner -g runner /opt/hostedtoolcache
71+
```
72+
73+
Keep the VM patched (`unattended-upgrades`), open no inbound ports (the runner
74+
only makes outbound HTTPS connections to GitHub), and do not store other
75+
credentials on it.
76+
77+
### 3. Register the runner
78+
79+
1. Open <https://github.com/noderings/saltext-noderings/settings/actions/runners/new>
80+
(Settings → Actions → Runners → **New self-hosted runner**), pick
81+
**Linux** and **x64**. The page shows a registration token that is valid
82+
for one hour. Use it only in the VM's shell. Do not paste it anywhere else.
83+
2. As the `runner` user on the VM:
84+
85+
```bash
86+
mkdir -p ~/actions-runner && cd ~/actions-runner
87+
curl -fsSLO https://github.com/actions/runner/releases/download/v2.338.2/actions-runner-linux-x64-2.338.2.tar.gz
88+
echo "baebf204307bac6193480852732f0aba2ae97b6c5597c244f4d5558390147c40 actions-runner-linux-x64-2.338.2.tar.gz" | sha256sum -c
89+
tar xzf actions-runner-linux-x64-2.338.2.tar.gz
90+
echo "AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache" >> .env
91+
./config.sh --unattended \
92+
--url https://github.com/noderings/saltext-noderings \
93+
--token <TOKEN FROM THE PAGE> \
94+
--name noderings-ci-1 \
95+
--labels noderings \
96+
--work _work
97+
```
98+
99+
`self-hosted`, `Linux` and `X64` are added automatically. `noderings` is
100+
the label the workflows ask for.
101+
3. Back as root, install and start the service:
102+
103+
```bash
104+
cd /home/runner/actions-runner
105+
./svc.sh install runner
106+
./svc.sh start
107+
```
108+
109+
4. The runner should now show as **Idle** on
110+
<https://github.com/noderings/saltext-noderings/settings/actions/runners>.
111+
112+
### 4. Switch CI over
113+
114+
Repository → Settings → Secrets and variables → Actions → **Variables** →
115+
New repository variable: `NODERINGS_RUNNER` = `true`.
116+
Then re-run CI on `main` (Actions → CI → Run workflow) and check that the jobs
117+
show the runner name `noderings-ci-1`.
118+
119+
To switch back, delete the variable or set it to `false`.
120+
121+
### Optional: live API tests
122+
123+
Live tests run only when the repository secret `NODERINGS_TOKEN` exists. It
124+
should be a service account token for a separate test organization with a
125+
small credit balance. Fork pull requests never get secrets. Tests that order
126+
billed servers only run from a manual CI run with *billed* ticked.
127+
128+
### Later: ephemeral runners
129+
130+
A persistent runner keeps its work directory between jobs. Our workflows clean
131+
up after themselves and only trusted code reaches the runner, so this is
132+
acceptable to start with. To give every job a fresh machine, register with
133+
`--ephemeral`, then re-register after each job. This needs a GitHub App with
134+
the *Administration: write* repository permission so the VM can request
135+
registration tokens itself.

‎.github/workflows/ci.yml‎

Lines changed: 110 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: CI
22

3-
on:
3+
# Runs on GitHub-hosted runners until a NodeRings self-hosted runner exists.
4+
# To switch, register a runner with the labels "self-hosted" and "noderings"
5+
# (see .github/self-hosted-runner.md) and set the repository variable
6+
# NODERINGS_RUNNER=true. Pull requests from forks always stay on
7+
# GitHub-hosted runners: never run untrusted code on our own machines.
8+
"on":
49
push:
510
branches: [main]
611
pull_request:
@@ -18,82 +23,149 @@ concurrency:
1823
group: ci-${{ github.ref }}
1924
cancel-in-progress: true
2025

21-
jobs:
22-
format:
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v7
26-
- uses: actions/setup-python@v7
27-
with:
28-
python-version: "3.12"
29-
- run: pip install "black==26.5.1" "isort==8.0.1"
30-
- run: black --check src tests
31-
- run: isort --check-only src tests
26+
env:
27+
PIP_DISABLE_PIP_VERSION_CHECK: "1"
28+
FORCE_COLOR: "1"
3229

33-
lint:
34-
runs-on: ubuntu-latest
30+
jobs:
31+
pre-commit:
32+
name: Pre-commit
33+
runs-on: ${{ (vars.NODERINGS_RUNNER == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) && fromJSON('["self-hosted","noderings"]') || 'ubuntu-latest' }}
34+
timeout-minutes: 30
3535
steps:
36-
- uses: actions/checkout@v7
36+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
3737
with:
3838
fetch-depth: 0
39-
- uses: actions/setup-python@v7
39+
persist-credentials: false
40+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
4041
with:
4142
python-version: "3.12"
42-
- run: pip install -e ".[lint,tests]"
43-
- name: Lint the extension
44-
run: pylint --rcfile=.pylintrc src/saltext/noderings
45-
- name: Lint the tests
46-
run: pylint --rcfile=.pylintrc --disable=redefined-outer-name,unused-argument,import-outside-toplevel tests
43+
- run: python -m pip install pre-commit nox uv
44+
- name: Run all hooks (format, docs stubs, bandit, pylint, actionlint)
45+
run: pre-commit run --all-files --show-diff-on-failure --color=always
4746

4847
unit:
4948
name: Unit (Salt ${{ matrix.salt }}, Python ${{ matrix.python }})
50-
runs-on: ubuntu-latest
49+
runs-on: ${{ (vars.NODERINGS_RUNNER == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) && fromJSON('["self-hosted","noderings"]') || 'ubuntu-latest' }}
50+
timeout-minutes: 20
5151
strategy:
5252
fail-fast: false
5353
matrix:
5454
include:
55-
- {salt: "3006.*", python: "3.11"}
56-
- {salt: "3008.*", python: "3.11"}
57-
- {salt: "3008.*", python: "3.12"}
55+
- {salt: "3006", python: "3.11"}
56+
- {salt: "3007", python: "3.12"}
57+
- {salt: "3008", python: "3.12"}
58+
- {salt: "3008", python: "3.13"}
5859
steps:
59-
- uses: actions/checkout@v7
60+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6061
with:
6162
fetch-depth: 0
62-
- uses: actions/setup-python@v7
63+
persist-credentials: false
64+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
6365
with:
6466
python-version: ${{ matrix.python }}
65-
- run: pip install "salt==${{ matrix.salt }}" -e ".[tests]"
66-
- run: pytest -ra tests/unit
67+
- run: python -m pip install nox uv
68+
- name: Unit tests (nox session from the copier template)
69+
env:
70+
SALT_REQUIREMENT: salt~=${{ matrix.salt }}.0
71+
run: nox -e "tests-${{ matrix.python }}" -- tests/unit
6772

6873
docs:
69-
runs-on: ubuntu-latest
74+
name: Docs
75+
runs-on: ${{ (vars.NODERINGS_RUNNER == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) && fromJSON('["self-hosted","noderings"]') || 'ubuntu-latest' }}
76+
timeout-minutes: 20
7077
steps:
71-
- uses: actions/checkout@v7
78+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
7279
with:
7380
fetch-depth: 0
74-
- uses: actions/setup-python@v7
81+
persist-credentials: false
82+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
7583
with:
7684
python-version: "3.12"
77-
- run: pip install -e ".[docs]"
78-
- run: sphinx-build -W -b html docs docs/_build/html
85+
- name: Check system packages (make, enchant for the spelling extension)
86+
run: |
87+
missing=()
88+
command -v make >/dev/null || missing+=(make)
89+
ldconfig -p | grep -q libenchant-2 || missing+=(libenchant-2-2)
90+
if [ "${#missing[@]}" -gt 0 ]; then
91+
sudo apt-get update -qq && sudo apt-get install -y -qq "${missing[@]}"
92+
fi
93+
- run: python -m pip install nox uv
94+
- name: Build the docs (linkcheck, coverage, HTML; warnings fail)
95+
run: nox -e docs
96+
97+
package:
98+
name: Package
99+
runs-on: ${{ (vars.NODERINGS_RUNNER == 'true' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)) && fromJSON('["self-hosted","noderings"]') || 'ubuntu-latest' }}
100+
timeout-minutes: 15
101+
steps:
102+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
103+
with:
104+
fetch-depth: 0
105+
persist-credentials: false
106+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
107+
with:
108+
python-version: "3.12"
109+
- run: python -m pip install build twine
110+
- run: python -m build
111+
- run: python -m twine check --strict dist/*
112+
- name: Install the wheel and check that Salt loads the extension
113+
run: |
114+
python -m venv /tmp/wheel-venv
115+
/tmp/wheel-venv/bin/pip install -q dist/*.whl
116+
/tmp/wheel-venv/bin/python - <<'PY'
117+
from importlib.metadata import entry_points
118+
eps = [ep for ep in entry_points(group="salt.loader") if ep.name == "saltext.noderings"]
119+
assert eps and eps[0].value == "saltext.noderings", eps
120+
import saltext.noderings.clouds.noderings_mod
121+
import saltext.noderings.modules.noderings_mod
122+
import saltext.noderings.states.noderings_mod
123+
print("entry point and modules OK")
124+
PY
125+
mkdir -p /tmp/salt-root
126+
printf 'root_dir: /tmp/salt-root\nfile_client: local\nuser: %s\n' "$(id -un)" > /tmp/salt-root/minion
127+
/tmp/wheel-venv/bin/salt-call -c /tmp/salt-root --local --out=json sys.list_functions noderings | grep -q '"noderings.list_regions"'
128+
/tmp/wheel-venv/bin/salt-call -c /tmp/salt-root --local --out=json sys.list_state_functions noderings | grep -q '"noderings.vm_present"'
79129
80130
live:
81131
name: Live tests (NodeRings API)
82132
needs: [unit]
83133
# Only where the secret exists; forks and outside pull requests skip.
84134
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
85-
runs-on: ubuntu-latest
135+
runs-on: ${{ vars.NODERINGS_RUNNER == 'true' && fromJSON('["self-hosted","noderings"]') || 'ubuntu-latest' }}
136+
timeout-minutes: 45
86137
env:
87138
NODERINGS_TOKEN: ${{ secrets.NODERINGS_TOKEN }}
88139
NODERINGS_TEST_BILLED: ${{ inputs.billed && '1' || '' }}
89140
steps:
90-
- uses: actions/checkout@v7
141+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
91142
with:
92143
fetch-depth: 0
93-
- uses: actions/setup-python@v7
144+
persist-credentials: false
145+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
94146
with:
95147
python-version: "3.12"
96-
- run: pip install "salt==3008.*" -e ".[tests]"
148+
- run: python -m pip install "salt~=3008.0" -e ".[tests]"
97149
- name: Functional and integration tests
98150
if: env.NODERINGS_TOKEN != ''
99151
run: pytest -ra tests/functional tests/integration
152+
- name: Note the skip
153+
if: env.NODERINGS_TOKEN == ''
154+
run: echo "::notice title=Live tests skipped::Add the repository secret NODERINGS_TOKEN (a service account token for a test organization) to run them."
155+
156+
result:
157+
name: CI result
158+
# The one required status check: it fails if any job above failed.
159+
if: always()
160+
needs: [pre-commit, unit, docs, package, live]
161+
runs-on: ubuntu-latest
162+
timeout-minutes: 5
163+
steps:
164+
- name: Check the job results
165+
env:
166+
RESULTS: ${{ join(needs.*.result, ' ') }}
167+
run: |
168+
echo "Job results: $RESULTS"
169+
for r in $RESULTS; do
170+
case "$r" in success|skipped) ;; *) exit 1 ;; esac
171+
done

0 commit comments

Comments
 (0)