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

CI: Add release workflow for staging the Python package through GHA to PyPI #41

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
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
cd cratedb_sqlparse_py
python -m build
twine check dist/{*.tar.gz,*.whl}

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: cratedb_sqlparse_py/dist/
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:

???
Comment on lines +63 to +69
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know relevant incantations for the JavaScript domain. Are there any?

Copy link
Collaborator

@surister surister Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm test and npm build

But I can add them later in the upcoming javascript patch

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I didn't see the "?", no currently there is no format, maybe we should add it int he future with prettier, for running a single test is npm test -- other.test.js

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Yeah, please fill in the gaps, or delete sections where applicable.




## 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).