Skip to content
This repository has been archived by the owner on Jun 16, 2020. It is now read-only.

Commit

Permalink
setup chromedriver
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Oct 3, 2019
1 parent b7d9110 commit dc6cf39
Show file tree
Hide file tree
Showing 16 changed files with 1,342 additions and 950 deletions.
20 changes: 11 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: "Test typescript-action"
on:
pull_request:
push:
branches:
- master
- 'releases/*'
name: "Test chromedriver"
on: [ push, pull_request ]

jobs:
test:
Expand All @@ -16,5 +11,12 @@ jobs:
- run: npm run build
- run: npm test
- uses: ./
with:
milliseconds: 1000
with:
chromedriver-version: '77.0.3865.40'
- name: setup
run: |
sudo pip3 install selenium
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # disable headless mode
python3 $GITHUB_WORKSPACE/__tests__/chromedriver.py
125 changes: 19 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,26 @@
# Create a JavaScript Action using TypeScript
# setup-chromedriver

Use this template to bootstrap the creation of a JavaScript action.:rocket:
<p align="left">
<a href="https://github.com/nanasess/setup-chromedriver"><img alt="GitHub Actions status" src="https://github.com/nanasess/setup-chromedriver/workflows/Main%20workflow/badge.svg"></a>
<a href="https://github.com/nanasess/setup-chromedriver/blob/master/LICENSE"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg"></a>
</p>

This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.
This action sets up a [ChromeDriver](https://chromedriver.chromium.org/) for use in actions

If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
# Usage

## Create an action from this template
See [action.yml](action.yml)

Click the `Use this Template` and provide the new repo details for your action
``` yaml
steps:
- uses: actions/checkout@master
- uses: nanasess/setup-chromedriver@master
with:
chromedriver-version: '77.0.3865.40'
- run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
```
## Code in Master
Install the dependencies
```bash
$ npm install
```

Build the typescript
```bash
$ npm run build
```

Run the tests :heavy_check_mark:
```bash
$ npm test

PASS ./index.test.js
✓ throws invalid number (3ms)
wait 500 ms (504ms)
test runs (95ms)

...
```

## Change action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)

## Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

```javascript
import * as core from '@actions/core';
...

async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}

run()
```

See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.

## Publish to a distribution branch

Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case).

Comment out node_modules in .gitignore and create a releases/v1 branch
```bash
# comment out in distribution branches
# node_modules/
```

```bash
$ git checkout -b releases/v1
$ git commit -a -m "prod dependencies"
```

```bash
$ npm prune --production
$ git add node_modules
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```

Your action is now published! :rocket:

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)

## Validate

You can now validate the action by referencing the releases/v1 branch

```yaml
uses: actions/typescript-action@releases/v1
with:
milliseconds: 1000
```
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
## Usage:
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and tested action
```yaml
uses: actions/typescript-action@v1
with:
milliseconds: 1000
```
13 changes: 13 additions & 0 deletions __tests__/chromedriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import time
from selenium import webdriver

driver = webdriver.Chrome() # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
print(driver.title)
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
print(driver.title)
driver.quit()
23 changes: 0 additions & 23 deletions __tests__/main.test.ts

This file was deleted.

5 changes: 5 additions & 0 deletions __tests__/run.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('example tests', () => {
it('testing', () => {
expect(true).toBe(true);
});
});
13 changes: 5 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
inputs:
myInput: # change this
description: 'input description here'
default: 'default value if applicable'
name: 'setup-chromedriver'
description: 'Setup chromedriver'
author: 'nanasess'
runs:
using: 'node12'
main: 'lib/main.js'
main: 'lib/setup-chromedriver.js'

22 changes: 22 additions & 0 deletions docs/contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Contributors

### Checkin

- Do checkin source (src)
- Do checkin build output (lib)
- Do checkin runtime node_modules
- Do not checkin devDependency node_modules (husky can help see below)

### devDependencies

In order to handle correctly checking in node_modules without devDependencies, we run [Husky](https://github.com/typicode/husky) before each commit.
This step ensures that formatting and checkin rules are followed and that devDependencies are excluded. To make sure Husky runs correctly, please use the following workflow:

```
npm install # installs all devDependencies including Husky
git add abc.ext # Add the files you've changed. This should include files in src, lib, and node_modules (see above)
git commit -m "Informative commit message" # Commit. This will run Husky
```

During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) as well as pruning out devDependencies using `npm prune --production`.
It will also make sure these changes are appropriately included in your commit (no further work is needed)
31 changes: 23 additions & 8 deletions lib/main.js → lib/setup-chromedriver.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Expand All @@ -16,16 +17,30 @@ var __importStar = (this && this.__importStar) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const wait_1 = require("./wait");
const exec = __importStar(require("@actions/exec"));
const path = __importStar(require("path"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const ms = core.getInput('milliseconds');
console.log(`Waiting ${ms} milliseconds ...`);
core.debug((new Date()).toTimeString());
wait_1.wait(parseInt(ms));
core.debug((new Date()).toTimeString());
core.setOutput('time', new Date().toTimeString());
console.log(`##setup chromedriver`);
const version = core.getInput("chromedriver-version", { required: true });
const plat = process.platform;
let arch = "linux";
switch (plat) {
case "win32":
arch = plat;
break;
case "darwin":
arch = "mac64";
break;
default:
case "linux":
arch = "linux64";
}
yield exec.exec(path.join(__dirname, "setup-chromedriver.sh"), [
version,
arch
]);
}
catch (error) {
core.setFailed(error.message);
Expand Down
12 changes: 12 additions & 0 deletions lib/setup-chromedriver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -eo pipefail

version=$1
arch=$2

sudo apt-fast install -y xvfb screen google-chrome-stable

wget -c -nc --retry-connrefused --tries=0 https://chromedriver.storage.googleapis.com/${version}/chromedriver_${arch}.zip
unzip -o -q chromedriver_${arch}.zip
sudo mv chromedriver /usr/local/bin/chromedriver
11 changes: 0 additions & 11 deletions lib/wait.js

This file was deleted.

Loading

0 comments on commit dc6cf39

Please sign in to comment.