Skip to content

Commit 03f11b2

Browse files
committed
Migrating Java CI build to GitHub Actions
1 parent 8f8bbee commit 03f11b2

File tree

10 files changed

+284
-37
lines changed

10 files changed

+284
-37
lines changed

.bazelrc

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ build --test_output=errors
2020
build --noexperimental_sandbox_default_allow_network
2121

2222
# pass environment variables to the test environment
23+
build --test_env=CI
24+
build --test_env=GITHUB_ACTIONS
2325
build --test_env=TRAVIS
2426
build --test_env=DISPLAY
2527
build --test_env=MOZ_HEADLESS

.github/.bazelrc.local

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Set up caching on local disk so incremental builds are faster
2+
# See https://bazel.build/designs/2016/09/30/repository-cache.html
3+
build --repository_cache=~/.cache/bazel-repo
4+
test --repository_cache=~/.cache/bazel-repo
5+
# See https://docs.bazel.build/versions/master/remote-caching.html#disk-cache
6+
build --disk_cache=~/.cache/bazel-disk
7+
test --disk_cache=~/.cache/bazel-disk"
8+
9+
# Make output easier to read
10+
build --curses=no
11+
build --color=no
12+
build --show_timestamps

.github/actions/bazel-test/action.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Run bazel query and pass found targets to bazel test'
2+
inputs:
3+
query: # id of input
4+
required: true
5+
runs:
6+
using: "composite"
7+
steps:
8+
- run: |
9+
cp .github/.bazelrc.local .
10+
bazel query "${{ inputs.query }}" | xargs bazel test
11+
shell: bash

