Skip to content

Commit 5bcb638

Browse files
author
Peter Valdez
authored
Merge pull request #1 from shipyard/feat/add-fetch-shipyard-env-action
feat: add fetch shipyard env action
2 parents 09a3dbc + 44db575 commit 5bcb638

18 files changed

Lines changed: 3247 additions & 129 deletions

.gitignore

Lines changed: 4 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,4 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
build/
12-
develop-eggs/
13-
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
pip-wheel-metadata/
24-
share/python-wheels/
25-
*.egg-info/
26-
.installed.cfg
27-
*.egg
28-
MANIFEST
29-
30-
# PyInstaller
31-
# Usually these files are written by a python script from a template
32-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33-
*.manifest
34-
*.spec
35-
36-
# Installer logs
37-
pip-log.txt
38-
pip-delete-this-directory.txt
39-
40-
# Unit test / coverage reports
41-
htmlcov/
42-
.tox/
43-
.nox/
44-
.coverage
45-
.coverage.*
46-
.cache
47-
nosetests.xml
48-
coverage.xml
49-
*.cover
50-
*.py,cover
51-
.hypothesis/
52-
.pytest_cache/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
68-
# Scrapy stuff:
69-
.scrapy
70-
71-
# Sphinx documentation
72-
docs/_build/
73-
74-
# PyBuilder
75-
target/
76-
77-
# Jupyter Notebook
78-
.ipynb_checkpoints
79-
80-
# IPython
81-
profile_default/
82-
ipython_config.py
83-
84-
# pyenv
85-
.python-version
86-
87-
# pipenv
88-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91-
# install all needed dependencies.
92-
#Pipfile.lock
93-
94-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95-
__pypackages__/
96-
97-
# Celery stuff
98-
celerybeat-schedule
99-
celerybeat.pid
100-
101-
# SageMath parsed files
102-
*.sage.py
103-
104-
# Environments
105-
.env
106-
.venv
107-
env/
108-
venv/
109-
ENV/
110-
env.bak/
111-
venv.bak/
112-
113-
# Spyder project settings
114-
.spyderproject
115-
.spyproject
116-
117-
# Rope project settings
118-
.ropeproject
119-
120-
# mkdocs documentation
121-
/site
122-
123-
# mypy
124-
.mypy_cache/
125-
.dmypy.json
126-
dmypy.json
127-
128-
# Pyre type checker
129-
.pyre/
1+
.pytest_cache
2+
.DS_Store
3+
*.pyc
4+
__pycache__/

README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Shipyard Github Action
2+
3+
[![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/shipyard/github-action/master/LICENSE) [![Github Action Community](https://img.shields.io/badge/community-Github%20Actions%20Discuss-343434.svg)](https://github.community/c/github-ecosystem/github-apps/64)
4+
5+
Use Github Action to run jobs on ephemeral environments automatically deployed by Shipyard, authenticating into them via a bypass token.
6+
This job connects with Shipyard during a Github Action job, fetching necessary environment variables in order to run e2e tests where authentication via OAuth is normally required.
7+
8+
## How to use
9+
10+
In your Github Workflow file located in `.github/workflows/`, you can use the Shipyard's Github Action as per the following example:
11+
12+
```
13+
on: [pull_request]
14+
15+
jobs:
16+
cypress-e2e-tests:
17+
runs-on: ubuntu-latest
18+
name: Collect the bypass token and URL for an authenticated ephemeral environment attached to this PR in order to run e2e tests on it.
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Fetch Shipyard Tokens
23+
uses: shipyard/github-action/fetch-shipyard-env@1.0.0
24+
env:
25+
SHIPYARD_API_TOKEN: ${{ secrets.SHIPYARD_API_TOKEN }}
26+
- name: Run the e2e tests on the ephemeral environment
27+
run: npm run test
28+
shell: bash
29+
env:
30+
CYPRESS_BASE_URL: $SHIPYARD_ENVIRONMENT_URL
31+
CYPRESS_BYPASS_TOKEN: $SHIPYARD_BYPASS_TOKEN
32+
33+
```
34+
35+
The Github Action can be configured by passing inputs or environment variables:
36+
37+
**Inputs**
38+
```
39+
- name: Fetch Shipyard Tokens
40+
uses: shipyard/github-action/fetch-shipyard-env@1.0.0
41+
with:
42+
api-token: ${{ secrets.SHIPYARD_API_TOKEN }}
43+
timeout-minutes: 30
44+
```
45+
46+
| Input name | Description | Default Value |
47+
| --------------- | --------------- |--------------- |
48+
| `api-token` | Token required to connect to Shipyard's APIs. Can be obtained from your Organization's setting page | -|
49+
| `timeout-minutes` | Number of minutes to wait for Shipyard environment before timing out. | 60|
50+
51+
52+
**Environment Variables**
53+
```
54+
- name: Fetch Shipyard Tokens
55+
uses: shipyard/github-action/fetch-shipyard-env@1.0.0
56+
env:
57+
SHIPYARD_API_TOKEN: ${{ secrets.SHIPYARD_API_TOKEN }}
58+
SHIPYARD_TIMEOUT: 30
59+
```
60+
61+
| Environment Variable | Description | Default Value |
62+
| --------------- | --------------- |--------------- |
63+
| `SHIPYARD_API_TOKEN` | Token required to connect to Shipyard's APIs. Can be obtained from your Organization's setting page |-|
64+
| `SHIPYARD_TIMEOUT` | Number of minutes to wait for Shipyard environment before timing out. |60|
65+
66+
**NOTE**: Inputs are given precedence over environment variables.
67+
68+
If input `api-token` or environment variable `SHIPYARD_API_TOKEN` is not provided, error is raised.
69+
70+
On successful run, the following environment variables are set, which can then be passed on to other actions in the same workflow.
71+
72+
| Parameter Name | Description |
73+
| --------------- | --------------- |
74+
|`SHIPYARD_ENVIRONMENT_URL` | URL of the ephemeral environment |
75+
|`SHIPYARD_BYPASS_TOKEN` | Token to bypass authentication |
76+
77+
78+
## Resources
79+
80+
[Shipyard Documentation](https://docs.shipyard.build/docs/)

fetch-shipyard-env/action.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Shipyard
2+
description: Use the Github Action to run jobs on Staging Environments automatically deployed by Shipyard.
3+
inputs:
4+
api-token:
5+
description: Shipyard API token used to fetch necessary environment variables from Shipyard.
6+
required: true
7+
timeout-minutes:
8+
description: Number of minutes to wait for Shipyard environment before timing out.
9+
required: false
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Install Python
15+
uses: actions/setup-python@v3
16+
with:
17+
python-version: '3.x'
18+
- name: Install Dependencies
19+
run: pip install -r $GITHUB_ACTION_PATH/../src/requirements.txt > /dev/null
20+
shell: bash
21+
# Pass inputs via shell until https://github.com/actions/runner/issues/665 resolved
22+
- name: Pass Inputs to Shell
23+
run: |
24+
echo "INPUT_API_TOKEN=${{ inputs.api-token }}" >> $GITHUB_ENV
25+
echo "INPUT_TIMEOUT_MINUTES=${{ inputs.timeout-minutes }}" >> $GITHUB_ENV
26+
shell: bash
27+
- name: Fetch the Shipyard environment variables
28+
run: python $GITHUB_ACTION_PATH/../src/fetch_shipyard_env.py
29+
shell: bash
30+
branding:
31+
icon: git-pull-request
32+
color: blue

0 commit comments

Comments
 (0)