Skip to content

Commit 9d48e60

Browse files
authored
Enable Hoverfly to be installed (#22)
* Enable Hoverfly to be installed Prior to this commit the GitHub Action was just printing "Hello world". * Update README with Hoverfly info Prior to this commit the README still contained the content from the template Container Action[1] that this repo was generated from. Also added a `CONTRIBUTING.md` [1] https://github.com/actions/container-action/blob/main/README.md
1 parent 27bb9fb commit 9d48e60

File tree

4 files changed

+164
-9
lines changed

4 files changed

+164
-9
lines changed

CONTRIBUTING.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# How to contribute
2+
3+
Firstly thanks for thinking of contributing - the project is [open source](https://opensource.guide/how-to-contribute/) and all contributions are very welcome :slightly_smiling_face: :boom: :thumbsup:
4+
5+
## How to report a bug or suggest a new feature
6+
7+
[Create an issue](https://github.com/agilepathway/hoverfly-github-action/issues), describing the bug or new feature in as much detail as you can.
8+
9+
## How to make a contribution
10+
11+
* [Create an issue](https://github.com/agilepathway/hoverfly-github-action/issues) describing the change you are proposing.
12+
* [Create a pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests). The project uses the _[fork and pull model](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-collaborative-development-models)_:
13+
* [Fork the project](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/working-with-forks)
14+
* Make your changes on your fork
15+
* Write a [good commit message(s)](https://chris.beams.io/posts/git-commit/) for your changes
16+
* [Create the pull request for your changes](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/proposing-changes-to-your-work-with-pull-requests)

README.md

+107-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,109 @@
1-
# Container Action Template
1+
# Hoverfly GitHub Action
22

3-
To get started, click the `Use this template` button on this repository [which will create a new repository based on this template](https://github.blog/2019-06-06-generate-new-repositories-with-repository-templates/).
3+
[![reviewdog](https://github.com/agilepathway/hoverfly-github-action/workflows/reviewdog/badge.svg?branch=main&event=push)](https://github.com/agilepathway/hoverfly-github-action/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amain)
4+
[![License](https://img.shields.io/badge/license-MIT-blue.svg?maxAge=43200)](LICENSE)
45

5-
For info on how to build your first Container action, see the [toolkit docs folder](https://github.com/actions/toolkit/blob/master/docs/container-action.md).
6+
**[GitHub Action](https://github.com/features/actions) that installs [Hoverfly](https://docs.hoverfly.io/), so that it can be used in subsequent steps in your GitHub Actions CI/CD pipeline (e.g. when running tests that use Hoverfly).**
7+
8+
9+
## Using the Hoverfly action
10+
11+
Using this action is as simple as:
12+
13+
1. **create a `.github\workflows` directory** in your repository
14+
2. **create a
15+
[YAML](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#about-yaml-syntax-for-workflows)
16+
file** in the `.github\workflows` directory (file name can be anything you like,
17+
with either a `.yml` or `.yaml` file extension), with this content:
18+
19+
```
20+
---
21+
name: Hoverfly
22+
on:
23+
push:
24+
25+
jobs:
26+
27+
install-hoverfly:
28+
name: Install
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Install Hoverfly
32+
uses: agilepathway/hoverfly-github-action@main
33+
with:
34+
runner_github_workspace_path: ${{ github.workspace }}
35+
```
36+
37+
You will also typically have additional steps both before and after the Hoverfly installation step,
38+
e.g. to checkout your code and to run your tests. Here's an example:
39+
40+
```
41+
---
42+
name: Run tests
43+
on:
44+
push:
45+
46+
jobs:
47+
48+
run-tests:
49+
name: Install Hoverfly and run tests
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v2
54+
- name: Install Hoverfly
55+
uses: agilepathway/hoverfly-github-action@main
56+
with:
57+
runner_github_workspace_path: ${{ github.workspace }}
58+
- name: Run Tests
59+
run: <command-to-run-your-tests>
60+
```
61+
62+
Once the Hoverfly installation has completed, both the
63+
[Hoverfly](https://docs.hoverfly.io/en/latest/pages/reference/hoverfly/hoverflycommands.html) and
64+
[Hoverctl](https://docs.hoverfly.io/en/latest/pages/keyconcepts/hoverctl.html)
65+
commands are available to you for the remainder of your GitHub Actions workflow:
66+
- `hoverfly`
67+
- `hoverctl`
68+
69+
70+
## Specifying the Hoverfly version
71+
72+
Example:
73+
74+
```
75+
steps:
76+
- name: Install Hoverfly
77+
uses: agilepathway/hoverfly-github-action@main
78+
with:
79+
version: v1.3.0
80+
runner_github_workspace_path: ${{ github.workspace }}
81+
```
82+
83+
`version` can be any [released Hoverfly version](https://github.com/SpectoLabs/hoverfly/releases).
84+
If you do not provide a version, it will default to the
85+
[latest](https://github.com/SpectoLabs/hoverfly/releases/latest) release.
86+
87+
88+
## Runner GitHub Workspace path and Hoverfly installation location
89+
90+
As per the above examples, you have to provide the following parameter:
91+
92+
`runner_github_workspace_path: ${{ github.workspace }}`
93+
94+
The value must always be `${{ github.workspace }}`
95+
96+
This is so that the Hoverfly binaries are added to the path properly.
97+
98+
The Hoverfly binaries are installed at `${{ github.workspace }}/bin`
99+
100+
(The [GitHub workspace directory is persistent throughout the GitHub Action workflow](https://docs.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners), which means that the binaries are available to any subsequent workflow steps.)
101+
102+
103+
## Suggestions / bug reports / contributions
104+
105+
The project is [open source](https://opensource.guide/how-to-contribute/) and all contributions are very welcome :slightly_smiling_face: :boom: :thumbsup:
106+
107+
* [How to report a bug or suggest a new feature](CONTRIBUTING.md#how-to-report-a-bug-or-suggest-a-new-feature)
108+
109+
* [How to make a contribution](CONTRIBUTING.md#how-to-make-a-contribution)

action.yml

+14-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@ description: >
55
so that other GitHub Actions can use it easily (e.g. for testing)
66
author: 'John Boyes'
77
inputs:
8-
myInput:
9-
description: 'Input to use'
10-
default: 'world'
8+
version:
9+
description: >
10+
The Hoverfly version to install.
11+
Can be any released Hoverfly version:
12+
https://github.com/SpectoLabs/hoverfly/releases
13+
Defaults to the latest version.
14+
default: 'v1.3.0'
15+
required: false
16+
runner_github_workspace_path:
17+
description: >
18+
Always set this to be: `<dollarsign>{{ github.workspace}}`,
19+
replacing <dollarsign> with $
20+
required: true
1121
runs:
1222
using: 'docker'
1323
image: 'Dockerfile'
1424
args:
15-
- ${{ inputs.myInput }}
25+
- ${{ inputs.runner_github_workspace_path }}
1626
branding:
1727
icon: 'play'
1828
color: 'blue'

entrypoint.sh

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1-
#!/bin/sh -l
1+
#!/bin/sh
22

3-
echo "hello $1"
3+
export RUNNER_GITHUB_WORKSPACE_PATH=$1
4+
export RUNNER_HOVERFLY_INSTALL_PATH=$RUNNER_GITHUB_WORKSPACE_PATH/bin
5+
export CONTAINER_HOVERFLY_INSTALL_PATH=$GITHUB_WORKSPACE/bin
6+
export HOVERFLY_PLATFORM=linux_amd64
7+
export HOVERFLY_VERSION=$INPUT_VERSION
8+
export HOVERFLY_BUNDLE=hoverfly_bundle_$HOVERFLY_PLATFORM
9+
export HOVERFLY_DOWNLOAD_URL=https://github.com/SpectoLabs/hoverfly/releases/download/
10+
11+
mkdir -p "$CONTAINER_HOVERFLY_INSTALL_PATH"
12+
mkdir -p /tmp/hoverfly
13+
cd /tmp/hoverfly || exit
14+
15+
wget "$HOVERFLY_DOWNLOAD_URL$HOVERFLY_VERSION/$HOVERFLY_BUNDLE.zip"
16+
unzip $HOVERFLY_BUNDLE.zip
17+
install -m 755 hoverfly "$CONTAINER_HOVERFLY_INSTALL_PATH"
18+
install -m 755 hoverctl "$CONTAINER_HOVERFLY_INSTALL_PATH"
19+
20+
cd /tmp || exit
21+
rm -rf /tmp/hoverfly
22+
23+
echo "Installed hoverfly and hoverctl"
24+
25+
"$CONTAINER_HOVERFLY_INSTALL_PATH/hoverfly" -version
26+
"$CONTAINER_HOVERFLY_INSTALL_PATH/hoverctl" version
27+
28+
echo "::add-path::$RUNNER_HOVERFLY_INSTALL_PATH"

0 commit comments

Comments
 (0)