Skip to content

Commit 41e92cf

Browse files
authored
test: validate sh code-blocks in examples (#273)
1 parent 9d29dc7 commit 41e92cf

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

.github/workflows/examples.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Examples
2+
on:
3+
pull_request:
4+
paths:
5+
- "**.go"
6+
- "go.mod"
7+
- "go.sum"
8+
- "examples/**.md"
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout head
15+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
16+
- name: Setup Go
17+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
18+
with:
19+
go-version-file: "go.mod"
20+
- name: Install mdtest and upctl
21+
run: |
22+
go install github.com/UpCloudLtd/mdtest@latest
23+
make build
24+
echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH
25+
- name: Test examples
26+
env:
27+
UPCLOUD_USERNAME: ${{ secrets.UPCLOUD_USERNAME }}
28+
UPCLOUD_PASSWORD: ${{ secrets.UPCLOUD_PASSWORD }}
29+
run: |
30+
upctl version
31+
mdtest examples/

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66
- 'go.mod'
77
- 'go.sum'
88
jobs:
9-
platform_tests:
10-
name: Run platform tests
9+
unit-tests:
10+
name: Run unit-tests
1111
strategy:
1212
matrix:
1313
os: [ubuntu-latest, macos-latest, windows-latest]

examples/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
# Examples
22

33
This directory contains examples on more complex `upctl` use-cases. As `upctl` is often used in scripts the examples also aim to parse values from machine readable outputs. This allows using the examples also as end-to-end test cases and makes them more copy-pasteable.
4+
5+
## Testing
6+
7+
The examples in this directory are validated with [mdtest](https://github.com/UpCloudLtd/mdtest). It parses `env` and `sh` code-blocks from the markdown files and executes those as scripts.
8+
9+
The tool can be installed with go install.
10+
11+
```sh
12+
go install github.com/UpCloudLtd/mdtest@latest
13+
```
14+
15+
To test the examples, run `mdtest .`.
16+
17+
```sh
18+
mdtest .
19+
```

0 commit comments

Comments
 (0)