Skip to content

Publish JetBrains plugin #9

Publish JetBrains plugin

Publish JetBrains plugin #9

Workflow file for this run

name: Publish JetBrains plugin
on:
schedule:
- cron: "17,47 * * * *"
repository_dispatch:
types:
- vscode-marketplace-released
workflow_dispatch:
inputs:
version:
description: Zoo Code version to publish (for example, 3.78.0)
required: true
type: string
permissions:
contents: read
concurrency:
group: jetbrains-marketplace-production
cancel-in-progress: false
jobs:
prepare:
name: Find unpublished stable release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release.outputs.number }}
marketplace-published: ${{ steps.marketplace.outputs.published }}
github-released: ${{ steps.github-release.outputs.published }}
steps:
- name: Resolve and verify the VS Code Marketplace release
id: release
env:
DISPATCH_REPOSITORY: ${{ github.event.client_payload.repository }}
DISPATCH_VERSION: ${{ github.event.client_payload.version }}
MANUAL_VERSION: ${{ inputs.version }}
shell: bash
run: |
expected_repository="Zoo-Code-Org/Zoo-Code"
requested_version="${DISPATCH_VERSION:-$MANUAL_VERSION}"
requested_version="${requested_version#v}"
if [ "$GITHUB_EVENT_NAME" = "repository_dispatch" ] && [ "$DISPATCH_REPOSITORY" != "$expected_repository" ]; then
echo "Expected a release from ${expected_repository}, received ${DISPATCH_REPOSITORY:-<empty>}."
exit 1
fi
if [ -n "$requested_version" ] && [[ ! "$requested_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version must be a stable semantic version (x.y.z), received: $requested_version."
exit 1
fi
query='{"filters":[{"criteria":[{"filterType":7,"value":"ZooCodeOrganization.zoo-code"}]}],"flags":439}'
response="$(curl --fail --silent --show-error --retry 3 \
-H "Content-Type: application/json" \
-H "Accept: application/json;api-version=7.1-preview.1" \
--data "$query" \
https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery)"
# shellcheck disable=SC2016
version="$(printf '%s' "$response" | REQUESTED_VERSION="$requested_version" node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
const data = JSON.parse(input);
const requested = process.env.REQUESTED_VERSION;
const versions = data.results?.[0]?.extensions?.[0]?.versions ?? [];
const stable = versions.filter(({ properties = [] }) =>
!properties.some(({ key, value }) =>
key === "Microsoft.VisualStudio.Code.PreRelease" && value === "true"
)
);
const release = requested
? stable.find(({ version }) => version === requested)
: stable[0];
if (!release) {
console.error(requested
? `ZooCodeOrganization.zoo-code ${requested} is not a stable VS Code Marketplace release.`
: "The VS Code Marketplace did not return a stable Zoo Code release.");
process.exit(1);
}
process.stdout.write(release.version);
});
')"
echo "Resolved stable Zoo Code release $version."
echo "number=$version" >> "$GITHUB_OUTPUT"
- name: Check whether this version is already published
id: marketplace
env:
VERSION: ${{ steps.release.outputs.number }}
shell: bash
run: |
if curl --fail --silent --show-error --retry 3 \
"https://plugins.jetbrains.com/api/plugins/32979/updates?size=100" | \
node -e '
let input = "";
process.stdin.on("data", chunk => input += chunk);
process.stdin.on("end", () => {
const updates = JSON.parse(input);
process.exit(updates.some(update => update.version === process.env.VERSION) ? 0 : 1);
});
'; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "Zoo Code $VERSION is already present on JetBrains Marketplace; skipping the build and upload."
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Check whether the GitHub release exists
id: github-release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.release.outputs.number }}
shell: bash
run: |
if gh release view "v${VERSION}" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
echo "published=true" >> "$GITHUB_OUTPUT"
echo "GitHub release v${VERSION} already exists."
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
publish:
name: Publish Zoo Code ${{ needs.prepare.outputs.version }}
needs: prepare
if: needs.prepare.outputs.marketplace-published != 'true' || needs.prepare.outputs.github-released != 'true'
runs-on: ubuntu-latest
environment: jetbrains-marketplace-production
permissions:
contents: write
steps:
- name: Check out the JetBrains plugin
uses: actions/checkout@v5
with:
lfs: true
- name: Set up Java 17
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "17"
cache: gradle
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: npm
cache-dependency-path: extension_host/package-lock.json
- name: Build the plugin from the released VS Code extension
env:
GITHUB_TOKEN: ${{ github.token }}
ZOO_EXTENSION_VERSION: ${{ needs.prepare.outputs.version }}
run: ./scripts/release.sh --mode release --clean
- name: Publish to JetBrains Marketplace
if: needs.prepare.outputs.marketplace-published != 'true'
env:
PUBLISH_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}
VERSION: ${{ needs.prepare.outputs.version }}
working-directory: jetbrains_plugin
shell: bash
run: |
test -n "$PUBLISH_TOKEN"
test -f "build/distributions/ZooCode-${VERSION}.zip"
./gradlew publishPlugin \
-PdebugMode=release \
-PvscodePlugin=zoo-code \
-PpluginVersion="$VERSION" \
--no-configuration-cache
- name: Create or update the GitHub release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.prepare.outputs.version }}
shell: bash
run: |
tag="v${VERSION}"
artifact="dist/ZooCode-${VERSION}.zip"
notes="Zoo Code ${VERSION} for JetBrains IDEs. This build packages the stable Zoo Code ${VERSION} VS Code Marketplace release."
test -f "$artifact"
if gh release view "$tag" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release upload "$tag" "$artifact" \
--repo "$GITHUB_REPOSITORY" \
--clobber
else
gh release create "$tag" "$artifact" \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--title "Zoo Code ${tag}" \
--notes "$notes"
fi