Skip to content

Commit

Permalink
new release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dsp-ant committed Jan 14, 2025
1 parent 8e94436 commit 8bbdb8c
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 1 deletion.
82 changes: 81 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
outputs:
hash: ${{ steps.last-release.outputs.hash }}
version: ${{ steps.create-version.outputs.version}}
npm_packages: ${{ steps.create-npm-packages.outputs.npm_packages}}
pypi_packages: ${{ steps.create-pypi-packages.outputs.pypi_packages}}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -43,6 +45,20 @@ jobs:
name: release-notes
path: RELEASE_NOTES.md

- name: Create python matrix
id: create-pypi-packages
run: |
PYPI=$(uv run --script scripts/release.py generate-matrix --pypi)
echo "pypi_packages $PYPI"
echo "pypi_packages=$PYPI" >> $GITHUB_OUTPUT
- name: Create npm matrix
id: create-npm-packages
run: |
NPM=$(uv run --script scripts/release.py generate-matrix --npm)
echo "npm_packages $NPM"
echo "npm_packages=$NPM" >> $GITHUB_OUTPUT
update-packages:
needs: [create-metadata]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -97,9 +113,73 @@ jobs:

- name: Create release
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN}}
run: |
VERSION="${{ needs.create-metadata.outputs.version }}"
gh release create "$VERSION" \
--title "Release $VERSION" \
--notes-file RELEASE_NOTES.md
publish-pypi:
needs: [create-release, create-metadata]
strategy:
matrix:
package: ${{ fromJson(needs.create-metadata.outputs.pypi_packages) }}
name: Build ${{ matrix.package }}
environment: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "src/${{ matrix.package }}/.python-version"

- name: Install dependencies
working-directory: src/${{ matrix.package }}
run: uv sync --frozen --all-extras --dev

- name: Run pyright
working-directory: src/${{ matrix.package }}
run: uv run --frozen pyright

- name: Build package
working-directory: src/${{ matrix.package }}
run: uv build

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish-npm:
needs: [create-release, create-metadata]
strategy:
matrix:
package: ${{ fromJson(needs.create-metadata.outputs.pypi_packages) }}
name: Build ${{ matrix.package }}
environment: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm

- name: Install dependencies
working-directory: src/${{ matrix.package }}
run: npm ci

- name: Build package
working-directory: src/${{ matrix.package }}
run: npm run build

- name: Publish package
working-directory: src/${{ matrix.package }}
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
24 changes: 24 additions & 0 deletions scripts/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,29 @@ def generate_version() -> int:
return 0


@cli.command("generate-matrix")
@click.option(
"--directory", type=click.Path(exists=True, path_type=Path), default=Path.cwd()
)
@click.option("--npm", is_flag=True, default=False)
@click.option("--pypi", is_flag=True, default=False)
@click.argument("git_hash", type=GIT_HASH)
def generate_matrix(directory: Path, git_hash: GitHash, pypi: bool, npm: bool) -> int:
# Detect package type
path = directory.resolve(strict=True)
version = gen_version()

changes = []
for package in find_changed_packages(path, git_hash):
pkg = package.path.relative_to(path)
if npm and isinstance(package, NpmPackage):
changes.append(str(pkg))
if pypi and isinstance(package, NpmPackage):
changes.append(str(pkg))

click.echo(json.dumps(changes))
return 0


if __name__ == "__main__":
sys.exit(cli())

0 comments on commit 8bbdb8c

Please sign in to comment.