Skip to content

Commit

Permalink
Merge pull request #123 from vintasoftware/feat/release-publish
Browse files Browse the repository at this point in the history
Release workflow
  • Loading branch information
pamella authored Jun 26, 2024
2 parents e67c25f + 590293d commit ecde586
Show file tree
Hide file tree
Showing 12 changed files with 713 additions and 12 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/docs-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- main
- docs-update
tags:
- '**'
- "**"

env:
COLUMNS: 150
Expand Down Expand Up @@ -51,15 +51,20 @@ jobs:
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
- run: poetry run mike deploy -b gh-pages dev --push
if: "github.ref == 'refs/heads/main'"
- name: Deploy on push to main
if: ${{ github.ref == 'refs/heads/main' }}
run: |
poetry run mike deploy -b gh-pages dev --push
- if: "github.ref == 'refs/heads/docs-update' || startsWith(github.ref, 'refs/tags/')"
- name: Check version
if: ${{ github.ref == 'refs/heads/docs-update' || startsWith(github.ref, 'refs/tags/') }}
id: check-version
uses: samuelcolvin/[email protected]
with:
version_file_path: 'django_ai_assistant/__init__.py'
version_file_path: "django_ai_assistant/__init__.py"
skip_env_check: true

- run: poetry run mike deploy -b gh-pages ${{ steps.check-version.outputs.VERSION_MAJOR_MINOR }} latest --update-aliases --push
if: "(github.ref == 'refs/heads/docs-update' || startsWith(github.ref, 'refs/tags/')) && !fromJSON(steps.check-version.outputs.IS_PRERELEASE)"
- name: Deploy on push to docs-update branch or tag push
if: ${{ (github.ref == 'refs/heads/docs-update' || startsWith(github.ref, 'refs/tags/')) && !fromJSON(steps.check-version.outputs.IS_PRERELEASE) }}
run: |
poetry run mike deploy -b gh-pages ${{ steps.check-version.outputs.VERSION_MAJOR_MINOR }} latest --update-aliases --push
75 changes: 75 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Publish packages (PyPI, npm)

on:
release:
types: [published]

jobs:
publish-pypi:
name: Publish django-ai-assistant to PyPI

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with dev --no-interaction
- name: Build package
run: |
poetry build
poetry run twine check dist/*
- name: Publish package distributions to PyPI
run: |
poetry run twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}

publish-npm:
name: Publish django-ai-assistant-client to npm

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"

- name: Install dependencies
working-directory: ./frontend
run: |
npm install
- name: Run ci
working-directory: ./frontend
run: |
npm ci
- name: Build package
working-directory: ./frontend
run: |
npm run build
- name: Publish package distributions to npm
working-directory: ./frontend
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_API_TOKEN }}
66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release draft creation

on:
workflow_dispatch:
inputs:
version:
description: "Version of the release"
required: true
type: number

jobs:
release:
name: Release

runs-on: ubuntu-latest

permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Extract changelog for version
id: changelog
run: |
VERSION=${{ github.event.inputs.version }}
# Extract changelog for version
CHANGELOG=$(awk -v version="$VERSION" 'BEGIN{RS="## "; FS="\n"} $0 ~ version {print "## "$0}' CHANGELOG.md)
# Remove the first line (version title)
CHANGELOG=$(echo "$CHANGELOG" | sed '1d')
# Verify if changelog was found
if [ -z "$CHANGELOG" ]; then
echo "Changelog for version $VERSION not found"
exit 1
fi
# Set output
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Print changelog
run: |
echo "Output is ${{ env.CHANGELOG }}"
- name: Create GitHub Release Draft
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event.inputs.version }}
name: ${{ github.event.inputs.version }}
body: ${{ env.CHANGELOG }}
draft: true
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Summary
run: |
echo "## 🚀 Release Summary" >> $GITHUB_STEP_SUMMARY
echo "Release draft created for version ${{ github.event.inputs.version }}." >> $GITHUB_STEP_SUMMARY
echo "Visit the [Releases section](https://github.com/vintasoftware/django-ai-assistant/releases) to review and publish the release." >> $GITHUB_STEP_SUMMARY
echo "Once the draft is published, another action will automatically be triggered to publish the packages." >> $GITHUB_STEP_SUMMARY
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ repos:
# Only run missing migration check if migration-generating files have changed:
files: (.*/?(settings|migrations|models)/.+|.+models\.py|.+constants\.py|.+choices\.py|.+pyproject\.toml)
pass_filenames: false
- id: check-packages-versions
name: check packages versions
entry: ./scripts/check_packages_versions.sh
language: script
files: ^(pyproject\.toml|frontend/package\.json)$
- id: generate-openapi-schema
name: generate OpenAPI schema
entry: poetry run python manage.py generate_openapi_schema --output frontend/openapi_schema.json
language: system
# Only run OpenAPI schema generation if views.py has changed:
files: views\.py$
# Only run OpenAPI schema generation if views.py or package version have changed:
files: (views\.py$|pyproject\.toml)
pass_filenames: false
- id: generate-frontend-client
name: generate frontend client
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

This changelog references changes made both to the Django backend, `django-ai-assistant`, and the
frontend TypeScript client, `django-ai-assistant-client`.


!!! note
The backend and the frontend are versioned together, that is, they have the same version number.
When you update the backend, you should also update the frontend to the same version.

## 0.0.1 <small>June 25, 2024</small> {id="0.0.1"}

- Initial release
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,17 @@ To run the documentation locally, you need to run:
```bash
poetry run mkdocs serve
```

## Release

!!! info
The backend and the frontend are versioned together, that is, they should have the same version number.

To release and publish a new version, follow these steps:

1. Update the version in `pyproject.toml` and `frontend/package.json`.
2. Update the changelog in `CHANGELOG.md`.
3. Open a PR with the changes.
4. Once the PR is merged, run the [Release GitHub Action](https://github.com/vintasoftware/django-ai-assistant/actions/workflows/release.yml) to create a draft release.
5. Review the draft release, ensure the description has at least the associated changelog entry, and publish it.
6. Once the review is publish, the [Publish GitHub Action](https://github.com/vintasoftware/django-ai-assistant/actions/workflows/publish.yml) will automatically run to publish the new version to [PyPI](https://pypi.org/project/django-ai-assistant) and [npm](https://www.npmjs.com/package/django-ai-assistant-client). Check the logs to ensure the publication was successful.
1 change: 1 addition & 0 deletions docs/changelog.md
13 changes: 12 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,26 @@
"node": ">=20 <21"
},
"version": "0.0.1",
"description": "",
"description": "TypeScript client to facilitate the integration with the Django AI Assistant backend.",
"homepage": "https://github.com/vintasoftware/django-ai-assistant",
"documentation": "https://vintasoftware.github.io/django-ai-assistant",
"bugs": "https://github.com/vintasoftware/django-ai-assistant/issues",
"repository": {
"type": "git",
"url": "git+https://github.com/vintasoftware/django-ai-assistant.git"
},
"license": "MIT",
"author": "Vinta Software",
"keywords": [
"ai-agent",
"ai-assistant",
"ai",
"chatgpt",
"django",
"gpt",
"langchain",
"openai"
],
"scripts": {
"build": "vite build",
"build:watch": "vite build --watch",
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ nav:
- helpers.use_cases: reference/use-cases-ref.md
- helpers.assistants: reference/assistants-ref.md
- models: reference/models-ref.md
- Changelog: changelog.md
- Contributing: contributing.md
- Support: support.md

Expand Down
Loading

0 comments on commit ecde586

Please sign in to comment.