Skip to content

Commit

Permalink
add local plugin repo utility (#292)
Browse files Browse the repository at this point in the history
* add local plugin repo utility

* add plugin id arg
  • Loading branch information
yonip23 authored Feb 28, 2022
1 parent c1fdd29 commit f14532e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
40 changes: 40 additions & 0 deletions local-repo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Running a local plugin repository
For more info read: https://plugins.jetbrains.com/docs/intellij/update-plugins-format.html

### Why?
To test a flow which updates the plugin to a new version without actually deploying versions to the marketplace.

### How?
The `run-local-repo.sh` takes a locally built version and creates a web server that serves this version in a format that JetBrains acknowledges.

#### Prerequisites
1. Install `ngrok` and `http-server`:
```bash
npm i -g ngrok http-server
```

#### Instructions
1. Run ngrok, in order to have an https url (IJ requires it):
```bash
ngrok http 8080
```
2. Edit `build.gradle`: Set the version to something higher than what you intend to run, in order for IJ to consider this plugin an "update" - Edit this line:
```groovy
version project.hasProperty('externalVersion') ? project.externalVersion : '<your-version>'
```
3. **In this directory**, run the script like so:
```bash
./run-local-repo.sh -b -u <ngrok https url>
```
(You can drop `-b` if you already have a plugin built in `../build/distributions`).

4. In the output of this command you'll find a line that goes like so:
```
>>> This is the url you need to add as a repository: <url>
```
Copy this `url`.
5. Revert the changes to `build.gradle`.
6. Run the `runIde` gradle task.
7. In the debugger sandbox, got to `Settings -> Plugins -> <Settings icon> -> Manage Plugin Repositories...`. Click the `+` sign - Copy the `url` there.
And that's it! Now You'll see that there's an available update from the local repository with the version you built.
43 changes: 43 additions & 0 deletions local-repo/run-local-repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /bin/bash

set -e

xml_file_name=updatePlugins.xml
build_plugin=false

while getopts :u:i:b flag; do
case "${flag}" in
u) url=${OPTARG} ;;
b) build_plugin=true ;;
i) plugin_id=${OPTARG} ;;
*) ;;
esac
done

if [ "$build_plugin" == "true" ]; then
echo ">>> Building the plugin..."
cd ..
./gradlew buildPlugin
cd -
fi
if [ -z "$plugin_id" ]; then
plugin_id="com.tabnine.TabNine"
fi
if [ -z "$url" ]; then
echo "'-u' is required"
exit
fi

cp ../build/distributions/*TabNine*.zip .
plugin_file="$(basename -- "$(ls -al ./*TabNine*.zip)")"
plugin_version="$(echo "$plugin_file" | grep -o -P '(?<=-).*(?=.zip)')"

xml_data="<plugins><plugin id=\"$plugin_id\" url=\"$url/$plugin_file\" version=\"$plugin_version\"/></plugins>"

printf ">>> generating %s with the following data: \"%s\"\n" "$xml_file_name" "$xml_data"
printf "\n$(tput setaf 2)>>> This is the url you need to add as a repository: %s$(tput sgr0)\n\n" "$url/$xml_file_name"

echo "$xml_data" >$xml_file_name

echo ">>> Running http-server..."
http-server

0 comments on commit f14532e

Please sign in to comment.