Skip to content

Commit 0df1407

Browse files
committed
consolidate local/ci test steps in a shell script
1 parent fb98e88 commit 0df1407

File tree

3 files changed

+152
-22
lines changed

3 files changed

+152
-22
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,7 @@ jobs:
7777
NETFOUNDRY_CLIENT_ID: ${{ secrets.NETFOUNDRY_CLIENT_ID }}
7878
NETFOUNDRY_PASSWORD: ${{ secrets.NETFOUNDRY_PASSWORD }}
7979
NETFOUNDRY_OAUTH_URL: ${{ secrets.NETFOUNDRY_OAUTH_URL }}
80-
run: |
81-
set -o xtrace
82-
set -o pipefail
83-
84-
nfctl config \
85-
general.network=$(nfctl demo --echo-name --prefix 'gh-${{ github.run_id }}') \
86-
general.yes=True \
87-
general.verbose=yes || true # FIXME: sometimes config command exits with an error
88-
nfctl --wait 3000 demo \
89-
--size medium \
90-
--regions us-west-2 us-east-1 \
91-
--provider AWS
92-
nfctl \
93-
list services
94-
nfctl \
95-
get service name=echo% > /tmp/echo.yml
96-
nfctl \
97-
delete service name=echo%
98-
nfctl \
99-
create service --file /tmp/echo.yml
100-
nfctl \
101-
delete network
80+
run: ./scripts/test-demo.sh
10281

10382
- name: Publish Test Package
10483
uses: pypa/gh-action-pypi-publish@v1.13.0

scripts/README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Test Scripts
2+
3+
## test-demo.sh
4+
5+
Test script for the `nfctl demo` command. Can be run locally or in GitHub Actions.
6+
7+
### Usage
8+
9+
**In GitHub Actions:**
10+
11+
```yaml
12+
- name: Run demo test
13+
env:
14+
NETFOUNDRY_CLIENT_ID: ${{ secrets.NETFOUNDRY_CLIENT_ID }}
15+
NETFOUNDRY_PASSWORD: ${{ secrets.NETFOUNDRY_PASSWORD }}
16+
NETFOUNDRY_OAUTH_URL: ${{ secrets.NETFOUNDRY_OAUTH_URL }}
17+
run: ./scripts/test-demo.sh
18+
```
19+
20+
The script automatically detects GitHub Actions via `GITHUB_RUN_ID` and uses it in the network name prefix.
21+
22+
**Locally:**
23+
24+
```bash
25+
# Use default prefix (local-<timestamp>)
26+
./scripts/test-demo.sh
27+
28+
# Use custom prefix
29+
DEMO_PREFIX=mytest ./scripts/test-demo.sh
30+
31+
# Specify organization and network group
32+
NETFOUNDRY_ORGANIZATION=acme \
33+
NETFOUNDRY_NETWORK_GROUP=testing \
34+
DEMO_PREFIX=mytest \
35+
./scripts/test-demo.sh
36+
```
37+
38+
### What it does
39+
40+
1. Creates a temporary directory and config file (cleaned up on exit)
41+
2. Generates a unique network name using `--echo-name`
42+
3. Configures nfctl with all settings in the temp config:
43+
- Network name (generated)
44+
- Organization (from `NETFOUNDRY_ORGANIZATION` if set)
45+
- Network group (from `NETFOUNDRY_NETWORK_GROUP` if set)
46+
- Auto-confirm and verbose flags
47+
4. Runs the demo with medium size, AWS provider, us-west-2 and us-east-1 regions
48+
5. Tests service operations (list, get, delete, create)
49+
6. Cleans up by deleting the network and removing temp directory
50+
51+
### Environment Variables
52+
53+
**Script Configuration:**
54+
55+
- `GITHUB_RUN_ID` - Auto-detected in GitHub Actions, used for network prefix
56+
- `DEMO_PREFIX` - Custom prefix for local runs (default: `local-<timestamp>`)
57+
- `NETFOUNDRY_PROFILE` - Profile name for token cache isolation (default: `default`)
58+
59+
**Standard NetFoundry Environment Variables:**
60+
61+
- `NETFOUNDRY_ORGANIZATION` - Optional organization name (omitted if unset)
62+
- `NETFOUNDRY_NETWORK_GROUP` - Optional network group name (omitted if unset)
63+
- `NETFOUNDRY_CLIENT_ID` - NetFoundry API credentials
64+
- `NETFOUNDRY_PASSWORD` - NetFoundry API credentials
65+
- `NETFOUNDRY_OAUTH_URL` - NetFoundry OAuth URL
66+
- `NETFOUNDRY_API_ACCOUNT` - Path to API credentials JSON file
67+
68+
These standard variables match those used by `nfctl login --eval` for consistency.
69+
70+
**Profile Usage:**
71+
72+
The `NETFOUNDRY_PROFILE` variable allows you to isolate token caches for different accounts. Each profile uses a separate cache file (`~/.cache/netfoundry/<profile>.json`), preventing conflicts when working with multiple NetFoundry accounts.
73+
74+
```bash
75+
# Use a specific profile
76+
NETFOUNDRY_PROFILE=advdev \
77+
NETFOUNDRY_API_ACCOUNT=~/.config/netfoundry/advdev.json \
78+
./scripts/test-demo.sh
79+
```
80+
81+
### Features
82+
83+
- **Isolated config**: Each run uses a temporary config file that doesn't interfere with your existing nfctl configuration
84+
- **Auto-cleanup**: Temporary directory is automatically removed on exit (success or failure)
85+
- **Config-based scoping**: Organization and network group are set in the config file (from environment variables) rather than passed as CLI options on every command

