Skip to content

Commit

Permalink
Merge pull request #11 from hatchboxio/deploy-sha
Browse files Browse the repository at this point in the history
Use GitHub SHA to deploy on Hatchbox v2
  • Loading branch information
excid3 committed Sep 15, 2023
2 parents 1b13550 + b38903a commit c504016
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 35 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### v2

* Drop Hatchbox Classic support
* Deploy using ${{ github.sha }} instead of latest branch commit
* Include response in GitHub Action outputs
* Raise error on failure

### v1

* Trigger deployments in Hatchbox.io and Hatchbox Classic
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
# Hatchbox Notify Deploy Action
# Hatchbox.io Deploy Action

Sending deployment notifications to Hatchbox.
Trigger Hatchbox.io app deployments.

For Hatchbox Classic users, see [v1]().

#### Inputs

Use these inputs to customise the action.

Input Name | Default | Required? | Description
------------ | ------------- | ------------ | -------------
deploy_key | N/A | Y | The Hatchbox project deploy key
classic | false | N | If Hatchbox Classic is used or not
branch | master | N | (Hatchbox Classic Only) The branch to be deployed
deploy_key | N/A | Y | Your Hatchbox.io app's Deploy Key.
sha | ${{ github.sha }} | N | The commit sha to deploy. Default's to the sha that triggered the GitHub Action.

## Usage

#### Deploy Key
Set HATCHBOX_DEPLOY_KEY to XYZ in your GitHub Secrets.
Set `HATCHBOX_DEPLOY_KEY` in your GitHub Secrets. You can find the Deploy Key in the URL on the App's Repository tab in Hatchbox.io.

**Hatchbox v2**
#### Example

You can find the "deploy key" in the URL on the App's Repository tab in Hatchbox v2. For example, it would show:
```yaml
# .github/workflows/deploy.yml
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: hatchboxio/github-hatchbox-deploy-action@v1
with:
deploy_key: ${{ secrets.HATCHBOX_DEPLOY_KEY }}
```
https://app.hatchbox.io/webhooks/deployments/XYZ?latest=true
```

## Hatchbox Classic

**Hatchbox Classic**

Expand All @@ -34,10 +48,12 @@ https://www.hatchbox.io/webhooks/github/push/XYZ
#### Example

```yaml
# .github/workflows/deploy.yml

on:
push:
branches:
- master
- main

jobs:
build:
Expand All @@ -47,5 +63,6 @@ jobs:
- uses: hatchboxio/github-hatchbox-deploy-action@v1
with:
deploy_key: ${{ secrets.HATCHBOX_DEPLOY_KEY }}
branch: main
```
classic: "true"
branch: "main"
```
22 changes: 10 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
name: 'Hatchbox Deploy Action'
description: 'Send deployment notifications to the Hatchbox API'
name: 'Hatchbox.io Deploy Action'
description: 'Send deployment notifications to the Hatchbox.io API'
branding:
icon: 'globe'
color: 'red'
inputs:
deploy_key:
description: 'The Hatchbox project deploy key'
description: 'Your Hatchbox.io app's Deploy Key.'
required: true
branch:
description: 'The branch that needs to be deployed'
sha:
description: 'The commit sha to be deployed.'
required: false
default: 'master'
classic:
description: 'If hatchbox classic is used'
required: false
default: 'false'
default: ${{ github.sha }}
outputs:
response:
description: "JSON response for the Hatchbox.io deployment"

runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.deploy_key }}
- ${{ inputs.branch }}
- ${{ inputs.classic }}
- ${{ inputs.sha }}
13 changes: 4 additions & 9 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#!/bin/sh -l

set -x
set -xe

if [[ $INPUT_CLASSIC == "true" ]]; then
url="https://classic.hatchbox.io/webhooks/custom/push/$INPUT_DEPLOY_KEY?ref=refs%2Fheads%2F$INPUT_BRANCH"
else
url="https://app.hatchbox.io/webhooks/deployments/$INPUT_DEPLOY_KEY?latest=true"
fi

curl -X POST --fail $url
echo "Success"
response=curl -X POST --fail-with-body "https://app.hatchbox.io/webhooks/deployments/$INPUT_DEPLOY_KEY?sha=$INPUT_SHA"
echo "response=$response" >> $GITHUB_OUTPUT
echo "Deployment has started on Hatchbox.io"

0 comments on commit c504016

Please sign in to comment.