Skip to content

Commit

Permalink
CI: Add release workflow staging the Python package through GHA to PyPI
Browse files Browse the repository at this point in the history
Along the lines, the patch includes "developer guide" documentation for
both Python and JavaScript.
  • Loading branch information
amotl committed Jun 17, 2024
1 parent b11e326 commit 1a15a7a
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 20 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Release

on: push

jobs:
pypi:
name: Build and publish package to PyPI
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags')
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Generate grammar
run: |
python -m pip install -r requirements.txt
poe generate
- name: Build package
run: |
python -m pip install build twine
python -m build
twine check dist/{*.tar.gz,*.whl}
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
125 changes: 125 additions & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Developer Guide for cratedb-sqlparse

About building locally, or using a different CrateDB version.

> The generated parser is not uploaded to the repository because it is huge.
> To use the package locally or to build a different version use the build script.
## Setup

To start things off, bootstrap the sandbox environment.

### Acquire sources
```shell
git clone [email protected]:crate/cratedb-sqlparse.git
cd cratedb-sqlparse
```

### Install dependencies
```
pip install -r requirements.txt
```

### Generate grammar files
```shell
poe generate
```


## Running Tests for Python

First, navigate to the corresponding subdirectory:

cd cratedb_sqlparse_py

Verify code by running all linters and software tests:

poe check

Run specific tests:

pytest -k enricher
pytest -k lexer

Format code:

poe format


## Running Tests for JavaScript

First, navigate to the corresponding subdirectory:

cd cratedb_sqlparse_js

Set up project:

npm install

Verify code by running all linters and software tests:

npm test

Run specific tests:

???

Format code:

???



## Running a Release

### Python

Overview:
- Versioning happens automatically based on the `versioningit` package.
You just need to tag the repository.
- Package building and publishing happens automatically, being staged
through GHA to PyPI.

On branch `main`:
- Add a section for the new version in the `CHANGES.md` file.
- Commit your changes with a message like `Release vx.y.z`.
- Create a tag, and push to remote.
This will trigger a GitHub action which releases the new version to PyPI.
```shell
git tag v0.0.3
git push --tags
```
- On GitHub, designate a new release, copying in the relevant section
from the CHANGELOG.
https://github.com/crate/cratedb-sqlparse/releases

Optionally, build the package and upload to PyPI manually.
```shell
poe release
```


### JavaScript

Overview:
- Versioning happens manually on behalf of the `package.json` file.
- Package building and publishing to npmjs.com happens manually, using
the `npm` program.

On branch `main`:
- Make sure to run `poe generate` on the root folder first.
- Adjust version number in `package.json`.
- Generate `package-lock.json`.

npm install --package-lock-only

- Commit your changes with a message like `Release vx.y.z`.
- Create a tag, and push to remote.
- Build package.

npm run build

- Publish package.

npm login
npm publish
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,27 @@ These libraries allow you to parse Crate's SQL dialect without sending it to a C
- `Python`: https://github.com/crate/cratedb-sqlparse/tree/main/cratedb_sqlparse_py
- `Javascript`: https://github.com/crate/cratedb-sqlparse/tree/main/cratedb_sqlparse_js

## Example:

## Install

You can install the package in both its Python and JavaScript variants.

- https://pypi.org/project/cratedb-sqlparse/
- https://www.npmjs.com/package/@cratedb/cratedb-sqlparse

### Python

```shell
pip install cratedb-sqlparse
```

### JavaScript
```shell
npm install @cratedb/cratedb-sqlparse
```


## Synopsis

```python
from cratedb_sqlparse import sqlparse
Expand Down Expand Up @@ -49,23 +69,8 @@ exceptions as error listener, dollar-strings and any new one. See past commits t
implemented in Python and Javascript, remember that [CrateDB'S SQLParser](https://github.com/crate/crate/tree/master/libs/sql-parser/src/main/java/io/crate/sql/parser) written in Java is the most
complete and the default reference.

## Building locally & using a different CrateDB version

The generated parser is not uploaded to the repository since it's huge, to use the package locally or
to build a different version use the build script.

### Acquire sources
```shell
git clone [email protected]:crate/cratedb-sqlparse.git
cd cratedb-sqlparse
```

### Install dependencies
```
pip install -r requirements.txt
```
## Development

### Generate grammar files
```shell
poe generate
```
The generated parser is not uploaded to the repository because it is huge.
To use the package locally or to build a different version use the build script.
Further information can be found in the [developer guide](DEVELOP.md).

0 comments on commit 1a15a7a

Please sign in to comment.