Skip to content

Commit a8a4201

Browse files
authored
Add optional auto-stop parameter to start action (#8)
1 parent 123a422 commit a8a4201

File tree

3 files changed

+72
-69
lines changed

3 files changed

+72
-69
lines changed

.github/workflows/test-all.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ jobs:
1919

2020
- name: Start Dev Proxy
2121
id: start-devproxy
22-
uses: ./start
23-
with:
24-
logFile: ${{ env.LOG_FILE }}
22+
uses: ./start
2523

2624
- name: Start recording
2725
id: start-recording
@@ -36,10 +34,6 @@ jobs:
3634
id: stop-recording
3735
uses: ./record-stop
3836

39-
- name: Stop Dev Proxy
40-
id: stop-devproxy
41-
uses: ./stop
42-
4337
- name: Show logs
4438
run: |
4539
echo "Dev Proxy logs:"

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ Start Dev Proxy with optional configuration file. Dev Proxy will run in the back
3838
uses: dev-proxy-tools/actions/start@v0
3939
with:
4040
log-file: devproxy.log # optional, defaults to devproxy.log
41-
config-file: ./devproxyrc.json # optional, will use default configuration if not provided
41+
config-file: ./devproxyrc.json # optional, will use default configuration if not provided
42+
auto-stop: true # optional, defaults to false
4243
```
4344

4445
**Inputs:**
4546

4647
| Name | Description | Required | Default |
4748
|------|-------------|----------|---------|
4849
| `log-file` | The file to log Dev Proxy output to | Yes | `devproxy.log` |
49-
| `config-file` | The path to the Dev Proxy configuration file | No | - |
50+
| `config-file` | The path to the Dev Proxy configuration file | No | Uses default configuration |
51+
| `auto-stop` | Automatically stop Dev Proxy after the workflow completes | No | `true` |
5052

5153
### Stop
5254

start/action.yml

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,78 +8,85 @@ inputs:
88
config-file:
99
description: The path to the Dev Proxy configuration file
1010
required: false
11+
auto-stop:
12+
description: Automatically stop Dev Proxy when workflow completes
13+
required: false
14+
default: "true"
1115
runs:
1216
using: composite
1317
steps:
14-
- name: Start Dev Proxy
15-
id: start
16-
run: |
17-
log_file="${{ inputs.log-file }}"
18+
- name: Start Dev Proxy with post step
19+
id: stat-with-post-step
20+
uses: pyTooling/Actions/[email protected]
21+
with:
22+
main: |
23+
log_file="${{ inputs.log-file }}"
1824
19-
echo "Starting Dev Proxy..."
25+
echo "Starting Dev Proxy..."
2026
21-
# Create directory for Dev Proxy configuration and certificates
22-
mkdir -p ~/.config/dev-proxy/rootCert
27+
# Create directory for Dev Proxy configuration and certificates
28+
mkdir -p ~/.config/dev-proxy/rootCert
2329
24-
# Set environment variables for Dev Proxy
25-
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
26-
export XDG_DATA_HOME=~/.config
27-
export DEV_PROXY_CERT_PATH=rootCert/rootCert.pfx
30+
# Set environment variables for Dev Proxy
31+
export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
32+
export XDG_DATA_HOME=~/.config
33+
export DEV_PROXY_CERT_PATH=rootCert/rootCert.pfx
2834
29-
echo "cert-path=$DEV_PROXY_CERT_PATH" >> $GITHUB_OUTPUT
35+
# Create cert-path
36+
cert_path="$XDG_DATA_HOME/dev-proxy/$DEV_PROXY_CERT_PATH"
3037
31-
# start Dev Proxy in the background
32-
# log Dev Proxy output to the log file
33-
# log stdout and stderr to the file
34-
config_arg=""
35-
if [ -n "${{ inputs.config-file }}" ]; then
36-
config_arg="-c ${{ inputs.config-file }}"
37-
fi
38-
39-
./devproxy/devproxy $config_arg > $log_file 2>&1 &
38+
# start Dev Proxy in the background
39+
# log Dev Proxy output to the log file
40+
# log stdout and stderr to the file
41+
config_arg=""
42+
if [ -n "${{ inputs.config-file }}" ]; then
43+
config_arg="-c ${{ inputs.config-file }}"
44+
fi
4045
41-
proxy_pid=$!
46+
./devproxy/devproxy $config_arg > $log_file 2>&1 &
4247
43-
# wait for init
44-
echo "Waiting for Dev Proxy to start..."
45-
while true; do
46-
if grep -q "Configure your operating system to use this proxy's port and address 127.0.0.1:8000" $log_file; then
47-
break
48-
fi
49-
sleep 1
50-
done
51-
shell: bash
52-
- name: Trust certificate
53-
id: trust-certificate
54-
run: |
55-
echo "🔒 Trusting Dev Proxy certificate..."
56-
57-
# Use the cert-path from the start step output
58-
cert_path="$HOME/.config/dev-proxy/${{ steps.start.outputs.cert-path }}"
48+
proxy_pid=$!
5949
60-
echo "Checking for certificate at: $cert_path"
61-
if [ -f "$cert_path" ]; then
62-
echo "✅ Certificate found"
63-
64-
echo "Exporting the Dev Proxy's Root Certificate"
65-
if openssl pkcs12 -in "$cert_path" -clcerts -nokeys -out dev-proxy-ca.crt -passin pass:""; then
66-
echo "Installing the Dev Proxy's Root Certificate"
67-
sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/
50+
# wait for init
51+
echo "Waiting for Dev Proxy to start..."
52+
while true; do
53+
if grep -q "Configure your operating system to use this proxy's port and address 127.0.0.1:8000" $log_file; then
54+
break
55+
fi
56+
sleep 1
57+
done
6858
69-
echo "Updating the CA certificates"
70-
sudo update-ca-certificates
59+
echo "🔒 Trusting Dev Proxy certificate..."
60+
61+
echo "Checking for certificate at: $cert_path"
62+
if [ -f "$cert_path" ]; then
63+
echo "✅ Certificate found"
7164
72-
# Set the system proxy settings
73-
echo "http_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
74-
echo "https_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
75-
76-
echo "✅ Dev Proxy certificate trusted successfully!"
65+
echo "Exporting the Dev Proxy's Root Certificate"
66+
if openssl pkcs12 -in "$cert_path" -clcerts -nokeys -out dev-proxy-ca.crt -passin pass:""; then
67+
echo "Installing the Dev Proxy's Root Certificate"
68+
sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/
69+
70+
echo "Updating the CA certificates"
71+
sudo update-ca-certificates
72+
73+
# Set the system proxy settings
74+
echo "http_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
75+
echo "https_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
76+
77+
echo "✅ Dev Proxy certificate trusted successfully!"
78+
else
79+
echo "❌ Failed to export certificate from $cert_path"
80+
echo "⚠️ SSL verification may fail"
81+
fi
7782
else
78-
echo "❌ Failed to export certificate from $cert_path"
79-
echo "⚠️ SSL verification may fail"
83+
echo "❌ Certificate not found at: $cert_path"
84+
echo "⚠️ Skipping certificate trust - SSL verification may fail"
85+
fi
86+
post: |
87+
if [ "${{ inputs.auto-stop }}" = "true" ]; then
88+
echo "Stopping Dev Proxy..."
89+
curl -X POST http://127.0.0.1:8897/proxy/stopproxy
90+
echo "Dev Proxy has been stopped."
8091
fi
81-
else
82-
echo "❌ Certificate not found at: $cert_path"
83-
echo "⚠️ Skipping certificate trust - SSL verification may fail"
84-
fi
85-
shell: bash
92+
shell: bash

0 commit comments

Comments
 (0)