scripts/test-demo.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Test script for nfctl demo command
3+
# Can be run locally or in GitHub Actions
4+
5+
set -o xtrace
6+
set -o pipefail
7+
8+
# Create temporary directory and config file
9+
TEMP_DIR=$(mktemp -d)
10+
TEMP_CONFIG="${TEMP_DIR}/nfctl.ini"
11+
echo "Using temporary config: ${TEMP_CONFIG}"
12+
13+
# Cleanup on exit
14+
trap 'rm -rf "${TEMP_DIR}"' EXIT
15+
16+
# Determine prefix based on environment
17+
if [[ -n "${GITHUB_RUN_ID}" ]]; then
18+
# Running in GitHub Actions
19+
PREFIX="gh-${GITHUB_RUN_ID}"
20+
else
21+
# Running locally - use timestamp or custom prefix
22+
PREFIX="${DEMO_PREFIX:-local-$(date +%s)}"
23+
fi
24+
25+
echo "Using demo prefix: ${PREFIX} (override with DEMO_PREFIX)"
26+
27+
# Set profile (default: "default")
28+
: "${NETFOUNDRY_PROFILE:=default}"
29+
echo "Using profile: ${NETFOUNDRY_PROFILE} (override with NETFOUNDRY_PROFILE)"
30+
31+
# Helper function to run nfctl with the temp config and profile
32+
nfctl() {
33+
command nfctl --profile "${NETFOUNDRY_PROFILE}" --config-file "${TEMP_CONFIG}" "$@"
34+
}
35+
36+
# Configure nfctl with generated network name and basic settings
37+
nfctl config \
38+
"general.network=$(command nfctl demo --echo-name --prefix "${PREFIX}")" \
39+
general.yes=True \
40+
general.verbose=yes || true # FIXME: sometimes config command exits with an error
41+
42+
# Set optional organization and network group from standard NetFoundry env vars
43+
if [[ -n "${NETFOUNDRY_ORGANIZATION}" ]]; then
44+
nfctl config "general.organization=${NETFOUNDRY_ORGANIZATION}"
45+
fi
46+
if [[ -n "${NETFOUNDRY_NETWORK_GROUP}" ]]; then
47+
nfctl config "general.network_group=${NETFOUNDRY_NETWORK_GROUP}"
48+
fi
49+
50+
# Run the demo
51+
nfctl --wait 3000 demo \
52+
--size medium \
53+
--regions us-west-2 us-east-1 \
54+
--provider AWS
55+
56+
# Test service operations
57+
nfctl list services
58+
59+
nfctl get service name=echo% > /tmp/echo.yml
60+
61+
nfctl delete service name=echo%
62+
63+
nfctl create service --file /tmp/echo.yml
64+
65+
# Cleanup: delete the network
66+
nfctl delete network

0 commit comments

Comments
 (0)