From 6e19d58caa4eb8846cc71d675581decbab10b004 Mon Sep 17 00:00:00 2001 From: Reuben Wong Date: Sun, 27 Aug 2023 23:10:29 +0800 Subject: [PATCH] Add emojis to runs (#6) * change tag matching * add emojis to templates * better render, revert official deploy * rerun sqlx prepare --- .github/actions/deploy-action/README.md | 77 ------------------ .github/actions/deploy-action/action.yml | 79 ------------------- .github/workflows/deploy.yml | 4 +- ...2cb88284e37e564c2436061b3825476dfb26.json} | 6 +- src/database.rs | 7 +- src/message.rs | 47 +++++++++-- templates/list_runs.j2 | 4 +- templates/list_tally.j2 | 16 +++- templates/list_users.j2 | 4 +- 9 files changed, 67 insertions(+), 177 deletions(-) delete mode 100644 .github/actions/deploy-action/README.md delete mode 100644 .github/actions/deploy-action/action.yml rename .sqlx/{query-f6e57469ae6306d7cc7ceeacdad3b3ee6876ebf4727a89badcd62ade36215e82.json => query-1bac28fd3f26ea49e82f22401dac2cb88284e37e564c2436061b3825476dfb26.json} (56%) diff --git a/.github/actions/deploy-action/README.md b/.github/actions/deploy-action/README.md deleted file mode 100644 index 77bce26..0000000 --- a/.github/actions/deploy-action/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# 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 | -| --- | --- | - - -## 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 }}' -``` diff --git a/.github/actions/deploy-action/action.yml b/.github/actions/deploy-action/action.yml deleted file mode 100644 index d1ff021..0000000 --- a/.github/actions/deploy-action/action.yml +++ /dev/null @@ -1,79 +0,0 @@ -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 \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c8f5a28..82513ab 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,14 +3,14 @@ name: Shuttle Deploy on: push: tags: - - "*" + - v[1-9]+.[0-9]+.[0-9]+ workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest steps: - - uses: ./.github/actions/deploy-action + - uses: shuttle-hq/deploy-action@main with: deploy-key: ${{ secrets.SHUTTLE_DEPLOY_KEY }} secrets: | diff --git a/.sqlx/query-f6e57469ae6306d7cc7ceeacdad3b3ee6876ebf4727a89badcd62ade36215e82.json b/.sqlx/query-1bac28fd3f26ea49e82f22401dac2cb88284e37e564c2436061b3825476dfb26.json similarity index 56% rename from .sqlx/query-f6e57469ae6306d7cc7ceeacdad3b3ee6876ebf4727a89badcd62ade36215e82.json rename to .sqlx/query-1bac28fd3f26ea49e82f22401dac2cb88284e37e564c2436061b3825476dfb26.json index 27c5aae..3e6eb78 100644 --- a/.sqlx/query-f6e57469ae6306d7cc7ceeacdad3b3ee6876ebf4727a89badcd62ade36215e82.json +++ b/.sqlx/query-1bac28fd3f26ea49e82f22401dac2cb88284e37e564c2436061b3825476dfb26.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT user_name, COUNT(*), SUM(distance)\n FROM runs\n JOIN users ON users.id = runs.user_id\n WHERE user_id = ANY($1)\n GROUP BY user_name", + "query": "SELECT user_name, COUNT(*), SUM(distance) as total_ran\n FROM runs\n JOIN users ON users.id = runs.user_id\n WHERE user_id = ANY($1)\n GROUP BY user_name\n ORDER BY total_ran DESC", "describe": { "columns": [ { @@ -15,7 +15,7 @@ }, { "ordinal": 2, - "name": "sum", + "name": "total_ran", "type_info": "Float4" } ], @@ -30,5 +30,5 @@ null ] }, - "hash": "f6e57469ae6306d7cc7ceeacdad3b3ee6876ebf4727a89badcd62ade36215e82" + "hash": "1bac28fd3f26ea49e82f22401dac2cb88284e37e564c2436061b3825476dfb26" } diff --git a/src/database.rs b/src/database.rs index 05b8122..c05498d 100644 --- a/src/database.rs +++ b/src/database.rs @@ -269,11 +269,12 @@ pub async fn get_tally(chat_id: ChatId, connection: &PgPool) -> DBResult = users.iter().map(|user| user.id).collect(); let tally = sqlx::query!( - "SELECT user_name, COUNT(*), SUM(distance) + "SELECT user_name, COUNT(*), SUM(distance) as total_ran FROM runs JOIN users ON users.id = runs.user_id WHERE user_id = ANY($1) - GROUP BY user_name", + GROUP BY user_name + ORDER BY total_ran DESC", &user_ids[..], ) .fetch_all(connection) @@ -284,7 +285,7 @@ pub async fn get_tally(chat_id: ChatId, connection: &PgPool) -> DBResult