npm package: @ouc/distribute-software
Description: Distrubute OUC software to our various systems.
Latest version: 2.0.3

# @ouc/nextcloud-distribute

Access nextcloud and distribute ouc product releases.

## Dependencies

-   [nextcloud-node-client](https://github.com/hobigo/nextcloud-node-client)
-   [commander](https://github.com/tj/commander.js)

## Installation

The package is published on npmjs.com. Just run this command:

```
npm install @ouc/distribute-software --save-dev
```

## Configuration

Make sure that the appropriate environment variables are set in the project.

```
/* Usually set by bitbucker automatically */
REPO_SLUG -> important for the creation of the file name
BRANCH_NAME -> important for the creation of the file name

/* Only required on upload to nextcloud */
NEXTCLOUD_USER -> nextcloud credentials
NEXTCLOUD_APP_PASSWORD -> nextcloud credentials
NEXTCLOUD_URL -> Your nextcloud host
NEXTCLOUD_SLUG -> base path of the desired place for the zip file on nextcloud (e.g. /Software-Intern/ousp-vacationmanagement)

/* Only required on upload to docker hub */
DOCKER_HUB_REPOSITORY -> docker hub repository name
DOCKER_HUB_USERNAME -> docker hub credentials
DOCKER_HUB_PASSWORD -> docker hub credentials

/* Only required on upload to chartmuseum */
CHARTMUSEUM_URL -> helm chartmuseum url
CHARTMUSEUM_USERNAME -> helm chartmuseum credentials
CHARTMUSEUM_PASSWORD -> helm chartmuseum credentials
```

## Usage

The package takes care of the correct creation of the ZIP-file name. All you have to do is, call the script with the desired version.

```
node node_modules/@ouc/distribute-software upload <version> -h <path/to/helm-chart> -n <path/to/dist-folder> -d <docker-build-tag>
```

ℹ️ Upload to nextcloud also generates a .zipFilePath file, which includes the path to the generated zip file for further usage, e.g. bitbucket file upload.

## E.g.

bitbucket-pipelines.yml

```yaml
 - step: &deploy-artifacts-docker
        name: Deploy artifacts and Docker images (hub.docker.com)
        image:
          name: oneunity/docker-compose
          username: $DOCKER_HUB_USERNAME
          password: $DOCKER_HUB_PASSWORD
        caches:
          - docker
          - npm
          - node
        script:
          - *git-auth
          - *git-checkout-stashed-hash
          - *docker-build
          - PACKAGE_VERSION=$(node -p "require('./package.json').version")
          - node node_modules/@ouc/distribute-software/ upload $PACKAGE_VERSION -n ./dist/prod -d vacationmanagement:build
          - pipe: atlassian/bitbucket-upload-file:0.3.3
            variables:
              BITBUCKET_USERNAME: "${BITBUCKET_USERNAME}"
              BITBUCKET_APP_PASSWORD: "${BITBUCKET_APP_PASSWORD}"
              FILENAME: "$(cat .zipFilePath)"
```

### Jira

To use the automatic version and asset management on Jira, the following environment variables must be defined:
`JIRA_HOST`, `JIRA_USER`, `JIRA_API_TOKEN`, `JIRA_PROJECT_ID`.

#### Jira NEXT version

To create a new `NEXT` release, the `-jn` parameter must be used.

e.g.

```
node node_modules/@ouc/distribute-software/ upload $PACKAGE_VERSION -jn
```

Here the current `NEXT` version will automatically be renamed and a new one created.

#### Jira release version

To create a new `NEXT` release, the `-jr` parameter must be used.

e.g.

```
node node_modules/@ouc/distribute-software/ upload $PACKAGE_VERSION -jr
```

### Jira Assets

To use the automatic version and asset management on Jira, the following environment variables must be defined:
`JIRA_HOST`, `JIRA_ASSET_WORKSPACE_ID`, `JIRA_ASSET_APP_NAME`, `JIRA_ASSET_PRODUCT_CAT`.

#### Jira asset create

To create a new asset, the `-jac` parameter must be used.
e.g.

```
node node_modules/@ouc/distribute-software/ upload $PACKAGE_VERSION -jac
```

#### Jira asset release

To release a existing asset, the `-jar` parameter must be used.
e.g.

```
node node_modules/@ouc/distribute-software/ upload $PACKAGE_VERSION -jar
```