mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-11 05:58:40 +00:00
ci: migrate to GitHub Actions from CircleCI, allow running Browserstack on forked repo via label (#2417)
* Remove CircleCI and codecov * Add GitHub Actions workflow * Add Browserstack credentials * Skip tests if ci skip or skip ci is in commit messages * Update and rename test.yml to ci.yml * Postfix artifacts name with browser * Disable proxy on chrome * Update dockers/screenshotter/screenshotter.js * Add status badge * Set directory option in codecov action * Run Browserstack on forked repo via label * Print Docker logs * Disable GPU on ChromeDriver * Add comments * Add comments
This commit is contained in:
179
.github/workflows/ci.yml
vendored
Normal file
179
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
pull_request_target:
|
||||
branches: [ master ]
|
||||
types: [ labeled ] # 'test screenshots' label on PRs from fork
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
if: |
|
||||
github.event_name != 'pull_request_target' &&
|
||||
!contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
!contains(toJSON(github.event.commits.*.message), '[ci skip]')
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Use Node.js 12.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12'
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
.yarn/cache
|
||||
.pnp.js
|
||||
key: yarn-deps-v1-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
yarn-deps-v1-
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Lint code
|
||||
run: yarn test:lint
|
||||
|
||||
- name: Run Flow
|
||||
run: yarn test:flow
|
||||
if: always()
|
||||
|
||||
- name: Run Jest tests
|
||||
run: yarn test:jest --coverage
|
||||
if: always()
|
||||
|
||||
- uses: codecov/codecov-action@v1
|
||||
with:
|
||||
directory: ./coverage/
|
||||
|
||||
screenshotter_dispatcher:
|
||||
runs-on: ubuntu-latest
|
||||
if: |
|
||||
(github.event_name != 'pull_request_target' ||
|
||||
(github.event.pull_request.head.repo.full_name != 'KaTeX/KaTeX' &&
|
||||
contains(github.event.pull_request.labels.*.name, 'test screenshots'))) &&
|
||||
!contains(toJSON(github.event.commits.*.message), '[skip ci]') &&
|
||||
!contains(toJSON(github.event.commits.*.message), '[ci skip]')
|
||||
outputs:
|
||||
matrix: ${{ steps.set-matrix.outputs.result }}
|
||||
|
||||
steps:
|
||||
- id: set-matrix
|
||||
uses: actions/github-script@v2
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const SELENIUM_BROWSERS = ["chrome", "firefox"];
|
||||
const BROWSERSTACK_BROWSERS = [{
|
||||
browserName: "safari",
|
||||
browser_version: "13.1",
|
||||
os: "OS X",
|
||||
os_version: "Catalina",
|
||||
}];
|
||||
|
||||
const include = [];
|
||||
|
||||
// running selenium doesn't require access to secrets
|
||||
if (context.eventName !== "pull_request_target") {
|
||||
include.push(...SELENIUM_BROWSERS.map(name => ({
|
||||
browser: name,
|
||||
services: {selenium: {
|
||||
image: `selenium/standalone-${name}:3.141.59-20200525`,
|
||||
ports: ["4444:4444"],
|
||||
}},
|
||||
})));
|
||||
}
|
||||
|
||||
// check access to Browserstack crendential secrets
|
||||
if (context.eventName !== "pull_request" ||
|
||||
context.payload.pull_request.head.repo.full_name === "KaTeX/KaTeX") {
|
||||
if (context.eventName === "pull_request_target") {
|
||||
github.issues.removeLabel({
|
||||
issue_number: context.issue.number,
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
name: "test screenshots",
|
||||
});
|
||||
}
|
||||
include.push(...BROWSERSTACK_BROWSERS.map(capabilities => ({
|
||||
browser: capabilities.browserName,
|
||||
services: {},
|
||||
browserstack: capabilities,
|
||||
})));
|
||||
}
|
||||
|
||||
return {browser: include.map(b => b.browser), include};
|
||||
|
||||
screenshotter:
|
||||
runs-on: ubuntu-latest
|
||||
needs: screenshotter_dispatcher
|
||||
strategy:
|
||||
matrix: ${{ fromJson(needs.screenshotter_dispatcher.outputs.matrix) }}
|
||||
fail-fast: false
|
||||
services: ${{ matrix.services }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
if: github.event_name != 'pull_request_target'
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/checkout@v2
|
||||
if: github.event_name == 'pull_request_target'
|
||||
with:
|
||||
# pull_request_target is run in the context of the base repository
|
||||
# of the pull request, so the default ref is master branch and
|
||||
# ref should be manually set to the head of the PR
|
||||
ref: refs/pull/${{ github.event.pull_request.number }}/head
|
||||
submodules: recursive
|
||||
|
||||
- name: Use Node.js 12.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12'
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: |
|
||||
.yarn/cache
|
||||
.pnp.js
|
||||
key: yarn-deps-v1-${{ hashFiles('yarn.lock') }}
|
||||
restore-keys: |
|
||||
yarn-deps-v1-
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Verify screenshots and generate diffs and new screenshots
|
||||
run: yarn node dockers/screenshotter/screenshotter.js -b ${{ matrix.browser }} --verify --diff --new -c ${{ job.services.selenium.id }}
|
||||
if: matrix.services.selenium
|
||||
- name: Verify screenshots and generate diffs and new screenshots
|
||||
run: yarn node dockers/screenshotter/screenshotter.js -b ${{ matrix.browser }} --verify --diff --new --browserstack --selenium-capabilities '${{ toJson(matrix.browserstack) }}'
|
||||
if: matrix.browserstack
|
||||
env:
|
||||
BROWSERSTACK_USER: ${{ secrets.BROWSERSTACK_USER }}
|
||||
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
|
||||
|
||||
- name: Print Docker logs
|
||||
run: docker logs ${{ job.services.selenium.id }}
|
||||
if: always() && matrix.services.selenium
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
if: failure()
|
||||
with:
|
||||
name: new-${{ matrix.browser }}
|
||||
path: test/screenshotter/new
|
||||
- uses: actions/upload-artifact@v2
|
||||
if: failure()
|
||||
with:
|
||||
name: diff-${{ matrix.browser }}
|
||||
path: test/screenshotter/diff
|
Reference in New Issue
Block a user