.github/actions/bazel/action.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Run bazel'
2+
inputs:
3+
command: # id of input
4+
required: true
5+
runs:
6+
using: "composite"
7+
steps:
8+
- run: |
9+
cp .github/.bazelrc.local .
10+
bazel ${{ inputs.command }}
11+
shell: bash
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'Setup bazelisk'
2+
inputs:
3+
version: # id of input
4+
required: false
5+
default: 'v1.7.4'
6+
runs:
7+
using: "composite"
8+
steps:
9+
- run: |
10+
curl -L -o bazelisk "https://github.com/bazelbuild/bazelisk/releases/download/v1.7.4/bazelisk-linux-amd64"
11+
chmod +x bazelisk && sudo mv bazelisk /usr/local/bin/bazel
12+
shell: bash
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Setup Chrome and chromedriver'
2+
runs:
3+
using: "composite"
4+
steps:
5+
- run: |
6+
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
7+
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee -a /etc/apt/sources.list.d/google-chrome.list
8+
sudo apt-get update -qqy
9+
sudo apt-get -qqy install google-chrome-stable
10+
CHROME_VERSION=$(google-chrome-stable --version)
11+
CHROME_FULL_VERSION=${CHROME_VERSION%%.*}
12+
CHROME_MAJOR_VERSION=${CHROME_FULL_VERSION//[!0-9]}
13+
sudo rm /etc/apt/sources.list.d/google-chrome.list
14+
export CHROMEDRIVER_VERSION=`curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION%%.*}`
15+
curl -L -O "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
16+
unzip chromedriver_linux64.zip && chmod +x chromedriver && sudo mv chromedriver /usr/local/bin
17+
export CHROMEDRIVER_VERSION=`curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION%%.*}`
18+
curl -L -O "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
19+
unzip chromedriver_linux64.zip && chmod +x chromedriver && sudo mv chromedriver /usr/local/bin
20+
chromedriver -version
21+
shell: bash
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: 'Setup Firefox and geckodriver'
2+
runs:
3+
using: "composite"
4+
steps:
5+
- run: |
6+
GECKODRIVER_URL=`curl -Ls -o /dev/null -w %{url_effective} https://github.com/mozilla/geckodriver/releases/latest`
7+
GECKODRIVER_VERSION=`echo $GECKODRIVER_URL | sed 's#.*/##'`
8+
export GECKODRIVER_DOWNLOAD="https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz"
9+
curl -L -o geckodriver.tar.gz $GECKODRIVER_DOWNLOAD
10+
gunzip -c geckodriver.tar.gz | tar xopf -
11+
chmod +x geckodriver && sudo mv geckodriver /usr/local/bin
12+
geckodriver --version
13+
shell: bash

.github/workflows/java.yml

+164-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,169 @@ env:
1111
jobs:
1212
build:
1313
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout source tree
16+
uses: actions/checkout@v1
17+
- name: Cache Bazel artifacts
18+
uses: actions/cache@v2
19+
with:
20+
path: |
21+
~/.cache/bazel-disk
22+
~/.cache/bazel-repo
23+
key: ${{ runner.os }}-bazel-build-${{ hashFiles('**/BUILD.bazel') }}
24+
restore-keys: |
25+
${{ runner.os }}-bazel-build-
26+
- name: Setup bazelisk
27+
uses: ./.github/actions/setup-bazelisk
28+
- name: Setup Java
29+
uses: actions/setup-java@v1
30+
with:
31+
java-version: '11'
32+
- name: Build grid
33+
uses: ./.github/actions/bazel
34+
with:
35+
command: build grid
36+
37+
small_tests:
38+
needs: build
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout source tree
42+
uses: actions/checkout@v1
43+
- name: Cache Bazel artifacts
44+
uses: actions/cache@v2
45+
with:
46+
path: |
47+
~/.cache/bazel-disk
48+
~/.cache/bazel-repo
49+
key: ${{ runner.os }}-bazel-small-tests-${{ hashFiles('**/BUILD.bazel') }}
50+
restore-keys: |
51+
${{ runner.os }}-bazel-small-tests-
52+
${{ runner.os }}-bazel-build-
53+
- name: Setup bazelisk
54+
uses: ./.github/actions/setup-bazelisk
55+
- name: Setup Java
56+
uses: actions/setup-java@v1
57+
with:
58+
java-version: '11'
59+
- name: Run small tests
60+
uses: ./.github/actions/bazel-test
61+
with:
62+
query: attr(size, small, tests(//java/...)) except attr(tags, lint, tests(//java/...))
1463

64+
lint:
65+
needs: build
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Checkout source tree
69+
uses: actions/checkout@v1
70+
- name: Cache Bazel artifacts
71+
uses: actions/cache@v2
72+
with:
73+
path: |
74+
~/.cache/bazel-disk
75+
~/.cache/bazel-repo
76+
key: ${{ runner.os }}-bazel-lint-${{ hashFiles('**/BUILD.bazel') }}
77+
restore-keys: |
78+
${{ runner.os }}-bazel-lint-
79+
${{ runner.os }}-bazel-build-
80+
- name: Setup bazelisk
81+
uses: ./.github/actions/setup-bazelisk
82+
- name: Setup Java
83+
uses: actions/setup-java@v1
84+
with:
85+
java-version: '11'
86+
- name: Run linter
87+
uses: ./.github/actions/bazel-test
88+
with:
89+
query: attr(tags, lint, tests(//java/...))
90+
91+
chrome_tests:
92+
needs: build
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout source tree
96+
uses: actions/checkout@v1
97+
- name: Cache Bazel artifacts
98+
uses: actions/cache@v2
99+
with:
100+
path: |
101+
~/.cache/bazel-disk
102+
~/.cache/bazel-repo
103+
key: ${{ runner.os }}-bazel-chrome-tests-${{ hashFiles('**/BUILD.bazel') }}
104+
restore-keys: |
105+
${{ runner.os }}-bazel-chrome-tests-
106+
${{ runner.os }}-bazel-build-
107+
- name: Setup bazelisk
108+
uses: ./.github/actions/setup-bazelisk
109+
- name: Setup Java
110+
uses: actions/setup-java@v1
111+
with:
112+
java-version: '11'
113+
- name: Setup Chrome and chromedriver
114+
uses: ./.github/actions/setup-chrome
115+
- name: Run browser tests in Chrome
116+
uses: ./.github/actions/bazel-test
117+
with:
118+
query: attr(tags, chrome, tests(//java/client/...)) except attr(tags, remote, tests(//java/client/...))
119+
120+
firefox_tests:
121+
needs: build
122+
runs-on: ubuntu-latest
123+
steps:
124+
- name: Checkout source tree
125+
uses: actions/checkout@v1
126+
- name: Cache Bazel artifacts
127+
uses: actions/cache@v2
128+
with:
129+
path: |
130+
~/.cache/bazel-disk
131+
~/.cache/bazel-repo
132+
key: ${{ runner.os }}-bazel-firefox-tests-${{ hashFiles('**/BUILD.bazel') }}
133+
restore-keys: |
134+
${{ runner.os }}-bazel-firefox-tests-
135+
${{ runner.os }}-bazel-build-
136+
- name: Setup bazelisk
137+
uses: ./.github/actions/setup-bazelisk
138+
- name: Setup Java
139+
uses: actions/setup-java@v1
140+
with:
141+
java-version: '11'
142+
- name: Setup Firefox and geckodriver
143+
uses: ./.github/actions/setup-firefox
144+
- name: Run browser tests in Firefox
145+
uses: ./.github/actions/bazel-test
146+
with:
147+
query: attr(tags, firefox, tests(//java/client/...)) except attr(tags, remote, tests(//java/client/...))
148+
149+
150+
server_tests:
151+
needs: build
152+
runs-on: ubuntu-latest
15153
steps:
16-
- name: Checkout source tree
17-
uses: actions/checkout@v1
18-
- name: Setup bazelisk for Bazel builds
19-
uses: holvonix-open/[email protected]
20-
- name: Run Bazel build
21-
run: |
22-
bazel build //java/...
154+
- name: Checkout source tree
155+
uses: actions/checkout@v1
156+
- name: Cache Bazel artifacts
157+
uses: actions/cache@v2
158+
with:
159+
path: |
160+
~/.cache/bazel-disk
161+
~/.cache/bazel-repo
162+
key: ${{ runner.os }}-bazel-firefox-tests-${{ hashFiles('**/BUILD.bazel') }}
163+
restore-keys: |
164+
${{ runner.os }}-bazel-firefox-tests-
165+
${{ runner.os }}-bazel-build-
166+
- name: Setup bazelisk
167+
uses: ./.github/actions/setup-bazelisk
168+
- name: Setup Java
169+
uses: actions/setup-java@v1
170+
with:
171+
java-version: '11'
172+
- name: Setup Chrome and chromedriver
173+
uses: ./.github/actions/setup-chrome
174+
- name: Setup Firefox and geckodriver
175+
uses: ./.github/actions/setup-firefox
176+
- name: Run server tests
177+
uses: ./.github/actions/bazel-test
178+
with:
179+
query: tests(//java/server/...) except attr(tags, 'lint|ie|edge|edgehtml|safari', tests(//java/server/...))

java/client/test/org/openqa/selenium/testing/drivers/TestChromeDriver.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ private static ChromeDriverService getService() {
4949
try {
5050
Path logFile = Files.createTempFile("chromedriver", ".log");
5151
ChromeDriverService service = new ChromeDriverService.Builder()
52-
.withLogLevel(ChromeDriverLogLevel.ALL)
53-
.withLogFile(logFile.toFile())
54-
.build();
52+
.withLogLevel(ChromeDriverLogLevel.ALL)
53+
.withLogFile(logFile.toFile())
54+
.build();
5555
LOG.info("chromedriver will log to " + logFile);
5656
LOG.info("chromedriver will use log level " + ChromeDriverLogLevel.ALL.toString().toUpperCase());
5757
service.start();
@@ -65,7 +65,10 @@ private static ChromeDriverService getService() {
6565

6666
private static ChromeOptions chromeWithCustomCapabilities(Capabilities originalCapabilities) {
6767
ChromeOptions options = new ChromeOptions();
68-
options.addArguments("disable-extensions", "disable-infobars", "disable-breakpad");
68+
if (Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS"))) {
69+
options.setHeadless(true);
70+
}
71+
options.addArguments("disable-extensions", "disable-infobars", "disable-breakpad", "disable-dev-shm-usage", "no-sandbox");
6972
Map<String, Object> prefs = new HashMap<>();
7073
prefs.put("exit_type", "None");
7174
prefs.put("exited_cleanly", true);

java/client/test/org/openqa/selenium/testing/drivers/WebDriverBuilder.java

+31-26
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141
import java.util.Objects;
4242
import java.util.Optional;
4343
import java.util.Set;
44+
import java.util.function.Function;
4445
import java.util.function.Supplier;
4546
import java.util.logging.Level;
4647
import java.util.stream.Stream;
4748

4849
public class WebDriverBuilder implements Supplier<WebDriver> {
4950

50-
private static LinkedList<Runnable> shutdownActions = new LinkedList<>();
51-
private static Set<WebDriver> managedDrivers = new HashSet<>();
51+
private static final LinkedList<Runnable> shutdownActions = new LinkedList<>();
52+
private static final Set<WebDriver> managedDrivers = new HashSet<>();
5253
static {
5354
shutdownActions.add(() -> managedDrivers.forEach(WebDriver::quit));
5455
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdownActions.forEach(Runnable::run)));
@@ -58,16 +59,19 @@ static void addShutdownAction(Runnable action) {
5859
shutdownActions.add(action);
5960
}
6061

61-
private static Map<Browser, Supplier<Capabilities>> capabilitySuppliers =
62-
new ImmutableMap.Builder<Browser, Supplier<Capabilities>>()
63-
.put(Browser.CHROME, ChromeOptions::new)
64-
.put(Browser.FIREFOX, () -> new FirefoxOptions()
65-
.setLegacy(true)
66-
.setHeadless(Boolean.parseBoolean(System.getProperty("webdriver.firefox.headless", "false"))))
67-
.put(Browser.MARIONETTE, () -> new FirefoxOptions()
68-
.setHeadless(Boolean.parseBoolean(System.getProperty("webdriver.firefox.headless", "false"))))
69-
.put(Browser.IE, () -> {
70-
InternetExplorerOptions options = new InternetExplorerOptions();
62+
private static final Map<Browser, Function<Capabilities, Capabilities>> capabilitySuppliers =
63+
new ImmutableMap.Builder<Browser, Function<Capabilities, Capabilities>>()
64+
.put(Browser.CHROME, original -> new ChromeOptions().merge(original))
65+
.put(Browser.FIREFOX, original -> new FirefoxOptions(original)
66+
.setLegacy(true)
67+
.setHeadless(Boolean.parseBoolean(System.getProperty("webdriver.firefox.headless", "false"))))
68+
.put(Browser.MARIONETTE, original -> new FirefoxOptions(original)
69+
.setHeadless(
70+
Boolean.parseBoolean(System.getProperty("webdriver.firefox.headless", "false")) ||
71+
Boolean.parseBoolean(System.getenv("GITHUB_ACTIONS")))
72+
)
73+
.put(Browser.IE, original -> {
74+
InternetExplorerOptions options = new InternetExplorerOptions(original);
7175
if (Boolean.getBoolean("selenium.ie.disable_native_events")) {
7276
options.disableNativeEvents();
7377
}
@@ -76,12 +80,12 @@ static void addShutdownAction(Runnable action) {
7680
}
7781
return options;
7882
})
79-
.put(Browser.CHROMIUMEDGE, EdgeOptions::new)
80-
.put(Browser.EDGE, EdgeHtmlOptions::new)
81-
.put(Browser.HTMLUNIT, () -> new DesiredCapabilities(BrowserType.HTMLUNIT, "", Platform.ANY))
82-
.put(Browser.OPERABLINK, OperaOptions::new)
83-
.put(Browser.SAFARI, () -> {
84-
SafariOptions options = new SafariOptions();
83+
.put(Browser.CHROMIUMEDGE, original -> new EdgeOptions().merge(original))
84+
.put(Browser.EDGE, original -> new EdgeHtmlOptions().merge(original))
85+
.put(Browser.HTMLUNIT, original -> new DesiredCapabilities(BrowserType.HTMLUNIT, "", Platform.ANY).merge(original))
86+
.put(Browser.OPERABLINK, original -> new OperaOptions().merge(original))
87+
.put(Browser.SAFARI, original -> {
88+
SafariOptions options = new SafariOptions(original);
8589
if (Boolean.getBoolean("selenium.safari.tp")) {
8690
options.setUseTechnologyPreview(true);
8791
}
@@ -90,7 +94,7 @@ static void addShutdownAction(Runnable action) {
9094
.build();
9195

9296
public static Capabilities getStandardCapabilitiesFor(Browser toBuild) {
93-
return capabilitySuppliers.getOrDefault(toBuild, ImmutableCapabilities::new).get();
97+
return capabilitySuppliers.getOrDefault(toBuild, ImmutableCapabilities::new).apply(new ImmutableCapabilities());
9498
}
9599

96100
private final Browser toBuild;
@@ -109,15 +113,16 @@ public WebDriver get() {
109113
}
110114

111115
public WebDriver get(Capabilities desiredCapabilities) {
112-
Capabilities desiredCaps = getStandardCapabilitiesFor(toBuild).merge(desiredCapabilities);
116+
Capabilities desiredCaps = capabilitySuppliers
117+
.getOrDefault(toBuild, ImmutableCapabilities::new)
118+
.apply(desiredCapabilities);
113119

114120
WebDriver driver =
115-
Stream.of(
116-
new ExternalDriverSupplier(desiredCaps),
117-
new GridSupplier(desiredCaps),
118-
new RemoteSupplier(desiredCaps),
119-
new TestInternetExplorerSupplier(desiredCaps),
120-
new DefaultDriverSupplier(desiredCaps))
121+
Stream.of(new ExternalDriverSupplier(desiredCaps),
122+
new GridSupplier(desiredCaps),
123+
new RemoteSupplier(desiredCaps),
124+
new TestInternetExplorerSupplier(desiredCaps),
125+
new DefaultDriverSupplier(desiredCaps))
121126
.map(Supplier::get)
122127
.filter(Objects::nonNull)
123128
.findFirst()

0 commit comments

Comments
 (0)