Skip to content

Commit

Permalink
Configure release to PyPI and Homebrew (#48)
Browse files Browse the repository at this point in the history
* Setup PyPI deployment

* Switch to real PyPI index

* Tweak kernelspec assembly

* Trigger `pip` release on github release publishing

* Line break moment

* Remove deployment environment

* Return missing SCM

* Setup Homebrew release

* Fix metadata injection

* Update Homebrew release target

* New line moment
  • Loading branch information
m-dzianishchyts authored Oct 14, 2024
1 parent e993dac commit a1e5a64
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 56 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
java: [ 11, 17, 21 ]

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

- name: Set up JDK...
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
cache: 'maven'

- name: Build and test...
- name: Build and test
run: mvn clean verify -U
75 changes: 75 additions & 0 deletions .github/workflows/release-prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: 'prepare release'

on:
push:
tags:
- '[0-9]+.[0-9]+.?[ab]?[0-9]+'
permissions:
# allow a write access to GitHub Releases
contents: write

jobs:
build:
runs-on: ubuntu-latest

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

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

- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'

- name: Install build dependencies
run: pip install build

- name: Build
env:
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_jjava: ${{ github.ref_name }}
run: |
mvn clean verify -U
python -m build
- name: Collect the release distributions
run: |
mkdir -p release/
cp jjava/target/jjava-${{ github.ref_name }}-kernelspec.zip release/
cp -r dist/* release/
- name: Store the release distributions
uses: actions/upload-artifact@v4
with:
name: release-distributions
path: release/
if-no-files-found: error

prepare-release:
runs-on: ubuntu-latest
needs:
- build

steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: release-distributions
path: release/

- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
body: JJava ${{ github.ref_name }} release
draft: true
prerelease: false
files: release/*
fail_on_unmatched_files: true
93 changes: 54 additions & 39 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
name: 'create release'
name: 'release packages'

on:
push:
tags:
- '[0-9]+.[0-9]+*'

permissions:
# allow a write access to GitHub Releases
contents: write
release:
types: [published]

jobs:
prepare-release:
release-pypi:
runs-on: ubuntu-latest

outputs:
tag: ${{ steps.vars.outputs.tag }}
version: ${{ steps.vars.outputs.version }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
permissions:
id-token: write

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

- name: Set up JDK...
uses: actions/setup-java@v4
- name: Download release assets
uses: robinraju/release-downloader@v1
with:
java-version: 17
distribution: 'temurin'
cache: 'maven'
tag: ${{ github.ref_name }}
fileName: jjava-!(kernelspec)*@(.tar.gz|.whl)
out-file-path: dist/

- name: Build...
run: mvn clean package
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: ${{ runner.debug }}

- name: Set version...
id: vars
run: |
RELEASE_TAG=${GITHUB_REF#refs/*/}
echo "tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT
echo "version=${RELEASE_TAG}" >> $GITHUB_OUTPUT
release-homebrew:
runs-on: ubuntu-latest

- name: Create release...
id: create_release
uses: softprops/action-gh-release@v2
steps:
- name: Publish package to Homebrew
uses: m-dzianishchyts/brewtap@v1
with:
tag_name: ${{ steps.vars.outputs.tag }}
body: JJava ${{ steps.vars.outputs.version }} release
draft: true
prerelease: false
files: ./jjava/target/jjava-${{ steps.vars.outputs.version }}.zip
fail_on_unmatched_files: true
homebrew_owner: dflib
homebrew_tap: homebrew-tap
version: ${{ github.ref_name }}
depends_on: |
"jupyterlab"
"expect" => :test
target: jjava-${{ github.ref_name }}-kernelspec.zip
install: |
libexec.install Dir["*.jar"]
config = buildpath/"kernel.json"
inreplace config, "{resource_dir}", libexec
system "jupyter kernelspec install #{buildpath} --config=#{config} --sys-prefix --name=java"
test: |
jupyter = Formula["jupyterlab"].opt_bin/"jupyter"
assert_match " java ", shell_output("#{jupyter} kernelspec list")
(testpath/"console.exp").write <<~EOS
spawn #{jupyter} console --kernel=java
expect -timeout 30 "In "
send "System.out.println(\\\"Hello world!\\\");\r"
expect -timeout 10 "In "
send "\u0004"
expect -timeout 10 "exit"
send "y\r"
EOS
output = shell_output("expect -f console.exp")
assert_match "JJava kernel #{version}", output
assert_match "Hello world!", output
caveats: |
Although JJava doesn't depend on java, it requires jre>=11 to run.
Make sure you have one in your PATH.
update_readme_table: true
github_token: ${{ secrets.HOMEBREW_RELEASE_ACCESS_TOKEN }}
debug: ${{ runner.debug }}
6 changes: 3 additions & 3 deletions install-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#

BUILD_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
BUILD_DIR="jjava/target/jjava-${BUILD_VERSION}"
BUILD_DIR="jjava/target/jjava-${BUILD_VERSION}-kernelspec"
KERNEL_DIR="$(pwd)/${BUILD_DIR}"

mvn clean package || exit 1
unzip -u "${BUILD_DIR}".zip -d "${BUILD_DIR}" || exit 1
jupyter kernelspec install "${KERNEL_DIR}" --name=java --user || exit 1
unzip -u "${BUILD_DIR}".zip -d "${BUILD_DIR}" || exit 2
jupyter kernelspec install "${KERNEL_DIR}" --name=java --user || exit 3
5 changes: 1 addition & 4 deletions jjava/assembly/zip/zip.xml → jjava/assembly/kernelspec.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>zip</id>
<formats>
<format>zip</format>
</formats>
<id>kernelspec</id>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
Expand Down
14 changes: 11 additions & 3 deletions jjava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -113,16 +119,18 @@
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble-zip</id>
<id>assemble-kernelspec</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly/zip/zip.xml</descriptor>
<descriptor>assembly/kernelspec.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<formats>
<format>zip</format>
</formats>
</configuration>
</execution>
</executions>
Expand Down
6 changes: 3 additions & 3 deletions jjava/src/main/resources/jjava-kernel-metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "@version@",
"project": "@project@"
}
"version": "${project.version}",
"project": "${project.artifactId}"
}
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build-backend = "setuptools.build_meta"

[project]
name = "jjava"
version = "1.0+SNAPSHOT"
requires-python = ">=3.8"
description = "A Jupyter kernel for Java notebooks"
authors = [
Expand All @@ -21,6 +20,7 @@ classifiers = [
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows"
]
dynamic = ["version"]

[project.urls]
Documentation = "https://dflib.org/jjava/docs/1.x/"
Expand All @@ -33,5 +33,8 @@ Changelog = "https://github.com/dflib/jjava/blob/main/RELEASE-NOTES.md"
where = ["pip"]
include = ["jjava"]

[tool.setuptools_scm]
version_file = "pip/jjava/_version.py"

[tool.setuptools.data-files]
"share/jupyter/kernels/java" = ["kernelspec/java/*"]

0 comments on commit a1e5a64

Please sign in to comment.