Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use github action to generate cdproto #14

Open
wants to merge 3 commits into
base: old
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Gen

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
chromium:
description: 'chromium protocol version'
required: false
default: ''
v8:
description: 'v8 protocol version'
required: false
default: ''

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Checkout pdlgen
uses: actions/checkout@v2
with:
path: pdlgen

- name: Checkout chromedp
uses: actions/checkout@v2
with:
repository: chromedp/chromedp
path: chromedp

# "Checkout cdproto" should be the last checkout action,
# otherwise, its token will be overwritten and the "Commit changes"
# step will fail.
- name: Checkout cdproto
uses: actions/checkout@v2
with:
repository: chromedp/cdproto
token: ${{ secrets.CI_PDLGEN }}
fetch-depth: 0
path: cdproto

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.x

- name: Build cdproto-gen
working-directory: ./pdlgen
run: go build -v

- name: Run cdproto-gen
working-directory: ./pdlgen
run: ./cdproto-gen -chromium=${{ github.event.inputs.chromium }} -v8=${{ github.event.inputs.v8 }} -out=../cdproto

# test chromedp with the updated cdproto
- name: Test chromedp
working-directory: ./chromedp
run: |
go mod edit -replace github.com/chromedp/cdproto=../cdproto
TMPDIR=$RUNNER_TEMP go test -v ./...
./contrib/docker-test.sh

- name: Commit changes
working-directory: ./cdproto
run: |
git config user.name github-actions
git config user.email [email protected]
git checkout -b build-$GITHUB_RUN_NUMBER
git commit -a -m "Updating to $(basename $HOME/.cache/cdproto-gen/pdl/combined/*.pdl .pdl) definitions"
git push origin build-$GITHUB_RUN_NUMBER
if: github.event == 'workflow_dispatch'
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

52 changes: 46 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var (
flagNoDump = flag.Bool("no-dump", false, "toggle not dumping generated protocol file to out directory")

flagGoPkg = flag.String("go-pkg", "github.com/chromedp/cdproto", "go base package name")
flagGoWl = flag.String("go-wl", "LICENSE,README.md,*.pdl,go.mod,go.sum,"+easyjsonGo, "comma-separated list of files to whitelist (ignore)")
flagGoWl = flag.String("go-wl", "LICENSE,README.md,*.pdl,go.mod,go.sum", "comma-separated list of files to whitelist (ignore)")

// flagWorkers = flag.Int("workers", runtime.NumCPU(), "number of workers")
)
Expand Down Expand Up @@ -436,7 +436,46 @@ func goimports(fileBuffers map[string]*bytes.Buffer) error {

// easyjson runs easy json on the list of packages.
func easyjson(pkgs []string) error {
util.Logf("WRITING: easyjson stubs")
// All the easyjson.go files are removed in the CLEANING step,
// so that deprecated files (if any) won't stay in the repository.
// Now generate the stubs first so that the source codes are valid
// from the perspective of syntax.
if err := easyjsonStubs(pkgs); err != nil {
return err
}

util.Logf("RUNNING: easyjson")
// Got error messages like this when running g.Run() concurrently:
// # github.com/chromedp/cdproto/cachestorage
// cachestorage/easyjson.go:8:3: can't find import: "encoding/json"
// # github.com/chromedp/cdproto/cast
// cast/easyjson.go:6:3: can't find import: "github.com/mailru/easyjson"
// It seems that it fails more often on slow machines. The root cause is not clear yet,
// maybe it's relevant to the issue https://github.com/golang/go/issues/26794.
// The workaround for now is to run g.Run() one by one (take longer to finish).
for _, n := range pkgs {
n = filepath.Join(*flagOut, n)
p := parser.Parser{AllStructs: true}
if err := p.Parse(n, true); err != nil {
return err
}
g := bootstrap.Generator{
OutName: filepath.Join(n, easyjsonGo),
PkgPath: p.PkgPath,
PkgName: p.PkgName,
Types: p.StructNames,
NoFormat: true,
}
if err := g.Run(); err != nil {
return err
}
}
return nil
}

// easyjsonStubs runs easy json to generate stubs for the list of packages.
func easyjsonStubs(pkgs []string) error {
eg, _ := errgroup.WithContext(context.Background())
for _, k := range pkgs {
eg.Go(func(n string) func() error {
Expand All @@ -447,11 +486,12 @@ func easyjson(pkgs []string) error {
return err
}
g := bootstrap.Generator{
OutName: filepath.Join(n, easyjsonGo),
PkgPath: p.PkgPath,
PkgName: p.PkgName,
Types: p.StructNames,
NoFormat: true,
OutName: filepath.Join(n, easyjsonGo),
PkgPath: p.PkgPath,
PkgName: p.PkgName,
Types: p.StructNames,
NoFormat: true,
StubsOnly: true,
}
return g.Run()
}
Expand Down