-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (116 loc) · 4.61 KB
/
policy_docs.yml
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#################################
## DOCS STATIC SITE Build/Test ##
## Reusable Workflow ##
#################################
### TOOLS ###
# - mkdocs
# - sphinx
## AUTONOMOUS JOB ##
# 0. Never run
# 1. Always run
# 2. Run Docs on conditions
# - Triggered on a Long-living branch (ie main)
# - Triggered on a v* tag (ie v1.0.0)
# - Docs Source Files (ie docs/) changed, compared to previous commit
# 3. Run Docs, if Source Files changed, compared to previous commit
on:
workflow_call:
inputs:
# Defaults to Policy 2 (CI/CD)
run_policy:
default: '2'
type: string
description: 'Policy for when to run Docs Build'
required: false
dedicated_branches:
default: 'main, master, dev'
type: string
description: "Branches to always want to run Docs Build. Has effect only on Policy '2'"
required: false
source_code_targets:
default: 'docs/'
type: string
required: false
description: "Comma separated list of folders to watch for changes. Has effect only on Policy '2' and '3'"
## BUILD COMMAND
command:
default: 'tox -e docs --sitepackages -vv -s false'
type: string
description: 'Docs Build Command to run'
required: false
## Parametrizing Runtime Environment (ie py version)
python_version:
default: '3.10'
type: string
description: 'Python Interpreter Version to use for Docs Build Environment'
required: false
jobs:
docs_policy:
name: "Run Docs Workflow/Job?"
runs-on: ubuntu-latest
if: always() && inputs.run_policy != 0
steps:
- if: ${{ !contains('1, 2, 3', inputs.run_policy) }}
run: 'echo "Invalid run_policy: ${{ inputs.run_policy }}. Must be >0 and <4" && exit 1'
- if: inputs.run_policy == 1
name: 'POLICY: 1 -> Trigger'
run: echo "SHOULD_RUN_DOCS=true" >> $GITHUB_ENV
- if: inputs.run_policy == 2 && contains(inputs.dedicated_branches, github.ref_name)
name: 'POLICY: 2 & Branch: ${{ github.ref_name }} -> Trigger'
run: echo "SHOULD_RUN_DOCS=true" >> $GITHUB_ENV
- if: inputs.run_policy == 2 && startsWith(github.ref, 'refs/tags/v')
name: 'POLICY: 2 & Tag: ${{ github.ref_name }} -> Trigger'
run: echo "SHOULD_RUN_DOCS=true" >> $GITHUB_ENV
- if: ${{ env.SHOULD_RUN_DOCS != 'true' && contains('2, 3', inputs.run_policy) }}
name: 'POLICY: 2, 3 -> Derive from DIFF'
run: echo "SHOULD_DERIVE_FROM_DIFF=true" >> $GITHUB_ENV
- if: ${{ env.SHOULD_DERIVE_FROM_DIFF }}
name: 'POLICY: 2, 3 -> Checkout Code to compute DIFF'
uses: actions/checkout@v4
with:
fetch-depth: 2
- if: ${{ env.SHOULD_DERIVE_FROM_DIFF }}
name: 'POLICY: 2, 3 -> Check Docs Source Files DIFF'
run: |
echo "============ List Modified Files ============"
git diff --name-only HEAD^ HEAD
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
# Read Folders we 'Watch' for changes
TARGETS=$(echo "${{ inputs.source_code_targets }}" | tr ',' '\n')
# Loop through the Watched Folders
for TARGET in $TARGETS; do
# if rel path of changed file matches glob pattern
if [[ $CHANGED_FILES == *"$TARGET"* ]]; then
echo "SHOULD_RUN_DOCS=true" >> $GITHUB_ENV
echo " --> DOCS Change, from previous commit, found: $TARGET"
break
fi
done
### OUTPUT of JOB ###
- name: "Set 'Run Docs' Signal to ${{ env.SHOULD_RUN_DOCS }}"
id: set_docs_signal
run: echo "RUN_DOCS=${{ env.SHOULD_RUN_DOCS }}" >> $GITHUB_OUTPUT
outputs:
RUN_DOCS: ${{ steps.set_docs_signal.outputs.RUN_DOCS }}
docs:
name: "Docs: Build & Test"
runs-on: ubuntu-latest
needs: docs_policy
if: always() && needs.docs_policy.outputs.RUN_DOCS == 'true'
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ inputs.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
- name: Install Tox
run: |
python -m pip install --upgrade pip
python -m pip install tox==3.28
- name: Install Build dependencies
if: ${{ matrix.platform == 'macos-latest' && matrix.python-version != '3.6' }}
run: brew install enchant
- name: Build Documentation and Test
if: ${{ matrix.platform == 'ubuntu-latest' || matrix.python-version != '3.6' }}
run: ${{ inputs.command }}
# run: tox -e docs --sitepackages -vv -s false