Skip to content

Commit

Permalink
Jetpack AI Client: Introduce scaffolding for a Jetpack AI client JS p…
Browse files Browse the repository at this point in the history
…ackage (#30855)

* [not verified] Changelog

* [not verified] Introduce Jetpack AI JS client

* [not verified] Update README.md

* [not verified] Update tests env and run script

* [not verified] .

* [not verified] Improve README

* update pnpm-lock file

* fix import statements on docs

* Add composer.json .extra settings

* set private to false on package.json

---------

Co-authored-by: Douglas <douglas.henri@automattic.com>
Co-authored-by: Samiff <samiff@users.noreply.github.com>

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/5268110262
  • Loading branch information
dhasilva authored and matticbot committed Jun 14, 2023
1 parent 1152a8d commit c408036
Show file tree
Hide file tree
Showing 16 changed files with 1,020 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Files not needed to be distributed in the package.
.gitattributes export-ignore
node_modules export-ignore

# Files to exclude from the mirror repo
/changelog/** production-exclude
/.eslintrc.cjs production-exclude
109 changes: 109 additions & 0 deletions .github/workflows/autotagger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Auto-tagger

on:
push:
branches:
- trunk
- prerelease
- '*/branch-*'

jobs:
tag:
name: Tag
runs-on: ubuntu-latest
steps:
- name: Check that the secret is set
env:
TOKEN: ${{ secrets.API_TOKEN_GITHUB }}
run: |
if [[ -z "$TOKEN" ]]; then
echo '::error::The secret API_TOKEN_GITHUB must be set.'
exit 1
fi
- uses: actions/checkout@v3
with:
# We want to potentially trigger "tag" events, but the default GITHUB_TOKEN
# explicitly does not trigger events.
token: ${{ secrets.API_TOKEN_GITHUB }}

- name: Check branch
id: check-branch
run: |
PREFIXES=
if [[ -e composer.json ]]; then
PREFIXES=$(jq -r '.extra["release-branch-prefix"] // "" | if type == "array" then .[] else . end' composer.json)
fi
if [[ -z "$PREFIXES" && "$GITHUB_REF" != "refs/heads/trunk" && "$GITHUB_REF" != "refs/heads/prerelease" ]]; then
echo "::error::Expected to be called for \"refs/heads/trunk\" or \"refs/heads/prerelease\", not \"$GITHUB_REF\""
exit 1
elif [[ -n "$PREFIXES" && ( "$GITHUB_REF" == "refs/heads/trunk" || "$GITHUB_REF" == "refs/heads/prerelease" ) ]]; then
echo "::notice::Ignoring push to $GITHUB_REF, as this project has a release branch prefix set (\"${PREFIXES//$'\n'/'" "'}\")"
echo "run=false" >> "$GITHUB_OUTPUT"
else
if [[ -n "$PREFIXES" ]]; then
OK=false
while IFS= read -r P; do
[[ "$GITHUB_REF" == "refs/heads/$P/branch-"* ]] && OK=true
done <<<"$PREFIXES"
if ! $OK; then
echo "::error::Expected to be called for \"refs/heads/\$PREFIX/branch-*\" for a prefix in \"${PREFIXES//$'\n'/'" "'}\", not \"$GITHUB_REF\""
exit 1
fi
fi
echo "Push to \"$GITHUB_REF\" ok"
echo "run=true" >> "$GITHUB_OUTPUT"
fi
- name: Check version
id: version
if: steps.check-branch.outputs.run == 'true'
run: |
VER=$(sed -nEe 's/^## \[?([^]]*)\]? - .*/\1/;T;p;q' CHANGELOG.md || true)
echo "Version from changelog is ${VER:-<unknown>}"
echo "version=$VER" >> "$GITHUB_OUTPUT"
if [[ "$VER" =~ ^[0-9]+(\.[0-9]+)+$ ]]; then
echo "Version $VER ok to tag"
echo "run=true" >> "$GITHUB_OUTPUT"
else
echo "::notice::Not tagging version $VER"
echo "run=false" >> "$GITHUB_OUTPUT"
fi
- name: Check deps
id: check-deps
if: steps.check-branch.outputs.run == 'true' && steps.version.outputs.run == 'true'
run: |
RUN=true
if [[ -e composer.json ]]; then
TMP=$(jq -r '.require // {} | to_entries[] | select( .value | test( "-(alpha|a.[0-9]+)$" ) ) | "\(.key) (\(.value))"' composer.json)
if [[ -n "$TMP" ]]; then
echo "::notice::Not tagging due to -alpha deps on ${TMP//$'\n'/ }"
RUN=false
fi
fi
echo "run=$RUN" >> "$GITHUB_OUTPUT"
- name: Tag
if: steps.check-branch.outputs.run == 'true' && steps.version.outputs.run == 'true' && steps.check-deps.outputs.run == 'true'
env:
VER: ${{ steps.version.outputs.version }}
run: |
export GIT_AUTHOR_NAME=matticbot
export GIT_AUTHOR_EMAIL=matticbot@users.noreply.github.com
export GIT_COMMITTER_NAME=matticbot
export GIT_COMMITTER_EMAIL=matticbot@users.noreply.github.com
if [[ -e composer.json ]] && ! jq -e 'if try ( .extra.autotagger | has("v") ) catch false then .extra.autotagger.v else true end' composer.json >/dev/null; then
TAG="$VER"
else
TAG="v$VER"
fi
echo "::notice::Tagging $TAG"
git tag "$TAG"
git push origin "$TAG"
if [[ -e composer.json ]] && jq -e '.extra.autotagger.major?' composer.json >/dev/null; then
echo "::notice::Tagging ${TAG%%.*}"
git tag --force "${TAG%%.*}"
git push --force origin "${TAG%%.*}"
fi
33 changes: 33 additions & 0 deletions .github/workflows/npmjs-autopublisher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Npmjs auto-publisher

on:
push:
tags:
- 'v*.*.*'

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Check that the secret is set
env:
TOKEN: ${{ secrets.NPMJS_AUTOMATION_TOKEN }}
run: |
if [[ -z "$TOKEN" ]]; then
echo '::error::The secret NPMJS_AUTOMATION_TOKEN must be set.'
exit 1
fi
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
# NPM version shouldn't matter, just use the LTS.
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'

- name: Publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_AUTOMATION_TOKEN }}
run: npm publish --access public
25 changes: 25 additions & 0 deletions .github/workflows/readonly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Enforce read-only repo status

on:
issues:
types: opened
pull_request_target:
types: opened

jobs:
lockdown:
runs-on: ubuntu-latest
steps:
- uses: dessant/repo-lockdown@v2
with:
github-token: ${{ github.token }}
issue-comment: |
Thank you for your interest!
Issues should be filed at https://github.com/Automattic/jetpack/issues. Be sure to mention the product that the issue is regarding.
skip-closed-issue-comment: true
pr-comment: |
Thank you for your interest!
Pull requests should be made against the monorepo at https://github.com/Automattic/jetpack.
skip-closed-pr-comment: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
node_modules/
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Automatically generated ignore rules.
/.github/
/composer.json
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.0-alpha - unreleased

This is an alpha version! The changes listed here are not final.

### Added
- Add Jetpack AI Client
Loading

0 comments on commit c408036

Please sign in to comment.