-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaction.yml
189 lines (172 loc) · 8.79 KB
/
action.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
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
name: 'Render TYPO3 Documentation'
description: 'Uses render-guides to render documentation.'
branding:
icon: 'book-open'
color: 'orange'
inputs:
repository_url:
description: 'Repository to render'
required: false
default: https://github.com/${{ github.repository }}.git
source_branch:
description: 'Branch to render'
required: false
target_branch_directory:
description: 'Target Branch Directory'
required: false
outputs:
renderedPath:
description: "The path to the final rendered documentation incl. language versions."
value: ${{ steps.output.outputs.renderedPath }}
runs:
using: "composite"
steps:
- id: prepare
shell: bash
env:
GITHUB_REF: ${{ github.ref }}
run: |
if [[ '${{ inputs.source_branch }}' ]]; then
echo "source_branch=${{ inputs.source_branch }}" >> $GITHUB_ENV
else
echo "source_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
if [[ '${{ inputs.target_branch_directory }}' ]]; then
echo "target_branch_directory=${{ inputs.target_branch_directory }}" >> $GITHUB_ENV
else
echo "target_branch_directory=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
- id: checkout
shell: bash
run: |
git clone --depth 1 ${{ inputs.repository_url }} -b ${{ env.source_branch }} t3docsproject
- id: enable_guides
working-directory: t3docsproject
shell: bash
run: (test -e Documentation/guides.xml && echo "MIGRATED=true" || echo "MIGRATED=false") >> $GITHUB_OUTPUT
- id: pre-render-guides
working-directory: t3docsproject
shell: bash
run: mkdir -p RenderedDocumentation/Result/project/0.0.0
- id: migrate
if: steps.enable_guides.outputs.MIGRATED == 'false'
shell: bash
working-directory: t3docsproject
run: |
echo "::warning file=Documentation/Settings.cfg,line=1,title=Please migrate::Forced migration activated. Your project is not yet using the PHP-based rendering, please properly migrate: https://docs.typo3.org/m/typo3/docs-how-to-document/main/en-us/Howto/Migration/Index.html"
docker run --rm --user=$(id -u):$(id -g) \
--pull always \
-v $(pwd):/project \
ghcr.io/typo3-documentation/render-guides:latest \
migrate Documentation
- uses: TYPO3-Documentation/render-guides@main
id: render-guides
with:
working-directory: /github/workspace/t3docsproject
config: /github/workspace/t3docsproject/Documentation/
output: ./RenderedDocumentation/Result/project/0.0.0
configure-branch: ${{ env.source_branch }}
configure-project-release: ${{ env.target_branch_directory }}
configure-project-version: ${{ env.target_branch_directory }}
- id: render-guides-localization
shell: bash
working-directory: t3docsproject
run: |
echo "::group::Prepare move of possible localizations by render-guides"
# "render-guides" uses a different directory structure than sphinx did.
# Sphinx puts localizations OUTSIDE the main 0.0.0 directory tree, using "xx-yy"
# render-guides puts localizations WITHIN the main 0.0.0 directory tree, and
# uses "Localization.xx_YY" directory names
# This step harmonizes that to the expected sphinx directory structure.
# Expected directory structure BEFORE:
# RenderedDocumentation/Result/project/0.0.0/Index.html
# RenderedDocumentation/Result/project/0.0.0/Sub/Index.html
# RenderedDocumentation/Result/project/0.0.0/Localization.de_DE/Index.html
# RenderedDocumentation/Result/project/0.0.0/Localization.de_DE/Sub/Index.html
# RenderedDocumentation/Result/project/0.0.0/Localization.ru_RU/Index.html
# RenderedDocumentation/Result/project/0.0.0/Localization.ru_RU/Sub/Index.html
# Expected directory structure AFTER:
# RenderedDocumentation/Result/project/0.0.0/Index.html
# RenderedDocumentation/Result/project/0.0.0/Sub/Index.html
# RenderedDocumentation/Result/project/de-de/0.0.0/Index.html
# RenderedDocumentation/Result/project/de-de/0.0.0/Sub/Index.html
# RenderedDocumentation/Result/project/ru-ru/0.0.0/Index.html
# RenderedDocumentation/Result/project/ru-ru/0.0.0/Sub/Index.html
projectBaseDirectory="RenderedDocumentation/Result/project/0.0.0/"
if [ -d $projectBaseDirectory ]; then
currentWorkingDir=$(pwd)
cd $projectBaseDirectory
for localizationDirectory in Localization.*; do
echo "$localizationDirectory check..."
if [[ -d $localizationDirectory ]]; then
sub_dir_name=$(echo "$localizationDirectory" | sed 's/Localization.//' | tr '[:upper:]' '[:lower:]' | tr '_' '-')
echo " Operating on $sub_dir_name"
# Check if the subdirectory name matches the required pattern
if [[ $sub_dir_name =~ ^[a-z]+-[a-z]+$ ]]; then
# Move something like:
# > RenderedDocumentation/Result/project/0.0.0/Localization.ru_RU/
# to
# > RenderedDocumentation/Result/project/ru_RU/0.0.0
# This will allow further processing in the next steps.
echo " Move $localizationDirectory to ../$sub_dir_name/0.0.0"
mkdir -p "../$sub_dir_name"
mv "$localizationDirectory" "../$sub_dir_name/0.0.0"
else
echo " Invalid localization."
fi
else
echo " Not a directory."
fi
done
cd $currentWorkingDir
fi
echo "::endgroup::"
- id: langhandling
shell: bash
working-directory: t3docsproject
run: |
echo "::group::Prepare final structure"
# Expected directory structure BEFORE:
# RenderedDocumentation/Result/project/0.0.0/Index.html
# RenderedDocumentation/Result/project/0.0.0/Sub/Index.html
# RenderedDocumentation/Result/project/de-de/0.0.0/Index.html
# RenderedDocumentation/Result/project/de-de/0.0.0/Sub/Index.html
# RenderedDocumentation/Result/project/ru-ru/0.0.0/Index.html
# RenderedDocumentation/Result/project/ru-ru/0.0.0/Sub/Index.html
# Expected directory structure AFTER:
# FinalDocumentation/en-us/Index.html
# FinalDocumentation/en-us/Sub/Index.html
# FinalDocumentation/de-de/Index.html
# FinalDocumentation/de-de/Sub/Index.html
# FinalDocumentation/ru-ru/Index.html
# FinalDocumentation/ru-ru/Sub/Index.html
# if a result has been rendered for the main directory, we treat that as the 'en_us' version
if [ -d RenderedDocumentation/Result/project/0.0.0/ ]; then
echo "Handling main doc result as en-us version"
mkdir -p FinalDocumentation/en-us
# Move en-us files to target dir, including dot files
(shopt -s dotglob; mv RenderedDocumentation/Result/project/0.0.0/* FinalDocumentation/en-us)
# Remove the directory, all content has been moved
rmdir RenderedDocumentation/Result/project/0.0.0/
# Remove a possibly existing Localization.en_us directory, if it exists
rm -rf RenderedDocumentation/Result/project/en-us/
fi
# now see if other localization versions have been rendered. if so, move them to FinalDocumentation/, too
if [ "$(ls -A RenderedDocumentation/Result/project/)" ]; then
for LOCALIZATIONDIR in RenderedDocumentation/Result/project/*; do
LOCALIZATION=`basename $LOCALIZATIONDIR`
echo "Handling localized documentation version ${LOCALIZATION:?Localization could not be determined}"
mkdir FinalDocumentation/${LOCALIZATION}
(shopt -s dotglob; mv ${LOCALIZATIONDIR}/0.0.0/* FinalDocumentation/${LOCALIZATION})
# Remove the localization dir, it should be empty now
rmdir ${LOCALIZATIONDIR}/0.0.0/
rmdir ${LOCALIZATIONDIR}
done
fi
echo "::endgroup::"
- id: output
shell: bash
working-directory: t3docsproject
run: |
rm -Rf RenderedDocumentation
echo "renderedPath=t3docsproject/FinalDocumentation/" >> $GITHUB_OUTPUT