Skip to content

Commit

Permalink
feat: add application name as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshay Kalia committed Nov 3, 2022
1 parent 5bcb638 commit 18e7561
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The Github Action can be configured by passing inputs or environment variables:
| --------------- | --------------- |--------------- |
| `api-token` | Token required to connect to Shipyard's APIs. Can be obtained from your Organization's setting page | -|
| `timeout-minutes` | Number of minutes to wait for Shipyard environment before timing out. | 60|
| `app-name` | Filter the environments by name of the application on the Shipyard app. | -|


**Environment Variables**
Expand All @@ -56,12 +57,14 @@ The Github Action can be configured by passing inputs or environment variables:
env:
SHIPYARD_API_TOKEN: ${{ secrets.SHIPYARD_API_TOKEN }}
SHIPYARD_TIMEOUT: 30
INPUT_APP_NAME: 'react-app'
```

| Environment Variable | Description | Default Value |
| --------------- | --------------- |--------------- |
| `SHIPYARD_API_TOKEN` | Token required to connect to Shipyard's APIs. Can be obtained from your Organization's setting page |-|
| `SHIPYARD_TIMEOUT` | Number of minutes to wait for Shipyard environment before timing out. |60|
| `SHIPYARD_APP_NAME` | Filter the environments by name of the application on the Shipyard app. |-|

**NOTE**: Inputs are given precedence over environment variables.

Expand Down
4 changes: 4 additions & 0 deletions fetch-shipyard-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inputs:
timeout-minutes:
description: Number of minutes to wait for Shipyard environment before timing out.
required: false
app-name:
description: Filter the environment by name of the application on the Shipyard app.
required: false

runs:
using: composite
Expand All @@ -23,6 +26,7 @@ runs:
run: |
echo "INPUT_API_TOKEN=${{ inputs.api-token }}" >> $GITHUB_ENV
echo "INPUT_TIMEOUT_MINUTES=${{ inputs.timeout-minutes }}" >> $GITHUB_ENV
echo "INPUT_APP_NAME=${{ inputs.app-name }}" >> $GITHUB_ENV
shell: bash
- name: Fetch the Shipyard environment variables
run: python $GITHUB_ACTION_PATH/../src/fetch_shipyard_env.py
Expand Down
8 changes: 7 additions & 1 deletion src/fetch_shipyard_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- GITHUB_REF_NAME
- INPUT_API_TOKEN or SHIPYARD_API_TOKEN
- INPUT_TIMEOUT_MINUTES or SHIPYARD_TIMEOUT
- INPUT_APP_NAME or SHIPYARD_APP_NAME
"""
from __future__ import print_function

Expand Down Expand Up @@ -65,6 +66,11 @@ def exit(msg):
else:
timeout_minutes = 60

# Get the app name
app_name = os.environ.get("INPUT_APP_NAME")
if not app_name:
app_name = os.environ.get("SHIPYARD_APP_NAME")

# Prepare API client
configuration = swagger_client.Configuration()
configuration.api_key["x-api-token"] = api_token
Expand All @@ -78,7 +84,7 @@ def fetch_shipyard_environment():
# Hit the Shipyard API
try:
response = api_instance.list_environments(
org_name=org_name, repo_name=repo, branch=branch
org_name=org_name, repo_name=repo, branch=branch, name=app_name
).to_dict()
except ApiException as e:
exit("ERROR: issue while listing environments via API: {}".format(e))
Expand Down

0 comments on commit 18e7561

Please sign in to comment.