Using Dev Proxy in your GitHub Actions workflow on an Ubuntu hosted VM

In my previous blog post, I explained how you could use the Microsoft’s Dev Proxy in a GitHub Actions workflow on a macOS runner. In this blog post, I will show you how to use the Dev Proxy in your GitHub Actions workflow on an Ubuntu runner.

info

You can read how to configure it on a macOS runner in the Using Dev Proxy in your GitHub Actions workflow on a macOS runner article.

Most of the steps are the same, except how you trust the root certificate.

Installing and running the Dev Proxy

Like the macOS runner, you can install the bash script provided in the Dev Proxy documentation on the Ubuntu runner. To include this into your GitHub Actions workflow, you can use the following step:

Install and run the Dev Proxy - GitHub Actions steps
1
2
3
4
5
- name: Install Dev Proxy
  run: bash -c "$(curl -sL https://aka.ms/devproxy/setup.sh)"

- name: Run Dev Proxy
  run: ./devproxy/devproxy &
info

The Dev Proxy commands is using an ampersand & to run it as a background service. You can read more about it in the #DevHack: Running a background service on GitHub Actions article.

Once the Dev Proxy is installed, you can run it, but you cannot yet intercept HTTPS traffic. That is where the next step comes in. You need to trust the root certificate.

Trust the root certificate

Similar to the macOS configuration, we must trust the self-signed certificate the Dev Proxy created. Here are the steps to achieve the certificate trust on an Ubuntu runner:

Run Dev Proxy - GitHub Actions step
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
- name: Install the Dev Proxy's certificate
  timeout-minutes: 1
  run: |
    echo "Export the Dev Proxy's Root Certificate"
    openssl pkcs12 -in ~/.config/dev-proxy/rootCert.pfx -clcerts -nokeys -out dev-proxy-ca.crt -passin pass:""

    echo "Installing the Dev Proxy's Root Certificate"
    sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/

    echo "Updating the CA certificates"
    sudo update-ca-certificates
    echo "Certificate trusted."

    # Set the system proxy settings (optional)
    echo "http_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
    echo "https_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV    
info

The commands used in the above GitHub Actions step are very similar to how it is configured on a Docker container. You can find the official documentation for the Docker container in Configure Dev Proxy certificate in your Docker container documentation section.

After running this step, you can start intercepting HTTPS traffic with the Dev Proxy.

The complete GitHub Actions workflow

Below, you can find the complete GitHub Actions workflow file, which includes the installation of the Dev Proxy and the trust of the root certificate.

Complete GitHub Actions workflow
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
name: Ubuntu Dev Proxy

on:
  push:
    branches:
      - main
      - dev
  workflow_dispatch:

jobs:
  test:
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4

      - name: Install Dev Proxy
        run: bash -c "$(curl -sL https://aka.ms/devproxy/setup.sh)"

      - name: Run Dev Proxy
        run: ./devproxy/devproxy &

      - name: Install the Dev Proxy's certificate
        timeout-minutes: 1
        run: |
          echo "Export the Dev Proxy's Root Certificate"
          openssl pkcs12 -in ~/.config/dev-proxy/rootCert.pfx -clcerts -nokeys -out dev-proxy-ca.crt -passin pass:""

          echo "Installing the Dev Proxy's Root Certificate"
          sudo cp dev-proxy-ca.crt /usr/local/share/ca-certificates/

          echo "Updating the CA certificates"
          sudo update-ca-certificates
          echo "Certificate trusted."

          # Set the system proxy settings (optional)
          echo "http_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV
          echo "https_proxy=http://127.0.0.1:8000" >> $GITHUB_ENV          

      # Include the additional steps you want to run after the Dev Proxy started
      - name: Test the Dev Proxy
        run: |
          curl -ix http://127.0.0.1:8000 https://jsonplaceholder.typicode.com/posts
          # When you used the system proxy settings, you don't need to specify the proxy in the curl command
          curl -i https://jsonplaceholder.typicode.com/posts          
Show image Test Dev Proxy on GitHub Actions
Test Dev Proxy on GitHub Actions

With this setup, you can use the Dev Proxy in your GitHub Actions workflow on a Ubuntu runner.

info

Templates are available on the following GitHub repository.

Comments

Back to top