Skip to content

Commit

Permalink
Merge pull request #96 from tj-actions/feat/add-test
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 authored Jan 1, 2023
2 parents 48a8dbc + 7500a6a commit c777a2f
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 116 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/ghcr.yml

This file was deleted.

23 changes: 15 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@ on:
jobs:
test:
name: Test puppeteer
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
node-version: [10, 12, 14, 15, 16]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3.2.0
- name: Test action with node ${{ matrix.node-version }}

- name: Test action
uses: ./
id: puppeteer-test
with:
files: test/test.js

- name: Copy test output
uses: tj-actions/docker-cp@v2
with:
node-version: ${{ matrix.node-version }}
container: ${{ steps.puppeteer-test.outputs.container-id }}
source: ${{ steps.puppeteer-test.outputs.home }}/test.pdf
destination: test.pdf

- name: Display contents of test.pdf
run: cat test.pdf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.idea/
.envrc

node_modules

22 changes: 0 additions & 22 deletions Dockerfile

This file was deleted.

28 changes: 4 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,18 @@

Run Test through [puppeteer](https://github.com/puppeteer/puppeteer), the headless chrome Node API

## Environment Variables

* `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD`
* `PUPPETEER_EXECUTABLE_PATH`

## Usage

```yaml
...
steps:
- uses: actions/checkout@v2
- name: Install dependencies
uses: tj-actions/puppeteer@v3.2
with:
args: yarn install
- name: Run test
uses: tj-actions/puppeteer@v3.2
id: puppeteer
with:
args: yarn test
files: |
test/test.js
```
## Inputs
Expand All @@ -40,21 +33,8 @@ Run Test through [puppeteer](https://github.com/puppeteer/puppeteer), the headle
<!-- AUTO-DOC-INPUT:END -->
### Using docker
```shell script
docker pull ghcr.io/tj-actions/puppeteer:node-12
```

| Supported node versions |
|:------------------------:|
| 10 |
| 12 |
| 14 |
| 15 |
| 16 |
## Outputs
<!---->
* Free software: [MIT license](LICENSE)
Expand Down
37 changes: 21 additions & 16 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ name: puppeteer-chrome
description: Run Test through Puppeteer, the headless chrome Node API
author: tj-actions
inputs:
token:
description: '[GITHUB_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow) or a repo scoped [Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token)'
required: true
default: ${{ github.token }}
node-version:
description: 'Node version'
required: false
default: '14'
args:
description: 'Command to run puppeteer'
files:
description: 'Files to run'
required: true

outputs:
container-id:
description: 'Container ID'
value: ${{ steps.puppeteer-run.outputs.container-id }}
home:
description: 'Home directory'
value: /home/pptruser

runs:
using: 'composite'
steps:
- id: build
run: docker build --build-arg NODE_VERSION=${{ inputs.node-version }} -t puppetter:local-node${{ inputs.node-version }} .
shell: bash
- id: run
run: docker run --rm -v $(pwd):/github/workspace --workdir /github/workspace puppetter:local-node${{ inputs.node-version }} ${{ inputs.args }}
shell: bash
- name: Run puppeteer
id: puppeteer-run
uses: tj-actions/docker-run@v2
with:
image: ghcr.io/puppeteer/puppeteer:19.4.1
name: puppeteer-chrome
options: '-i --init --cap-add=SYS_ADMIN -v ${{ github.workspace }}:${{ github.workspace }}'
args: |
bash -c 'while read -r file; do echo "Running $file..." && mkdir -p $(dirname /home/pptruser/$file) && cp ${{ github.workspace }}/$file /home/pptruser/$file && node $file && echo "Completed executing $file"; done <<< "$(echo "${{ inputs.files }}" | xargs -n1)"'
branding:
icon: camera-off
color: white
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const puppeteer = require('puppeteer');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {
waitUntil: 'networkidle2',
});
await page.pdf({ path: 'test.pdf', format: 'a4' });

await browser.close();
})();

0 comments on commit c777a2f

Please # to comment.