Skip to content

Commit

Permalink
add install input
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Dec 21, 2023
1 parent 57311d1 commit f94196c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 21 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,56 @@ Preevy's [GitHub plugin](https://preevy.dev/github-plugin) will automatically up

See the [preevy-up action](https://github.com/marketplace/actions/preevy-up) for more information and examples.

## Permissions

Preevy requires the following [GitHub Actions permissions](https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs):

* `contents: read`: used by Preevy to read the Docker Compose file(s)
* `pull-requests: write`: used by the Preevy GitHub plugin to write or update a comment on the PR

In addition, if you're using GitHub's OIDC Token endpoint to authenticate to your cloud provider (as in the below examples), `id-token: write`: is also needed.

## Inputs

### `profile-url`

*required*: `true`

The profile url created by the CLI, [as detailed in the docs](https://preevy.dev/ci).
The profile url created by the CLI, [as detailed in the docs](https://preevy.dev/ci/).

### `docker-compose-yaml-paths`
### `args`

*required*: `false`

Optional path to the `docker-compose.yaml` file. If not provided, uses the working directory. If you have multiple docker compose files, you can add them as a comma seperated string like so `'docker-compose.yml,docker-compose.dev.yml'`
Optional additional args to the `preevy down` command. [Full reference](https://preevy.dev/cli-reference/down).

### `args`
### `version`

*required*: `false`

The preevy [CLI version](https://www.npmjs.com/package/preevy?activeTab=versions) to use. Defaults to `latest`.

***Note*** Since `v1.3.0`, this action requires Preevy CLI version `v0.0.58` or newer. To use an older version of the CLI, use `livecycle/[email protected]`.

### `docker-compose-yaml-paths`

*required*: `false`

Optional additional args to the `preevy down` command, see the full reference [here](https://preevy.dev/cli-reference/#preevy-down).
Optional path to the `docker-compose.yaml` file. If not provided, uses the working directory. If you have multiple docker compose files, you can add them as a comma seperated string like so `'docker-compose.yml,docker-compose.dev.yml'`

### `version`
### `install`

*required*: `false`

The preevy [CLI version](https://www.npmjs.com/package/preevy?activeTab=versions) to use. Defaults to `latest`.
***EXPERIMENTAL***. Installation method for the Preevy CLI. Specify `gh-release` to install Preevy from a binary file, which is much faster than using NPM. Specify `none` to skip the installation steps. The default is `npm` which will install from NPM.

***Note*** Version `v1.2.0` of this action supports Preevy CLI versions `0.0.58` and up. To use an older version of the CLI, use `livecycle/preevy[email protected]`.
If `gh-release` is specified, `version` can be either `latest` or one of the [released versions](https://github.com/livecycle/preevy/releases). Canary versions are not supported.

### `node-cache`

*required*: `false`

Node package manager used for caching. Supported values: npm, yarn, pnpm, or ''. [Details](https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data). Default: npm.

Node package manager used for caching. Supported values: `npm`, `yarn`, `pnpm`, or ''. [Details](https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data). Default: `npm`.

## Example usage

Expand All @@ -74,11 +90,10 @@ jobs:
aws-region: eu-west-1

- uses: actions/checkout@v3
- uses: livecycle/preevy-down-action@v1.2.0
- uses: livecycle/preevy-down-action@v1.3.0
id: preevy
with:
# Create the profile using the `preevy init` command, see
# https://preevy.dev/ci/overview
# Create the profile using the `preevy init` command, see https://preevy.dev/ci
profile-url: "s3://preevy-12345678-my-profile?region=eu-west-1"
docker-compose-yaml-paths: "./docker/docker-compose.yaml"
```
Expand Down
63 changes: 55 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
description: "The Preevy profile URL"
args:
required: false
description: "Additional args to provide to the `down` command."
description: "Additional args to provide to the `up` command."
docker-compose-yaml-paths:
required: false
description: "Array of comma separated paths to docker compose files. Uses current working directory if not provided."
Expand All @@ -20,24 +20,71 @@ inputs:
default: latest
node-cache:
required: false
description: "Specify Node package manager for caching. Supported values: npm, yarn, pnpm, or ''. See https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data"
description: "Node package manager used for caching. Supported values: npm, yarn, pnpm, or ''. See https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data"
default: npm
install:
required: false
description: "EXPERIMENTAL: Installation method of the Preevy CLI. Supported values: npm, gh-release or none"
default: npm
outputs: {}
runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
-
uses: actions/setup-node@v4
if: ${{ inputs.install == 'npm' }}
with:
node-version: 18
cache: ${{ inputs.node-cache }}

- name: Run Preevy down
- name: Install Preevy from GH release
shell: bash
id: install_prevy_gh_release
if: ${{ inputs.install == 'gh-release' }}
run: |
set -eou pipefail
function os_suffix() {
case "${{ runner.os }}" in
"Linux") echo -n "linux";;
"Windows") echo -n "win";;
"macOS") echo -n "macos";;
*) echo "No release for OS ${{ runner.os }}" 1>&2; exit 1;;
esac
}
function arch_suffix() {
case "${{ runner.arch }}" in
"X64") echo -n "x64";;
"ARM64") echo -n "arm64";;
*) echo "No release for arch ${{ runner.arch }}" 1>&2; exit 1;;
esac
}
release_version='${{ inputs.version }}'
if [[ "${{ inputs.version }}" == "latest" ]]; then
release_version=$(curl -s https://api.github.com/repos/livecycle/preevy/releases/latest | jq -r .tag_name)
fi
release_file="preevy-$(os_suffix)-$(arch_suffix).tar"
release_url="https://github.com/livecycle/preevy/releases/download/${release_version}/${release_file}"
wget -q "${release_url}" -O - | sudo tar -x -C /usr/local/bin
- name: Run Preevy
shell: bash
id: run_preevy_down
id: run_preevy
run: |
file_opt=""
if [[ ! -z "${{ inputs.docker-compose-yaml-paths }}" ]]; then
file_opt="-f ${{ inputs.docker-compose-yaml-paths }}"
opts="-f ${{ inputs.docker-compose-yaml-paths }}"
fi
urls_file=${RUNNER_TEMP}/preevy_urls.${RANDOM}.json
if [[ "${{ inputs.install }}" == "npm" ]]; then
preevy_cmd="npx -- preevy@${{ inputs.version }}"
else
preevy_cmd=preevy
fi
npx -- preevy down --profile '${{ inputs.profile-url }}' ${file_opt} ${{ inputs.args }}
${preevy_cmd} down ${opts} --profile '${{ inputs.profile-url }}' ${{ inputs.args }}

0 comments on commit f94196c

Please sign in to comment.