Skip to content

Commit

Permalink
Github CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdbrock committed Dec 2, 2024
1 parent ef7f471 commit e679d54
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 26 deletions.
62 changes: 42 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,70 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
# https://github.com/marketplace/actions/cache-apt-packages
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: protobuf-compiler

# https://github.com/purescript-contrib/setup-purescript/
- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purs-tidy: "latest"
spago: "unstable"

# https://github.com/marketplace/actions/cache
- name: Cache PureScript dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}-2
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}-2
path: |
.spago
output
./plugin/.spago
./conformance/.spago
- name: Install dependencies
run: spago install
run: |
protoc --version
echo -n "node "
node --version
echo -n "purs "
purs --version
echo -n "spago "
spago --version
echo ""
spago install
- name: Install plugin dependencies
run: spago -x spago-plugin.dhall install
- name: Build Plugin
run: |
cd plugin
spago build
- name: Install test dependencies
run: spago -x spago-test.dhall install
- name: Test Plugin
# Need --experimental_allow_proto3_optional until the CI protoc is upgraded
run: |
protoc --experimental_allow_proto3_optional --plugin=bin/protoc-gen-purescript --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
cd plugin
spago test
- name: Build plugin
run: spago -x spago-plugin.dhall build --no-install --purs-args '--censor-lib --strict --censor-codes='UserDefinedWarning''
# - name: Install test dependencies
# run: spago -x spago-test.dhall install

- run: mkdir -p ./test/generated
# - name: Build plugin
# run: spago -x spago-plugin.dhall build --no-install --purs-args '--censor-lib --strict --censor-codes='UserDefinedWarning''

- name: Generate test from .proto
run: PATH=./bin:$PATH protoc --experimental_allow_proto3_optional --purescript_out=./test/generated test/*.proto
# - run: mkdir -p ./test/generated

- name: Build test
run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --censor-codes='UserDefinedWarning''
# - name: Generate test from .proto
# run: PATH=./bin:$PATH protoc --experimental_allow_proto3_optional --purescript_out=./test/generated test/*.proto

- name: Run tests
run: spago -x spago-test.dhall test --no-install
# - name: Build test
# run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --censor-codes='UserDefinedWarning''

# - name: Run tests
# run: spago -x spago-test.dhall test --no-install

# We're not running the conformance test because the conformance
# test runner is a pretty heavy build.
# test runner is a pretty heavy build.

21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,28 @@ To compile PureScript .purs files from .proto files, run for example:

We can test out code generation immediately by
generating `.purs` files for any of Google’s built-in “well-known types” in the
[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command `protoc --purescript_out=. google/protobuf/any.proto`
or `protoc --purescript_out=. google/protobuf/timestamp.proto`.
[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command
```console
protoc --purescript_out=. google/protobuf/any.proto
```
or
```console
protoc --purescript_out=. google/protobuf/timestamp.proto
```

To see
[all of the `.proto` definitions](https://github.com/protocolbuffers/protobuf/tree/main/src/google/protobuf)
included with the Nix PureScript Protobuf installation including
the “well-known types,”
`ls $(nix path-info .#protobuf)/src/google/protobuf/*.proto`

If you don't want to use Nix, then install the PureScript toolchain and `protoc`,
If you don't want to use Nix,
1. install the PureScript toolchain and `protoc`.
2. Build the [PureScript plugin for `protoc`](plugin/).
3. Run `protoc` with the path to the PureScript plugin executable, like for example
```console
protoc --plugin=bin/protoc-gen-purescript --purescript_out=. google/protobuf/timestamp.proto
```
and add the executable script
[`bin/protoc-gen-purescript`](bin/protoc-gen-purescript)
to your `PATH`.
Expand Down Expand Up @@ -318,10 +330,11 @@ For that reason, we can only use top-level
### PureScript Imports

The generated PureScript code will usually have module imports which cause
the `purs` compiler to emit redundant import warnings. Sorry. If this causes
the `purs` compiler to emit `ImplicitQualifiedImport` warnings. Sorry. If this causes
trouble then the imports can be fixed automatically in a precompiling pass
with the command-line tool
[__suggest__](https://github.com/nwolverson/purescript-suggest).
Or you can [censor the warnings](https://discourse.purescript.org/t/suppressing-warnings-in-code/2485).

## Nix derivation

Expand Down
2 changes: 1 addition & 1 deletion bin/conformance-purescript
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
node --input-type=module --abort-on-uncaught-exception --trace-sigint --trace-uncaught -e "import {main} from 'conformance/output/Conformance.Main/index.js'; main();"
node --input-type=module --abort-on-uncaught-exception --trace-sigint --trace-uncaught -e "import {main} from './conformance/output/Main/index.js'; main();"
2 changes: 1 addition & 1 deletion bin/protoc-gen-purescript
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
node --input-type=module -e "import {main} from 'plugin/output/ProtocPlugin.Main/index.js'; main();"
node --input-type=module -e "import {main} from './plugin/output/ProtocPlugin.Main/index.js'; main();"
8 changes: 8 additions & 0 deletions conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ From the top directory of this repo,
```console
nix run .#conformance
```
or
```console
cd conformance
spago build
```
```console
conformance_test_runner --enforce_recommended bin/conformance-purescript
```

## About the conformance test runner

Expand Down
9 changes: 9 additions & 0 deletions plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@

# PureScript plugin for Protoc

Build:

```
spago build
```

The funny thing about writing a `protoc` compiler plugin codec is that it
bootstraps itself. We just have to write enough of the compiler plugin codec
that it can handle the `plugin.proto` and `descriptor.proto` files, and
Expand Down
5 changes: 5 additions & 0 deletions plugin/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ of the repo, then:
```console
protoc --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
```
or, for the plugin from src tree, not the Nix store,
``console
protoc --plugin=bin/protoc-gen-purescript --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
```
then
```console
cd plugin
```
Expand Down

0 comments on commit e679d54

Please sign in to comment.