Skip to content

Commit 25e3e41

Browse files
committed
[build] fix documentation generation tasks
commits should happen in the workflow not in the rake task
1 parent 044097e commit 25e3e41

File tree

2 files changed

+82
-193
lines changed

2 files changed

+82
-193
lines changed

.github/workflows/update-documentation.yml

Lines changed: 35 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -3,227 +3,87 @@ name: Update Documentation
33
on:
44
workflow_dispatch:
55
inputs:
6-
tag:
7-
description: Release tag (e.g. selenium-4.21.0)
6+
version:
7+
description: Release version (e.g., 4.21.0)
88
required: true
99
type: string
10+
language:
11+
description: language documentation
12+
required: true
13+
type: choice
14+
default: "all"
15+
options:
16+
- java
17+
- rb
18+
- py
19+
- dotnet
20+
- node
21+
- all
1022

1123
workflow_call:
1224
inputs:
13-
tag:
25+
version:
26+
required: true
27+
type: string
28+
sha:
1429
required: true
1530
type: string
31+
language:
32+
required: false
33+
type: string
34+
default: "all"
1635

1736
env:
1837
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1938

2039
jobs:
21-
determine-language:
22-
runs-on: ubuntu-latest
23-
outputs:
24-
language: ${{ steps.get-language.outputs.language }}
25-
steps:
26-
- name: Parse language from tag
27-
id: get-language
28-
run: |
29-
tag=${{ inputs.tag }}
30-
language=$(echo $tag | awk -F'-' '{print $NF}')
31-
if [[ ! "$language" =~ ^(java|ruby|python|dotnet|node)$ ]]; then
32-
language="all"
33-
fi
34-
echo "language=$language" > $GITHUB_OUTPUT
35-
36-
java-docs:
37-
runs-on: ubuntu-latest
38-
needs: determine-language
39-
steps:
40-
- name: Checkout the tag
41-
uses: actions/checkout@v4
42-
with:
43-
ref: ${{ inputs.tag }}
44-
- name: Prep git
45-
run: |
46-
git config --local user.email "selenium-ci@users.noreply.github.com"
47-
git config --local user.name "Selenium CI Bot"
48-
- name: Setup Java
49-
uses: actions/setup-java@v4
50-
with:
51-
java-version: 17
52-
distribution: 'temurin'
53-
- name: Update Documentation
54-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'java'
55-
run: ./go java:docs
56-
- name: Create patch for changes
57-
run: |
58-
git format-patch -1 HEAD --stdout > java-docs.patch
59-
- name: Upload patch
60-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'java'
61-
uses: actions/upload-artifact@v4
62-
with:
63-
name: java-docs-patch
64-
path: java-docs.patch
65-
66-
ruby-docs:
40+
build-docs:
6741
runs-on: ubuntu-latest
68-
needs: determine-language
6942
steps:
70-
- name: Checkout the tag
43+
- name: Checkout repository
7144
uses: actions/checkout@v4
7245
with:
73-
ref: ${{ inputs.tag }}
74-
- name: Prep git
46+
ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || inputs.sha }}
47+
- name: Setup git
7548
run: |
7649
git config --local user.email "selenium-ci@users.noreply.github.com"
7750
git config --local user.name "Selenium CI Bot"
51+
- name: Setup curl for Ubuntu
52+
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
7853
- name: Setup Java
7954
uses: actions/setup-java@v4
8055
with:
8156
java-version: 17
8257
distribution: 'temurin'
83-
- name: Setup curl for Ubuntu
84-
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
85-
- name: Update Documentation
86-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'ruby'
87-
run: ./go rb:docs
88-
- name: Create patch for changes
89-
run: |
90-
git format-patch -1 HEAD --stdout > ruby-docs.patch
91-
- name: Upload patch
92-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'ruby'
93-
uses: actions/upload-artifact@v4
94-
with:
95-
name: ruby-docs-patch
96-
path: ruby-docs.patch
97-
98-
python-docs:
99-
needs: determine-language
100-
runs-on: ubuntu-latest
101-
steps:
102-
- name: Checkout the tag
103-
uses: actions/checkout@v4
104-
with:
105-
ref: ${{ inputs.tag }}
106-
- name: Prep git
107-
run: |
108-
git config --local user.email "selenium-ci@users.noreply.github.com"
109-
git config --local user.name "Selenium CI Bot"
11058
- name: Set up Python 3.9
59+
if: ${{ inputs.language == 'all' || inputs.language == 'py' }}
11160
uses: actions/setup-python@v5
11261
with:
11362
python-version: 3.9
11463
- name: Install dependencies
64+
if: ${{ inputs.language == 'all' || inputs.language == 'py' }}
11565
run: |
11666
python -m pip install --upgrade pip
11767
pip install tox
118-
- name: Update Documentation
119-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'python'
120-
run: ./go py:docs
121-
- name: Create patch for changes
122-
run: |
123-
git format-patch -1 HEAD --stdout > python-docs.patch
124-
- name: Upload patch
125-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'python'
126-
uses: actions/upload-artifact@v4
127-
with:
128-
name: python-docs-patch
129-
path: python-docs.patch
130-
131-
dotnet-docs:
132-
needs: determine-language
133-
runs-on: ubuntu-latest
134-
steps:
135-
- name: Checkout the tag
136-
uses: actions/checkout@v4
137-
with:
138-
ref: ${{ inputs.tag }}
139-
- name: Prep git
140-
run: |
141-
git config --local user.email "selenium-ci@users.noreply.github.com"
142-
git config --local user.name "Selenium CI Bot"
143-
- name: Update Documentation
144-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'dotnet'
145-
run: ./go dotnet:docs
146-
- name: Create patch for changes
147-
run: |
148-
git format-patch -1 HEAD --stdout > dotnet-docs.patch
149-
- name: Upload patch
150-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'dotnet'
151-
uses: actions/upload-artifact@v4
152-
with:
153-
name: dotnet-docs-patch
154-
path: dotnet-docs.patch
155-
156-
node-docs:
157-
needs: determine-language
158-
runs-on: ubuntu-latest
159-
steps:
160-
- name: Checkout the tag
161-
uses: actions/checkout@v4
162-
with:
163-
ref: ${{ inputs.tag }}
164-
- name: Prep git
165-
run: |
166-
git config --local user.email "selenium-ci@users.noreply.github.com"
167-
git config --local user.name "Selenium CI Bot"
16868
- name: Install npm dependencies
69+
if: ${{ inputs.language == 'all' || inputs.language == 'node' }}
16970
run: |
17071
npm install
17172
npm install --prefix javascript/node/selenium-webdriver
17273
- name: Update Documentation
173-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'node'
174-
run: ./go node:docs
175-
- name: Create patch for changes
176-
run: |
177-
git format-patch -1 HEAD --stdout > node-docs.patch
178-
- name: Upload patch
179-
if: needs.determine-language.outputs.language == 'all' || needs.determine-language.outputs.language == 'node'
180-
uses: actions/upload-artifact@v4
181-
with:
182-
name: node-docs-patch
183-
path: node-docs.patch
74+
run: ./go ${{ inputs.language }}:docs
18475

