chore: release main #29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| release: | |
| types: | |
| - published | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| env: | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Run release-please | |
| if: ${{ github.event_name == 'push' }} | |
| id: release | |
| uses: googleapis/release-please-action@v4 | |
| with: | |
| config-file: .github/release-please-config.json | |
| manifest-file: .release-please-manifest.json | |
| - name: Checkout | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| uses: actions/checkout@v6 | |
| - name: Install toolchains | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| uses: jdx/mise-action@v4 | |
| with: | |
| cache: true | |
| - name: Install npm dependencies | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| run: npm ci | |
| - name: Run checks | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| run: npm run check | |
| - name: Publish npm package with trusted publishing | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| run: | | |
| set -euo pipefail | |
| package_name="$(node -p "require('./package.json').name")" | |
| package_version="$(node -p "require('./package.json').version")" | |
| published_version="$(npm view "$package_name" version 2>/dev/null || true)" | |
| if [ "$published_version" = "$package_version" ]; then | |
| echo "$package_name@$package_version is already published; skipping npm publish." | |
| exit 0 | |
| fi | |
| npm publish | |
| - name: Build Python package | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| run: | | |
| python -m pip install --upgrade build | |
| npm run python:build | |
| - name: Check PyPI published version | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| id: pypi | |
| run: | | |
| set -euo pipefail | |
| package_name="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['name'])")" | |
| package_version="$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")" | |
| published_version="$(python - "$package_name" <<'PY' | |
| import json | |
| import sys | |
| import urllib.error | |
| import urllib.request | |
| package_name = sys.argv[1] | |
| try: | |
| with urllib.request.urlopen(f"https://pypi.org/pypi/{package_name}/json", timeout=15) as response: | |
| print(json.load(response)["info"]["version"]) | |
| except urllib.error.HTTPError as error: | |
| if error.code != 404: | |
| raise | |
| PY | |
| )" | |
| echo "name=$package_name" >> "$GITHUB_OUTPUT" | |
| echo "version=$package_version" >> "$GITHUB_OUTPUT" | |
| if [ "$published_version" = "$package_version" ]; then | |
| echo "$package_name@$package_version is already published; skipping PyPI publish." | |
| echo "publish=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "publish=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish Python package with trusted publishing | |
| if: ${{ (github.event_name != 'push' || steps.release.outputs.releases_created == 'true') && steps.pypi.outputs.publish == 'true' }} | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| - name: Check crates.io published version | |
| if: ${{ github.event_name != 'push' || steps.release.outputs.releases_created == 'true' }} | |
| id: crate | |
| run: | | |
| set -euo pipefail | |
| crate_name="$(cargo metadata --no-deps --format-version 1 | python -c "import json,sys; data=json.load(sys.stdin); print(next(pkg['name'] for pkg in data['packages'] if pkg['manifest_path'].endswith('/crates/agenthint/Cargo.toml')))")" | |
| crate_version="$(cargo metadata --no-deps --format-version 1 | python -c "import json,sys; data=json.load(sys.stdin); print(next(pkg['version'] for pkg in data['packages'] if pkg['manifest_path'].endswith('/crates/agenthint/Cargo.toml')))")" | |
| published_version="$(cargo search "$crate_name" --limit 1 | sed -n "s/^$crate_name = \"\\([^\"]*\\)\".*/\\1/p" || true)" | |
| echo "name=$crate_name" >> "$GITHUB_OUTPUT" | |
| echo "version=$crate_version" >> "$GITHUB_OUTPUT" | |
| if [ "$published_version" = "$crate_version" ]; then | |
| echo "$crate_name@$crate_version is already published; skipping cargo publish." | |
| echo "publish=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "publish=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Request crates.io trusted publishing token | |
| if: ${{ (github.event_name != 'push' || steps.release.outputs.releases_created == 'true') && steps.crate.outputs.publish == 'true' }} | |
| id: cargo-auth | |
| uses: rust-lang/crates-io-auth-action@v1 | |
| - name: Publish Rust crate with trusted publishing | |
| if: ${{ (github.event_name != 'push' || steps.release.outputs.releases_created == 'true') && steps.crate.outputs.publish == 'true' }} | |
| run: cargo publish -p agenthint --locked | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ steps.cargo-auth.outputs.token }} |