Skip to content

Commit a969911

Browse files
committed
refactor(ci): Improve workflow environment detection and reliability
This commit significantly refactors the CI workflows to be more robust, portable, and reliable across different execution environments (GitHub.com, Gitea, and local `act`). Key changes include: - **Robust Environment Detection:** The primary environment detection logic in the `docs` workflow is overhauled. It no longer relies on a brittle file check. Instead, it now explicitly checks for the `$ACT` environment variable for local `act` runs and the `github.server_url` for Gitea/other self-hosted runners. This provides clearer and more reliable outputs (`is_act`, `is_gitea`, `is_self_hosted`). - **Smarter Network-Dependent Logic:** The decision to use the internal package mirror is no longer tied to the runner type. The `local-setup` action now actively checks for corporate network access by pinging the proxy server and exposes this as an `on-corp-network` output. The dependency installation step now uses this direct, reliable check. - **Consistent Python Invocation:** All calls to `python` have been changed to `python3` to ensure the correct interpreter is used consistently across all environments and to avoid PATH ambiguity. - **Safer Deployment Trigger:** The `deploy` job is now conditionally run based on the `is_self_hosted` output from the `build` job. This ensures that deployments to GitHub Pages are only ever attempted when running on GitHub.com, preventing failures on Gitea and `act`.
1 parent 2b4a6cf commit a969911

2 files changed

Lines changed: 35 additions & 15 deletions

File tree

.github/actions/local-setup/action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,29 @@ inputs:
66
gitea-token:
77
description: 'Token for authenticating with Gitea'
88
required: false
9+
outputs:
10+
on-corp-network:
11+
description: "True if the runner appears to be on the corporate network"
12+
value: ${{ steps.proxy-config.outputs.on-corp-network }}
913

1014
runs:
1115
using: "composite"
1216
steps:
1317
- name: Configure Proxy for Corporate Network
18+
id: proxy-config
1419
shell: bash
1520
run: |
21+
ON_CORP=false
1622
if ping -c 1 dh-cap02 &> /dev/null; then
1723
echo "✅ Proxy server 'dh-cap02' is available. Configuring environment variables."
1824
echo "http_proxy=http://dh-cap02:8008" >> $GITHUB_ENV
1925
echo "https_proxy=http://dh-cap02:8008" >> $GITHUB_ENV
26+
ON_CORP=true
2027
2128
NO_PROXY_LIST="localhost,127.0.0.1,kch-cap.kingsch.nhs.uk,github.com,*.blob.core.windows.net,${ACTIONS_CACHE_URL#http://}"
2229
echo "NO_PROXY=$NO_PROXY_LIST" >> $GITHUB_ENV
2330
fi
31+
echo "on-corp-network=${ON_CORP}" >> $GITHUB_OUTPUT
2432
2533
- name: Install System Dependencies
2634
shell: bash

.github/workflows/docs.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ concurrency:
1919
jobs:
2020
build:
2121
runs-on: ubuntu-latest
22+
outputs:
23+
is_self_hosted: ${{ steps.detect_env.outputs.is_self_hosted }}
2224
env:
2325
DEBIAN_FRONTEND: noninteractive
2426
steps:
@@ -28,29 +30,39 @@ jobs:
2830
- name: Detect Runner Environment
2931
id: detect_env
3032
run: |
31-
if [ -f "/usr/local/share/ca-certificates/kch_certauth.crt" ]; then
32-
echo "is_act_runner=true" >> $GITHUB_OUTPUT
33+
IS_SELF_HOSTED=false
34+
IS_ACT=false
35+
IS_GITEA=false
36+
if [ -n "$ACT" ]; then
37+
echo "Runner environment: local act"
38+
IS_ACT=true
39+
IS_SELF_HOSTED=true
40+
elif [ "${{ github.server_url }}" != "https://github.com" ]; then
41+
echo "Runner environment: Gitea"
42+
IS_GITEA=true
43+
IS_SELF_HOSTED=true
44+
else
45+
echo "Runner environment: GitHub.com"
3346
fi
47+
echo "is_act=$IS_ACT" >> $GITHUB_OUTPUT
48+
echo "is_gitea=$IS_GITEA" >> $GITHUB_OUTPUT
49+
echo "is_self_hosted=$IS_SELF_HOSTED" >> $GITHUB_OUTPUT
3450
3551
- name: Perform Local Runner Setup
3652
id: local_setup
37-
if: steps.detect_env.outputs.is_act_runner == 'true'
53+
if: steps.detect_env.outputs.is_self_hosted == 'true'
3854
uses: ./.github/actions/local-setup
3955
with:
4056
gitea-token: ${{ secrets.GITEA_TOKEN }}
4157

4258
- name: Set up Python
4359
uses: actions/setup-python@v5
44-
env:
45-
http_proxy: ${{ env.http_proxy }}
46-
https_proxy: ${{ env.https_proxy }}
47-
AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
4860
with:
4961
python-version: '3.10.18'
5062
check-latest: false
5163

5264
- name: Fix pip installation
53-
if: steps.detect_env.outputs.is_act_runner == 'true'
65+
if: steps.detect_env.outputs.is_self_hosted == 'true'
5466
run: |
5567
curl -sS https://bootstrap.pypa.io/get-pip.py | python3 - --ignore-installed
5668
python3 -m pip install --upgrade --ignore-installed pip setuptools wheel
@@ -60,25 +72,25 @@ jobs:
6072
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
6173
run: |
6274
pip_install_args=()
63-
if [[ "${{ steps.detect_env.outputs.is_act_runner }}" == "true" ]] && [[ -n "${GITEA_TOKEN}" ]]; then
64-
echo "🔧 Running in act - using local mirror and removing hash requirements"
75+
if [[ "${{ steps.local_setup.outputs.on-corp-network }}" == "true" ]]; then
76+
echo "🔧 On corporate network - using local mirror and removing hash requirements"
6577
find . -name "requirements*.txt" -type f -exec sed -i 's/ --hash=sha256:[a-f0-9]*//g' {} \;
6678
pip_install_args+=("--trusted-host" "dh-cap02" "-i" "http://dh-cap02:8008/mirrors/pat2vec")
6779
fi
6880
6981
echo "Installing project dependencies for docs..."
70-
python -m pip install "${pip_install_args[@]}" -e ".[dev]"
82+
python3 -m pip install "${pip_install_args[@]}" -e ".[dev]"
7183
7284
- name: Build Sphinx documentation
7385
run: |
74-
python -m sphinx.cmd.build -b html docs/source docs/build/html
86+
python3 -m sphinx.cmd.build -b html docs/source docs/build/html
7587
7688
- name: Setup Pages
77-
if: steps.detect_env.outputs.is_act_runner != 'true'
89+
if: steps.detect_env.outputs.is_self_hosted != 'true'
7890
uses: actions/configure-pages@v4
7991

8092
- name: Upload artifact
81-
if: steps.detect_env.outputs.is_act_runner != 'true'
93+
if: steps.detect_env.outputs.is_self_hosted != 'true'
8294
uses: actions/upload-pages-artifact@v3
8395
with:
8496
path: docs/build/html
@@ -89,7 +101,7 @@ jobs:
89101
url: ${{ steps.deployment.outputs.page_url }}
90102
runs-on: ubuntu-latest
91103
needs: build
92-
if: github.server_url == 'https://github.com'
104+
if: needs.build.outputs.is_self_hosted != 'true'
93105
steps:
94106
- name: Deploy to GitHub Pages
95107
id: deployment

0 commit comments

Comments
 (0)