185-
merge-patches:
186-
runs-on: ubuntu-latest
187-
needs: [java-docs, ruby-docs, python-docs, dotnet-docs, node-docs]
188-
steps:
189-
- name: Checkout documentation branch
190-
uses: actions/checkout@v4
191-
with:
192-
ref: 'gh-pages'
193-
fetch-depth: 0
194-
fetch-tags: true
195-
- name: Create and checkout new branch
196-
run: |
197-
git config --local user.email "selenium-ci@users.noreply.github.com"
198-
git config --local user.name "Selenium CI Bot"
199-
git checkout -b api-docs-${{ inputs.tag }}
200-
- name: Download all patches
201-
uses: actions/download-artifact@v4
202-
with:
203-
path: patches/
204-
merge-multiple: true
205-
- name: Show downloaded patches
206-
run: ls -lah patches/
207-
- name: Apply patches
208-
run: |
209-
for patch in patches/*.patch; do
210-
git am < "$patch"
211-
done
212-
rm -rf patches/
213-
- name: Push Branch
214-
run: git push origin api-docs-${{ inputs.tag }}
21576
- name: Documentation Pull Request
21677
uses: peter-evans/create-pull-request@v6
21778
with:
21879
token: ${{ secrets.SELENIUM_CI_TOKEN }}
21980
author: Selenium CI Bot <selenium-ci@users.noreply.github.com>
22081
delete-branch: true
221-
branch: api-docs-${{ inputs.tag }}
82+
branch: api-docs-${{ inputs.version }}-${{ inputs.language }}
22283
base: gh-pages
223-
title: Update documentation for ${{ inputs.tag }}
84+
title: Update documentation for Selenium ${{ inputs.version }} (${{ inputs.language }})
22485
body: |
225-
This PR updates the API documentation for all bindings
226-
based on the provided tag name.
86+
This PR updates the API documentation for **${{ inputs.language }}** language bindings to version **${{ inputs.version }}**.
22787
22888
- Auto-generated by [create-pull-request][1]
22989

Rakefile

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,15 @@ namespace :node do
484484

485485
desc 'Generate Node documentation'
486486
task :docs, [:skip_update] do |_task, arguments|
487+
abort('Aborting documentation update: nightly versions should not update docs.') if node_version.include?('nightly')
488+
489+
puts 'Generating Node documentation'
487490
FileUtils.rm_rf('build/docs/api/javascript/')
488491
begin
489-
sh 'npm run generate-docs --prefix javascript/node/selenium-webdriver || true', verbose: true
490-
rescue StandardError
491-
puts 'Ensure that npm is installed on your system'
492-
raise
492+
sh 'npm install --prefix javascript/node/selenium-webdriver', verbose: true
493+
sh 'npm run generate-docs --prefix javascript/node/selenium-webdriver', verbose: true
494+
rescue StandardError => e
495+
puts "Node documentation generation contains errors; continuing... #{e.message}"
493496
end
494497

495498
update_gh_pages unless arguments[:skip_update]
@@ -576,6 +579,11 @@ namespace :py do
576579

577580
desc 'Generate Python documentation'
578581
task :docs, [:skip_update] do |_task, arguments|
582+
if python_version.match?(/^\d+\.\d+\.\d+\.\d+$/)
583+
abort('Aborting documentation update: nightly versions should not update docs.')
584+
end
585+
puts 'Generating Python documentation'
586+
579587
FileUtils.rm_rf('build/docs/api/py/')
580588
FileUtils.rm_rf('build/docs/doctrees/')
581589
begin
@@ -714,6 +722,9 @@ namespace :rb do
714722

715723
desc 'Generate Ruby documentation'
716724
task :docs, [:skip_update] do |_task, arguments|
725+
abort('Aborting documentation update: nightly versions should not update docs.') if ruby_version.include?('nightly')
726+
puts 'Generating Ruby documentation'
727+
717728
FileUtils.rm_rf('build/docs/api/rb/')
718729
Bazel.execute('run', [], '//rb:docs')
719730
FileUtils.mkdir_p('build/docs/api')
@@ -801,6 +812,11 @@ namespace :dotnet do
801812

802813
desc 'Generate .NET documentation'
803814
task :docs, [:skip_update] do |_task, arguments|
815+
if dotnet_version.include?('nightly')
816+
abort('Aborting documentation update: nightly versions should not update docs.')
817+
end
818+
819+
puts 'Generating .NET documentation'
804820
FileUtils.rm_rf('build/docs/api/dotnet/')
805821
begin
806822
# Pinning to 2.78.2 to avoid breaking changes in newer versions
@@ -907,6 +923,11 @@ namespace :java do
907923

908924
desc 'Generate Java documentation'
909925
task :docs, [:skip_update] do |_task, arguments|
926+
if java_version.include?('SNAPSHOT')
927+
abort('Aborting documentation update: snapshot versions should not update docs.')
928+
end
929+
930+
puts 'Generating Java documentation'
910931
Rake::Task['javadocs'].invoke
911932

912933
update_gh_pages unless arguments[:skip_update]
@@ -1175,26 +1196,34 @@ def updated_version(current, desired = nil, nightly = nil)
11751196
end
11761197
end
11771198

1178-
def update_gh_pages
1179-
@git.fetch('origin', {ref: 'gh-pages'})
1180-
@git.checkout('gh-pages', force: true)
1199+
def update_gh_pages(force: true)
1200+
puts 'Switching to gh-pages branch...'
1201+
@git.fetch('https://github.com/seleniumhq/selenium.git', {ref: 'gh-pages'})
1202+
1203+
unless force
1204+
puts 'Stashing current changes before checkout...'
1205+
Git::Stash.new(@git, 'stash wip')
1206+
end
1207+
1208+
@git.checkout('gh-pages', force: force)
1209+
1210+
updated = false
11811211

11821212
%w[java rb py dotnet javascript].each do |language|
1183-
next unless Dir.exist?("build/docs/api/#{language}") && !Dir.empty?("build/docs/api/#{language}")
1213+
source = "build/docs/api/#{language}"
1214+
destination = "docs/api/#{language}"
11841215

1185-
FileUtils.rm_rf("docs/api/#{language}")
1186-
FileUtils.mv("build/docs/api/#{language}", "docs/api/#{language}")
1216+
next unless Dir.exist?(source) && !Dir.empty?(source)
11871217

1188-
commit!("updating #{language} API docs", ["docs/api/#{language}/"])
1218+
puts "Updating documentation for #{language}..."
1219+
FileUtils.rm_rf(destination)
1220+
FileUtils.mv(source, destination)
1221+
1222+
@git.add(destination)
1223+
updated = true
11891224
end
1190-
end
11911225

1192-
def restore_git(origin_reference)
1193-
puts 'Stashing docs changes for gh-pages'
1194-
Git::Stash.new(@git, 'docs changes for gh-pages')
1195-
puts "Checking out originating branch/tag — #{origin_reference}"
1196-
@git.checkout(origin_reference)
1197-
false
1226+
puts(updated ? 'Documentation staged. Ready for commit.' : 'No documentation changes found.')
11981227
end
11991228

12001229
def previous_tag(current_version, language = nil)

0 commit comments

Comments
 (0)