Skip to content

Commit

Permalink
Only allow source users to update their own runs (#5)
Browse files Browse the repository at this point in the history
* refactor queries to require user_id from telegram

* regenerate sqlx meta
  • Loading branch information
reubenwong97 authored Aug 27, 2023
1 parent 164e170 commit 2339ef1
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 103 deletions.
77 changes: 77 additions & 0 deletions .github/actions/deploy-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Shuttle Deploy Action

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. This action is a clone of the official deployment action, but having a `keep-alive` flag on deploy.

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"` |
| secrets | Content of the `Secrets.toml` file, if any | false | `""` |
| keep-alive | Whether service should be kept alive. | false | `"true"` |

## Outputs

| Name | Description |
| --- | --- |
<!-- | shuttle-url | The URL of the deployed project | -->

## Example usage

### Typical Example

```yaml
name: Shuttle Deploy

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

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: shuttle-hq/deploy-action@main
with:
deploy-key: ${{ secrets.SHUTTLE_DEPLOY_KEY }}
```
### Example with all inputs
```yaml
name: Shuttle Deploy

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

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: shuttle-hq/deploy-action@main
with:
deploy-key: ${{ secrets.SHUTTLE_DEPLOY_KEY }}
working-directory: "backend"
name: "my-project"
allow-dirty: "true"
no-test: "true"
cargo-shuttle-version: "0.21.0"
secrets: |
MY_AWESOME_SECRET_1 = '${{ secrets.SECRET_1 }}'
MY_AWESOME_SECRET_2 = '${{ secrets.SECRET_2 }}'
```
79 changes: 79 additions & 0 deletions .github/actions/deploy-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Shuttle Deploy
description: Deploy to Shuttle

inputs:
deploy-key:
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`"
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"
required: false
default: "false"
no-test:
description: "Don't run tests before deployment"
required: false
default: "false"
secrets:
description: |
Content of the `Secrets.toml` file, if any.
Use multiline text with `|` in case of multiple secrets
required: false
default: ""
keep-alive:
description: Whether service should be kept alive.
required: false
default: "true"

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) }}

# 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: Install cargo-shuttle
if: ${{ inputs.cargo-shuttle-version == '' }}
run: cargo binstall -y --locked cargo-shuttle
shell: bash
- 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: Create secret file
if: ${{ inputs.secrets != '' }}
run: echo "${{ inputs.secrets }}" > Secrets.toml
working-directory: ${{ inputs.working-directory }}
shell: bash

- 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) \
$(if [ "${{ inputs.keep-alive }}" != "false" ]; then echo --idle-minutes 0; fi) \
| awk '!/Database URI.*?$/'
working-directory: ${{ inputs.working-directory }}
env:
SHUTTLE_API_KEY: ${{ inputs.deploy-key }}
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: shuttle-hq/deploy-action@main
- uses: ./.github/actions/deploy-action
with:
deploy-key: ${{ secrets.SHUTTLE_DEPLOY_KEY }}
secrets: |
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions migrations/20230826131114_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add migration script here
ALTER TABLE users
ADD COLUMN telegram_userid BIGINT NOT NULL DEFAULT 0;
ALTER TABLE users
ALTER COLUMN telegram_userid DROP DEFAULT;
Loading

0 comments on commit 2339ef1

Please sign in to comment.