Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install cargo-binstall as binary. Add --no-test and version options. #11

Merged
merged 6 commits into from Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions README.md
@@ -1,35 +1,41 @@
# Shuttle Deploy Action

This action automates the deployment of a rust project to [Shuttle](https://www.shuttle.rs/). This action builds the project and then deploys the result to Shuttle.
This action automates the deployment of a Rust project to [Shuttle](https://www.shuttle.rs/). This action deploys the project to Shuttle, which builds it and hosts it.

Note that you need to have created a project on Shuttle before you can deploy to it. This action will NOT create a new project for you.
You can see the documentation on how to create a project [here](https://docs.shuttle.rs/introduction/quick-start).

Shuttle Secrets are not handled by this action (yet). Add secrets using Secrets.toml with a manual deploy command. Read more about secrets [here](https://docs.shuttle.rs/resources/shuttle-secrets).

## Inputs

| Name | Description | Required | Default |
| --- | --- | --- | --- |
| deploy-key | The Shuttle API key | true | N/A |
| cargo-shuttle-version | Version of cargo-shuttle | false | `""` (latest) |
| working-directory | The directory which includes the `Cargo.toml` | false | `"."` |
| name | The directory which includes the `Cargo.toml` | false | `"."` |
| allow-dirty | Allow uncommitted changes to be deployed | false | `"false"` |
| no-test | Don't run tests before deployment | false | `"false"` |

## Outputs

| Name | Description |
| --- | --- |
| shuttle-url | The URL of the deployed project |
<!-- | shuttle-url | The URL of the deployed project | -->
oddgrd marked this conversation as resolved.
Show resolved Hide resolved

## Example usage

### Typical Example

```yaml
name: Shuttle deploy
name: Shuttle Deploy

on:
push:
branches:
- "main"
workflow_dispatch:

jobs:
deploy:
Expand All @@ -43,12 +49,13 @@ jobs:
### Example with all inputs

```yaml
name: Shuttle deploy
name: Shuttle Deploy

on:
push:
branches:
- "main"
workflow_dispatch:

jobs:
deploy:
Expand All @@ -57,6 +64,9 @@ jobs:
- uses: shuttle-hq/deploy-action@main
with:
deploy-key: ${{ secrets.SHUTTLE_DEPLOY_KEY }}
working-directory: "my-project"
working-directory: "backend"
name: "my-project"
allow-dirty: "true"
no-test: "true"
cargo-shuttle-version: "0.21.0"
```
57 changes: 38 additions & 19 deletions action.yml
@@ -1,43 +1,62 @@
name: ShuttleHQ deploy
description: "Deploy to shuttle"
name: Shuttle Deploy
description: Deploy to Shuttle

inputs:
deploy-key:
description: 'the key found at "https://www.shuttle.rs/login"'
description: 'The key found at "https://www.shuttle.rs/login"'
required: true
cargo-shuttle-version:
description: "Version of cargo-shuttle"
required: false
default: ""
working-directory:
description: "the directory which includes the `Cargo.toml`"
description: "The directory which includes the `Cargo.toml`"
required: false
default: "."
name:
description: "Name of the project (overrides crate name & Shuttle.toml)"
required: false
default: ""
allow-dirty:
description: "allow uncommitted changes to be deployed"
description: "Allow uncommitted changes to be deployed"
required: false
default: "false"
no-test:
description: "Don't run tests before deployment"
required: false
default: "false"

runs:
using: "composite"
steps:
# check out repo if not done already
- id: check-repo-is-not-initialized
run: echo "remote-url=$( git config --get remote.origin.url )" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/checkout@v3
if: ${{ !contains(steps.check-repo-is-not-initialized.outputs.remote-url, github.repository) }}
- name: Install shuttle cli
run: |
# using cargo-binstall because it is faster to get shuttle-cli binary
cargo install cargo-binstall
cargo binstall -y cargo-shuttle

# install with cargo-binstall
- name: Install cargo-binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
shell: bash
- name: Log into shuttle
run: cargo shuttle login --api-key ${{ inputs.deploy-key }}
- name: Install cargo-shuttle
if: ${{ inputs.cargo-shuttle-version == '' }}
run: cargo binstall -y --locked cargo-shuttle
shell: bash
- name: Deploy to shuttle
if: ${{ inputs.allow-dirty == 'false' }}
run: cargo shuttle deploy | awk '!/Database URI.*?$/'
working-directory: ${{ inputs.working-directory }}
- name: Install cargo-shuttle ${{ inputs.cargo-shuttle-version }}
if: ${{ inputs.cargo-shuttle-version != '' }}
run: cargo binstall -y --locked cargo-shuttle@${{ inputs.cargo-shuttle-version }}
shell: bash
- name: Deploy to shuttle
if: ${{ inputs.allow-dirty != 'false' }}
run: cargo shuttle deploy --allow-dirty | awk '!/Database URI.*?$/'

- name: Deploy to Shuttle
run: |
cargo shuttle deploy \
$(if [ "${{ inputs.name }}" != "" ]; then echo "--name ${{ inputs.name }}"; fi) \
$(if [ "${{ inputs.allow-dirty }}" != "false" ]; then echo --allow-dirty; fi) \
$(if [ "${{ inputs.no-test }}" != "false" ]; then echo --no-test; fi) \
| awk '!/Database URI.*?$/'
working-directory: ${{ inputs.working-directory }}
env:
SHUTTLE_API_KEY: ${{ inputs.deploy-key }}
shell: bash