Repository navigation
203 lines (187 loc) · 7.5 KB
/
Copy pathpublish-web.yml
File metadata and controls
203 lines (187 loc) · 7.5 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: Publish opensips.org documentation
on:
# master and the release branches only. Without a branch filter a tag push
# triggers this too (GitHub ignores the paths below for tags), and a tag has
# no "before" commit, so every component looks changed and the whole
# documentation is republished under a version (4.0.1) the site rejects.
push:
branches:
- master
- '[0-9]+.[0-9]+'
paths:
- 'examples/**'
- 'modules/*/samples/**'
- 'net/*/samples/**'
- 'docs/manual/**'
- 'net/*/README.md'
- 'modules/*/README.md'
workflow_dispatch:
inputs:
component:
description: Documentation component to publish
required: true
type: choice
options:
- manual
- modules
- samples
module:
description: Module(s) to publish when component is modules (space-separated)
required: false
default: ''
type: string
permissions:
contents: read
concurrency:
group: publish-web-${{ github.ref }}
cancel-in-progress: true
jobs:
changed-components:
if: github.repository == 'OpenSIPS/opensips'
name: Find changed documentation components
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.components.outputs.matrix }}
has-components: ${{ steps.components.outputs.has-components }}
steps:
- name: Check out the repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Detect changed components
id: components
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE: ${{ github.event.before }}
SHA: ${{ github.sha }}
COMPONENT: ${{ inputs.component }}
MODULE: ${{ inputs.module }}
run: |
all_modules=false
if [[ "$EVENT_NAME" != "push" ]]; then
case "$COMPONENT" in
samples)
changed_files='examples/'
;;
manual)
changed_files='docs/manual/'
;;
modules)
modules_input="$MODULE"
if [[ -z "$modules_input" || "$modules_input" == "all" ]]; then
all_modules=true
changed_files=''
else
changed_files=''
modules_input="${modules_input//,/ }"
read -ra requested_modules <<< "$modules_input"
for module in "${requested_modules[@]}"; do
module="${module#"${module%%[![:space:]]*}"}"
module="${module%"${module##*[![:space:]]}"}"
[[ -z "$module" ]] && continue
changed_files+="$(printf 'modules/%s/README.md\nnet/%s/README.md\n' "$module" "$module")"
done
fi
;;
esac
elif [[ "$BEFORE" == "0000000000000000000000000000000000000000" ]]; then
changed_files="$(git ls-tree -r --name-only "$SHA")"
else
changed_files="$(git diff --name-only "$BEFORE" "$SHA")"
fi
components=()
modules=()
declare -A module_names=()
while IFS= read -r path; do
[[ "$path" =~ ^examples/ ]] && components+=(samples)
[[ "$path" =~ ^docs/manual/ ]] && components+=(manual)
if [[ "$path" =~ ^(net|modules)/([^/]+)/README\.md$ ]]; then
module_names["${BASH_REMATCH[2]}"]=1
elif [[ "$path" =~ ^(modules|net)/([^/]+)/samples/ ]]; then
module_names["${BASH_REMATCH[2]}"]=1
fi
done <<< "$changed_files"
components=( $(printf '%s\n' "${components[@]}" | sort -u) )
for module in "${!module_names[@]}"; do
modules+=("$module")
done
IFS=$'\n' read -r -d '' -a modules < <(printf '%s\n' "${modules[@]}" | sort && printf '\0') || true
if [[ ${#components[@]} -eq 0 && ${#modules[@]} -eq 0 && "$all_modules" != true ]]; then
echo 'has-components=false' >> "$GITHUB_OUTPUT"
echo 'matrix={"include":[]}' >> "$GITHUB_OUTPUT"
exit 0
fi
components_json="$(printf '%s\n' "${components[@]}" | jq -R -s 'split("\n") | map(select(length > 0) | {component: .})')"
modules_json='[]'
if [[ ${#modules[@]} -gt 0 ]]; then
modules_input="$(printf '%s ' "${modules[@]}")"
modules_input="${modules_input% }"
modules_json="$(jq -cn --arg modules "$modules_input" '[{component: "modules", module: $modules}]')"
fi
all_modules_json='[]'
if [[ "$all_modules" == true ]]; then
all_modules_json='[{"component":"modules","all":true}]'
fi
matrix="$(jq -cn --argjson components "$components_json" --argjson modules "$modules_json" --argjson all_modules "$all_modules_json" '{include: ($components + $modules + $all_modules)}')"
echo "has-components=true" >> "$GITHUB_OUTPUT"
echo "matrix=$matrix" >> "$GITHUB_OUTPUT"
- name: Show changed components
env:
MATRIX: ${{ steps.components.outputs.matrix }}
run: |
{
echo '### Changed documentation components'
echo
if [[ "$(echo "$MATRIX" | jq '.include | length')" -eq 0 ]]; then
echo '- None'
else
echo "$MATRIX" | jq -r '.include[] | if .module then "- \(.component): \(.module)" else "- \(.component)" end'
fi
} >> "$GITHUB_STEP_SUMMARY"
dispatch:
if: github.repository == 'OpenSIPS/opensips' && needs.changed-components.outputs.has-components == 'true'
name: Trigger ${{ matrix.component }} publication
needs: changed-components
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.changed-components.outputs.matrix) }}
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ secrets.OPENSIPS_WEB_APP }}
private-key: ${{ secrets.OPENSIPS_WEB_KEY }}
owner: OpenSIPS
repositories: ${{ secrets.OPENSIPS_WEB_REPO }}
permission-actions: write
- name: Trigger samples publication
if: ${{ matrix.component == 'samples' }}
uses: step-security/workflow-dispatch@v1
with:
token: ${{ steps.app-token.outputs.token }}
repo: ${{ secrets.OPENSIPS_WEB_REPO }}
workflow: publish.yml
ref: main
inputs: '{"component": "samples"}'
- name: Trigger manual publication
if: ${{ matrix.component == 'manual' }}
uses: step-security/workflow-dispatch@v1
with:
token: ${{ steps.app-token.outputs.token }}
repo: ${{ secrets.OPENSIPS_WEB_REPO }}
workflow: publish.yml
ref: main
inputs: '{"component": "${{ matrix.component }}", "version": "${{ github.ref_name }}"}'
- name: Trigger modules publication
if: ${{ matrix.component == 'modules' }}
uses: step-security/workflow-dispatch@v1
with:
token: ${{ steps.app-token.outputs.token }}
repo: ${{ secrets.OPENSIPS_WEB_REPO }}
workflow: publish.yml
ref: main
inputs: >-
${{ matrix.all == true && format('{{"component": "modules", "version": "{0}"}}', github.ref_name) || format('{{"component": "modules", "module": "{0}", "version": "{1}"}}', matrix.module, github.ref_name) }}