From 9e90920051fc52b87c5c1a280d2588b1e8f72dde Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 16:05:17 -0700 Subject: [PATCH 01/14] update linters and add sqlx query checking --- .github/workflows/linters.yml | 8 +++++-- .github/workflows/sqlx-updates.yml | 35 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/sqlx-updates.yml diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 338e7cd4..d3b53da1 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -43,9 +43,13 @@ jobs: components: clippy override: true + - name: "install sqlx cli" + run: "cargo install sqlx-cli" + + - name: "run database migrations" + run: "cargo sqlx migrate run" + - uses: actions-rs/clippy-check@v1 - env: - SQLX_OFFLINE: "true" with: token: ${{ secrets.GITHUB_TOKEN }} args: --all-features -- --forbid expect_used --forbid unwrap_used diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml new file mode 100644 index 00000000..9fb71c35 --- /dev/null +++ b/.github/workflows/sqlx-updates.yml @@ -0,0 +1,35 @@ +on: + pull_request: + + push: + branches: + - main + +name: "sqlx checks" + +jobs: + sqlx_check: + name: "sqlx check" + runs-on: ubuntu-latest + steps: + - name: "checkout repo" + uses: actions/checkout@v2 + + - name: "install rust" + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + + - name: "install sqlx-cli" + run: "cargo install sqlx-cli" + + - name: "save current sqlx-data.json" + run: "mv sqlx-data.json sqlx-data.json.old || touch sqlx-data.json.old" + + - name: "regenerate sqlx-data.json" + run: "cargo sqlx prepare" + + - name: "assert eq" + run: "diff -q sqlx-data.json sqlx-data.json.old" From d49474747ffe51cdbbe24e30f88692217836a67b Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 16:06:42 -0700 Subject: [PATCH 02/14] add branch this was pushed to --- .github/workflows/linters.yml | 1 + .github/workflows/sqlx-updates.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index d3b53da1..8bfc1157 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - gh-actions-fixes name: Linters diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index 9fb71c35..391e2265 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - gh-actions-fixes name: "sqlx checks" From 9c477eeb2244b975d2caf106010324d76fea5860 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 16:22:39 -0700 Subject: [PATCH 03/14] add postgres db --- .github/workflows/linters.yml | 19 +++++++++++++++++++ .github/workflows/sqlx-updates.yml | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 8bfc1157..95503ae6 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -32,6 +32,23 @@ jobs: clippy: name: Clippy runs-on: ubuntu-latest + + services: + postgres: + image: postgres:latest + env: + POSTGRES_DB: ferris_chat + POSTGRES_PASSWORD: ferris_chat + POSTGRES_PORT: 5432 + POSTGRES_USER: ferris_chat + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: "install ld" run: "sudo apt install lld -y" @@ -49,6 +66,8 @@ jobs: - name: "run database migrations" run: "cargo sqlx migrate run" + env: + - DATABASE_URL: "postgres://ferris_chat:ferris_chat@postgres:5432/ferris_chat" - uses: actions-rs/clippy-check@v1 with: diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index 391e2265..a71fa120 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -12,6 +12,23 @@ jobs: sqlx_check: name: "sqlx check" runs-on: ubuntu-latest + + services: + postgres: + image: postgres:latest + env: + POSTGRES_DB: ferris_chat + POSTGRES_PASSWORD: ferris_chat + POSTGRES_PORT: 5432 + POSTGRES_USER: ferris_chat + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: "checkout repo" uses: actions/checkout@v2 @@ -29,8 +46,15 @@ jobs: - name: "save current sqlx-data.json" run: "mv sqlx-data.json sqlx-data.json.old || touch sqlx-data.json.old" + - name: "migrate db" + run: "cargo sqlx migrate run" + env: + - DATABASE_URL: "postgres://ferris_chat:ferris_chat@postgres:5432/ferris_chat" + - name: "regenerate sqlx-data.json" run: "cargo sqlx prepare" + env: + - DATABASE_URL: "postgres://ferris_chat:ferris_chat@postgres:5432/ferris_chat" - name: "assert eq" run: "diff -q sqlx-data.json sqlx-data.json.old" From 41e2e0728591ea9b19ac49f14e446b983741a439 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 21:36:08 -0700 Subject: [PATCH 04/14] try fixing the postgres db --- .github/workflows/linters.yml | 13 ++++--------- .github/workflows/sqlx-updates.yml | 15 +++++---------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 95503ae6..4a064f29 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -35,14 +35,9 @@ jobs: services: postgres: - image: postgres:latest - env: - POSTGRES_DB: ferris_chat - POSTGRES_PASSWORD: ferris_chat - POSTGRES_PORT: 5432 - POSTGRES_USER: ferris_chat + image: "postgres:latest" ports: - - 5432:5432 + - "5432:5432" options: >- --health-cmd pg_isready --health-interval 10s @@ -65,9 +60,9 @@ jobs: run: "cargo install sqlx-cli" - name: "run database migrations" - run: "cargo sqlx migrate run" + run: "cargo sqlx database setup" env: - - DATABASE_URL: "postgres://ferris_chat:ferris_chat@postgres:5432/ferris_chat" + - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - uses: actions-rs/clippy-check@v1 with: diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index a71fa120..58f71b8c 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -15,14 +15,9 @@ jobs: services: postgres: - image: postgres:latest - env: - POSTGRES_DB: ferris_chat - POSTGRES_PASSWORD: ferris_chat - POSTGRES_PORT: 5432 - POSTGRES_USER: ferris_chat + image: "postgres:latest" ports: - - 5432:5432 + - "5432:5432" options: >- --health-cmd pg_isready --health-interval 10s @@ -47,14 +42,14 @@ jobs: run: "mv sqlx-data.json sqlx-data.json.old || touch sqlx-data.json.old" - name: "migrate db" - run: "cargo sqlx migrate run" + run: "cargo sqlx database setup" env: - - DATABASE_URL: "postgres://ferris_chat:ferris_chat@postgres:5432/ferris_chat" + - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - name: "regenerate sqlx-data.json" run: "cargo sqlx prepare" env: - - DATABASE_URL: "postgres://ferris_chat:ferris_chat@postgres:5432/ferris_chat" + - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - name: "assert eq" run: "diff -q sqlx-data.json sqlx-data.json.old" From 696da36126906ff5fd9dec7b83b6596221321e24 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 21:38:08 -0700 Subject: [PATCH 05/14] fix typo --- .github/workflows/linters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 4a064f29..9ed13b52 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -62,7 +62,7 @@ jobs: - name: "run database migrations" run: "cargo sqlx database setup" env: - - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - uses: actions-rs/clippy-check@v1 with: From fb369b841e8981a6f167dd4c388155a2d7cf2183 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 21:40:08 -0700 Subject: [PATCH 06/14] fix typos --- .github/workflows/sqlx-updates.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index 58f71b8c..4134544f 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -44,12 +44,12 @@ jobs: - name: "migrate db" run: "cargo sqlx database setup" env: - - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - name: "regenerate sqlx-data.json" run: "cargo sqlx prepare" env: - - DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - name: "assert eq" run: "diff -q sqlx-data.json sqlx-data.json.old" From d420d6a2c1578bf6457d9eae051c8f1e19bb7825 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 21:50:29 -0700 Subject: [PATCH 07/14] fix service is unhealthy error --- .github/workflows/linters.yml | 2 ++ .github/workflows/sqlx-updates.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 9ed13b52..1a1f321c 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -36,6 +36,8 @@ jobs: services: postgres: image: "postgres:latest" + env: + POSTGRES_PASSWORD: "postgres" ports: - "5432:5432" options: >- diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index 4134544f..374e7233 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -16,6 +16,8 @@ jobs: services: postgres: image: "postgres:latest" + env: + POSTGRES_PASSWORD: "postgres" ports: - "5432:5432" options: >- From 389f11befd30d8d8503b95b9a2476a0063415d35 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 22:23:45 -0700 Subject: [PATCH 08/14] remove .env in builds --- .github/workflows/linters.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 1a1f321c..209d1fd2 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -61,6 +61,9 @@ jobs: - name: "install sqlx cli" run: "cargo install sqlx-cli" + - name: "remove .env" + run: "rm -f .env" + - name: "run database migrations" run: "cargo sqlx database setup" env: From 91fd08451247304daa87e1b530baa3907a3263eb Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 22:35:15 -0700 Subject: [PATCH 09/14] move env key to where it needed to be --- .github/workflows/linters.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 209d1fd2..9e683984 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -61,9 +61,6 @@ jobs: - name: "install sqlx cli" run: "cargo install sqlx-cli" - - name: "remove .env" - run: "rm -f .env" - - name: "run database migrations" run: "cargo sqlx database setup" env: @@ -74,3 +71,5 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} args: --all-features -- --forbid expect_used --forbid unwrap_used name: Clippy Output + env: + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" From 15928626b9cad4b7c88aeabf29b0116be8c9d6ef Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 23:35:28 -0700 Subject: [PATCH 10/14] automatically update sqlx-data.json if not eq --- .github/workflows/sqlx-updates.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index 374e7233..e9182841 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -53,5 +53,5 @@ jobs: env: DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - - name: "assert eq" - run: "diff -q sqlx-data.json sqlx-data.json.old" + - name: "assert eq, update if not eq" + run: "diff -q sqlx-data.json sqlx-data.json.old || { git add sqlx-data.json; git commit -m \"automated sqlx-data.json update\"; }" From 4e7a3cb49813325d652fb9da1e0db14b9d8bf0f6 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Thu, 18 Nov 2021 23:58:17 -0700 Subject: [PATCH 11/14] fix capitalization and tell git who is updating the commit --- .github/workflows/sqlx-updates.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index e9182841..ee30bae4 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -6,11 +6,11 @@ on: - main - gh-actions-fixes -name: "sqlx checks" +name: "SQLx Checks" jobs: sqlx_check: - name: "sqlx check" + name: "SQLx Check" runs-on: ubuntu-latest services: @@ -54,4 +54,4 @@ jobs: DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - name: "assert eq, update if not eq" - run: "diff -q sqlx-data.json sqlx-data.json.old || { git add sqlx-data.json; git commit -m \"automated sqlx-data.json update\"; }" + run: "diff -q sqlx-data.json sqlx-data.json.old || { git config user.name github-actions; git config user.email github-actions@github.com; git add sqlx-data.json; git commit -m \"automated sqlx-data.json update\"; }" From 3492b0e492c5bdf3b5149679a1369aff16ce7346 Mon Sep 17 00:00:00 2001 From: 0/0 Date: Fri, 19 Nov 2021 00:04:02 -0700 Subject: [PATCH 12/14] cache rust assets it's not going to be great since the assets are linked to the rust version but it should help a bit --- .github/workflows/linters.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 9e683984..c3b289ac 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -66,6 +66,8 @@ jobs: env: DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" + - uses: Swatinem/rust-cache@v1 + - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} From 6ebc084d63fc76cbca8e3b9cef94f0485d75311a Mon Sep 17 00:00:00 2001 From: 0/0 Date: Fri, 19 Nov 2021 00:06:03 -0700 Subject: [PATCH 13/14] cache rust assets where possible --- .github/workflows/sqlx-updates.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sqlx-updates.yml b/.github/workflows/sqlx-updates.yml index ee30bae4..036a812d 100644 --- a/.github/workflows/sqlx-updates.yml +++ b/.github/workflows/sqlx-updates.yml @@ -36,6 +36,8 @@ jobs: profile: minimal toolchain: nightly override: true + + - uses: Swatinem/rust-cache@v1 - name: "install sqlx-cli" run: "cargo install sqlx-cli" From db0aadcd9dd980dd060d669a496aaa375656e1bd Mon Sep 17 00:00:00 2001 From: 0/0 Date: Fri, 19 Nov 2021 00:08:18 -0700 Subject: [PATCH 14/14] move asset caching before building sqlx --- .github/workflows/linters.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index c3b289ac..b1cb0f59 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -57,6 +57,8 @@ jobs: toolchain: nightly components: clippy override: true + + - uses: Swatinem/rust-cache@v1 - name: "install sqlx cli" run: "cargo install sqlx-cli" @@ -66,8 +68,6 @@ jobs: env: DATABASE_URL: "postgres://postgres:postgres@localhost:5432/ferris_chat" - - uses: Swatinem/rust-cache@v1 - - uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }}