# semantic-release-space

> A Semantic Release JetBrains Space plugin

Latest version **1.4.1** (published 2023-06-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install semantic-release-space
pnpm add semantic-release-space
yarn add semantic-release-space
bun add semantic-release-space
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.1 |
| Published | 2023-06-23 |
| First published | 2022-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 163.6 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Florian Kostenzer |
| Maintainers | 123flo321 |
| Keywords | jetbrains, space, jetbrains-space, semantic-release, plugin, semantic-release-plugin |

## Links

- npm: https://www.npmjs.com/package/semantic-release-space
- Repository: https://github.com/123FLO321/semantic-release-space
- Homepage: https://github.com/123FLO321/semantic-release-space#readme
- Issues: https://github.com/123FLO321/semantic-release-space/issues
- npm.io page: https://npm.io/package/semantic-release-space

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ~0.27.2
- [handlebars](https://npm.io/package/handlebars.md) ~4.7.7
- [jetbrains-space-api](https://npm.io/package/jetbrains-space-api.md) ~1.7.0

## Recent versions

- 1.4.1 (latest) — 2023-06-23
- 1.4.0-beta.4 (beta) — 2023-06-23
- 1.4.0 — 2023-06-23
- 1.4.0-beta.3 — 2023-06-23
- 1.4.0-beta.2 — 2023-06-22
- 1.4.0-beta.1 — 2023-06-22
- 1.3.4 — 2022-10-09
- 1.3.3 — 2022-07-25
- 1.3.2 — 2022-07-24
- 1.3.1 — 2022-07-22
- 1.3.0 — 2022-07-22
- 1.2.0 — 2022-07-21
- 1.1.4 — 2022-07-20
- 1.1.3 — 2022-07-20
- 1.1.2 — 2022-07-19
- … 4 more at https://npm.io/package/semantic-release-space/versions

## README

# semantic-release-space

[**semantic-release**](https://github.com/semantic-release/semantic-release) plugin to publish a
[JetBrains Space Deployment](https://www.jetbrains.com/help/space/deployments.html).

[![npm latest version](https://img.shields.io/npm/v/semantic-release-space/latest.svg)](https://www.npmjs.com/package/semantic-release-space)
[![npm next version](https://img.shields.io/npm/v/semantic-release-space/next.svg)](https://www.npmjs.com/package/semantic-release-space)
[![npm beta version](https://img.shields.io/npm/v/semantic-release-space/beta.svg)](https://www.npmjs.com/package/semantic-release-space)

| Step               | Description                                                                                                                                                  |
|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `verifyConditions` | Verifies that all required options are set.                                                                                                                  |
| `prepare`          | Creates a [JetBrains Space Deployment Target](https://www.jetbrains.com/help/space/deployments.html#creating-a-deployment-targetl) if it does not yet exist. |
| `publish`          | Starts a [JetBrains Space Deployment](https://www.jetbrains.com/help/space/deployments.html).                                                                |
| `success`          | Marks the [JetBrains Space Deployment](https://www.jetbrains.com/help/space/deployments.html) as completed.                                                  |
| `fail`             | Marks the [JetBrains Space Deployment](https://www.jetbrains.com/help/space/deployments.html) as failed.                                                     |

## Install

```bash
$ npm install --save-dev semantic-release-space
```

## Usage

The plugin can be configured in the [**semantic-release** configuration file](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration):

```json
"plugins": [
  ...
  [
    "semantic-release-space", {
      "targetId": "example-target"
    }
  ]
  ...
]
```

With this example a [JetBrains Space Deployment](https://www.jetbrains.com/help/space/deployments.html) will be published on the `example-target` deployment target .


## Configuration

Make sure to set `targetId` or `JB_SPACE_TARGET_ID` to the deployment target you want to use.
All other options are automatically set via their environment variables in a Space Job.

### Options and Environment variables

| Option             | Environment variable                        | Type                  | Description                                                                                                                    |
|--------------------|---------------------------------------------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `target`           | `JB_SPACE_TARGET_ID`                        | `TargetConfiguration` | **Required**<br/>The Space deployment target(s)<br>Set to an key value object to specify target(s) per branch                  |
| `projectId`        | `JB_SPACE_PROJECT_ID`                       | `string`              | **Required** *Automatically set in JetBrains Space Jobs*<br/>The Space project id                                              |
| `apiUrl`           | `JB_SPACE_API_URL`                          | `string`              | **Required** *Automatically set in JetBrains Space Jobs*<br/>The Space API url                                                 |
| `apiToken`         | `JB_SPACE_TOKEN`<br>`JB_SPACE_CLIENT_TOKEN` | `string`              | **Required** *Automatically set in JetBrains Space Jobs*<br/>The Space API auth token                                          |
| `repositoryName`   | `JB_SPACE_GIT_REPOSITORY_NAME`              | `string`              | **Required** *Automatically set in JetBrains Space Jobs*<br/>The repositories name                                             |
| `requireTarget`    | `JB_SPACE_REQUIRE_TARGET`                   | `boolean`             | *Defaults to true*<br/>If set to false an invalid or missing target configuration will be ignored instead of throwing an error |
| `job`              | `JB_SPACE_JOB_ID`                           | `JobConfiguration`    | *Defaults to []*<br>The Space automation job(s) to start<br/>Set to an key value object to specify job(s) per branch           |
| `jobTimeout`       | `JB_SPACE_JOB_TIMEOUT`                      | `number`              | *Defaults to 3600*<br/>The max timeout waiting for jobs to complete in seconds                                                 |
| `jobCheckInterval` | `JB_SPACE_JOB_CHECK_INTERVAL`               | `number`              | *Defaults to 10*<br/>The interval between job status checks in seconds                                                         |

#### Option Types
- TargetConfiguration: `string | string[] | { [branch: string]: string | string[] }` 
- JobConfiguration: `JobBranchConfiguration | { [branch: string]: JobBranchConfiguration }`
- JobBranchConfiguration: `string | string[] | { id: string, parameters?: { [name: string]: string } }`

#### Job Parameters

Job parameters can be set via the `parameters` property of a job configuration for all or only specific branches.
The values will be parsed using [Handlebars](https://handlebarsjs.com/) and with the [plugin context](https://semantic-release.gitbook.io/semantic-release/developer-guide/plugin#context) as template context.
Examples:
 - `"parameters": { "hello": "world" }` will set the parameter `hello` to `world`
 - `"parameters": { "version": "{{nextRelease.version}}" }` will set the parameter `version` to the next release version
 - `"parameters": { "channel": "{{#if nextRelease.channel}}{{nextRelease.channel}}{{else}}latest{{/if}}" }` will set the parameter `channel` to the next release channel or `latest` if no channel is set



## Job Example

With this example the package.json will be pumped and committed, a NPM package will be published and a [JetBrains Space Deployment](https://www.jetbrains.com/help/space/deployments.html)
of the new tag will be published on the `example-target` deployment target.

### Authentication

- Go into your Space Instance > Extensions > Applications and create a new Application (or select an existing one).
- Go into Authorization and give the Application at least the following permissions for the target project:
  - `Read Git repositories`
  - `Write Git repositories`
  - `Create package registries`
  - `Read package registries`
  - `Write package registires`
- Go into Permanent Tokens and create and copy a new token for the Application.
- Go into Projects > your target project > Settings > Secrets & Parameters > and create a new secret:
  - key: `ci-token`
  - value: `<application key>:<the token you just coppied>`

### .releaserc
```json
{
  "branches": [
    "main"
  ],
  "plugins": [
    [
      "@semantic-release/commit-analyzer",
      {}
    ],
    [
      "@semantic-release/release-notes-generator",
      {
        "linkCompare": false,
        "linkReferences": false
      }
    ],
    [
      "semantic-release-space",
      {
        "targetId": "example-target",
        "job": {
          "id": "Example",
          "parameters": {
            "example-param": "example-value",
            "release-version": "{{nextRelease.version}}",
            "release-channel": "{{#if nextRelease.channel}}{{nextRelease.channel}}{{else}}latest{{/if}}"
          }
        }
      }
    ],
    [
      "@semantic-release/npm",
      {}
    ],
    [
      "@semantic-release/git",
      {
        "assets": [
          "package.json"
        ],
        "message": "release: ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ]
  ]
}
```

### .space.kts
```kotlin
job("Release") {
  git {
    refSpec = "refs/heads/main"
  }

  container(displayName = "Publish", image = "node:lts") {
    env["GIT_CREDENTIALS"] = Secrets("ci-token")
    env["NPM_TOKEN"] = Secrets("ci-token")
    shellScript {
      content = """
        npm install
        npx semantic-release
      """
    }
  }
}

job("Example") {
  parameters {       
    text("release-version")
    text("release-channel")
    text("example-param")
  }

  startOn {}

  container(image = "alpine:lts") {
    shellScript {
      content = """
        echo {{ release-version }}
        echo {{ release-channel }}
        echo {{ example-param }}
      """
    }
  }  
}
```

---
_Source: https://npm.io/package/semantic-release-space · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
