From b7b7fe720c53a3b2c096ad3fcabdb5fc5d160eb8 Mon Sep 17 00:00:00 2001 From: itsscb Date: Fri, 6 Sep 2024 14:36:38 +0200 Subject: [PATCH 1/7] Update prod.yml --- .github/workflows/prod.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 6be93c4..420e081 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -54,8 +54,8 @@ jobs: - name: install tailwindcss run: npm install -g tailwindcss - - name: list frontend dir (pre build) [DEBUG] - run: ls -la ./frontend/dist + # - name: list frontend dir (pre build) [DEBUG] + # run: ls -la ./frontend/dist - name: build frontend working-directory: ./frontend/ From ce10b72e44356594b8811cc2987e65df1e6c2689 Mon Sep 17 00:00:00 2001 From: itsscb Date: Fri, 6 Sep 2024 14:46:05 +0200 Subject: [PATCH 2/7] Update prod.yml --- .github/workflows/prod.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml index 420e081..6bf0327 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/prod.yml @@ -18,7 +18,10 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: nightly + + - name: add rust target wasm32-unknown-unknown + run: rustup target add wasm32-unknown-unknown - name: cache trunk uses: actions/cache@v4 @@ -39,9 +42,6 @@ jobs: node_modules/ key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo-wordl - - - name: add rust target wasm32-unknown-unknown - run: rustup target add wasm32-unknown-unknown - name: install trunk run: cargo install trunk @@ -54,9 +54,6 @@ jobs: - name: install tailwindcss run: npm install -g tailwindcss - # - name: list frontend dir (pre build) [DEBUG] - # run: ls -la ./frontend/dist - - name: build frontend working-directory: ./frontend/ run: | @@ -97,6 +94,6 @@ jobs: - uses: shuttle-hq/deploy-action@main with: - # allow-dirty: "true" + allow-dirty: "true" deploy-key: ${{ secrets.SHUTTLE_API_KEY }} working-directory: . From 2ec00fd57329ac7bcac985df93c4a8354ca2aab5 Mon Sep 17 00:00:00 2001 From: itsscb Date: Fri, 6 Sep 2024 14:46:29 +0200 Subject: [PATCH 3/7] Update .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9fcc62e..39a0e04 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ debug/ target/ frontend/target/ -frontend/dist/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html From 75a8f830ebccabeae48be73bac959185eda08b17 Mon Sep 17 00:00:00 2001 From: itsscb Date: Sat, 7 Sep 2024 00:50:21 +0200 Subject: [PATCH 4/7] feat(workflow): refactor that shuttle deploy works without dirty (#34) * feat(workflow): refactor that shuttle deploy works without dirty * ref(workflow): packages whole project for deployment * fix(workflow): ignore failed read on packaging * fix(workflow): package whole dir instead of zipping it * fix(workflow): fix invalid artifact name in job deploy --- .github/workflows/{prod.yml => deploy.yml} | 90 ++++++++++++++-------- .github/workflows/test.yml | 41 ++++++++++ .gitignore | 7 ++ frontend/package-lock.json | 12 +-- frontend/package.json | 3 +- 5 files changed, 115 insertions(+), 38 deletions(-) rename .github/workflows/{prod.yml => deploy.yml} (52%) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/prod.yml b/.github/workflows/deploy.yml similarity index 52% rename from .github/workflows/prod.yml rename to .github/workflows/deploy.yml index 6bf0327..d97ec31 100644 --- a/.github/workflows/prod.yml +++ b/.github/workflows/deploy.yml @@ -14,6 +14,21 @@ jobs: - name: checkout uses: actions/checkout@v4 + - name: cache dependencies + uses: actions/cache@v4 + with: + path: | + ~/.rustup/ + ~/.cargo/registry/ + ~/.cargo/bin/ + ~/.cache/trunk/ + frontend/target/ + frontend/node_modules/ + target/ + node_modules/ + key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock', '~/.cargo/bin/trunk', '**/rust-toolchain.toml', '**/rust-toolchain') }} + restore-keys: ${{ runner.os }}-cargo-wordl + - name: install rust uses: actions-rs/toolchain@v1 with: @@ -22,29 +37,23 @@ jobs: - name: add rust target wasm32-unknown-unknown run: rustup target add wasm32-unknown-unknown + + - name: run frontend tests + working-directory: ./frontend/ + run: | + cargo test - - name: cache trunk - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/trunk - ~/.cache/trunk/ - key: ${{ runner.os }}-cargo-${{ hashFiles('~/.cargo/bin/trunk') }} - restore-keys: ${{ runner.os }}-trunk + - name: run backend tests + working-directory: . + run: | + cargo test + + - name: install cargo-binstall + uses: cargo-bins/cargo-binstall@main - - name: cache dependencies - uses: actions/cache@v4 - with: - path: | - ~/.cargo/ - ~/.cargo/bin/ - target/ - node_modules/ - key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo-wordl - - name: install trunk - run: cargo install trunk + run: | + cargo binstall trunk --no-confirm - name: install node.js uses: actions/setup-node@v4 @@ -52,48 +61,65 @@ jobs: node-version: 20 - name: install tailwindcss - run: npm install -g tailwindcss + working-directory: ./frontend/ + run: | + npm i -D + + - name: create ./frontend/dist dir + run: mkdir -p ./frontend/dist - name: build frontend working-directory: ./frontend/ run: | + sed -i 's/tailwindcss/npx/' Trunk.toml + sed -i 's/command_arguments \= \[/command_arguments \= \[\"tailwindcss\",/' Trunk.toml + cat Trunk.toml + sed -i '/frontend\/public\/styles.css/s/^/#/' ../.gitignore trunk build --release - - name: list frontend dir (pre upload) [DEBUG] - run: ls -la ./frontend/dist - - name: upload frontend artifacts uses: actions/upload-artifact@v4 with: name: frontend-artifacts path: ./frontend/dist - - name: run tests - run: | - cargo test --verbose - deploy: runs-on: ubuntu-latest needs: build - steps: + steps: - name: checkout uses: actions/checkout@v4 + - name: setup git + run: | + git config user.name github-actions + git config user.email github-actions@github.com + - name: remove ./frontend/dist dir run: | rm -rf ./frontend/dist - + - name: download frontend artifacts uses: actions/download-artifact@v4 with: name: frontend-artifacts path: ./frontend/dist + + - name: remove items from .gitignore + run: | + sed -i '/frontend\/dist\//s/^/#/' .gitignore + sed -i '/frontend\/public\/styles.css/s/^/#/' .gitignore + + - name: commit frontend build + run: | + git add frontend/dist -f + git add .gitignore + git commit -m "[${{github.run_attempt }}] ${{github.event.pusher}} > ${{ github.repository }}@${{ github.event.head_commit}}" || echo "No changes to commit" - name: List downloaded artifacts - run: ls -la ./frontend/dist + run: ls -laR ./frontend/dist - uses: shuttle-hq/deploy-action@main with: - allow-dirty: "true" deploy-key: ${{ secrets.SHUTTLE_API_KEY }} working-directory: . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d1a0721 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,41 @@ +on: + pull_request: + branches: + - master + +permissions: + contents: write + issues: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + + - name: cache dependencies + uses: actions/cache@v4 + with: + path: | + ~/.rustup/ + ~/.cargo/registry/ + ~/.cargo/bin/ + ~/.cache/trunk/ + frontend/target/ + target/ + frontend/node_modules/ + node_modules/ + key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock', '~/.cargo/bin/trunk', '**/rust-toolchain.toml', '**/rust-toolchain') }} + restore-keys: ${{ runner.os }}-cargo-wordl + + - name: install rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + + - name: run frontend tests + working-directory: ./frontend/ + run: | + cargo test diff --git a/.gitignore b/.gitignore index 39a0e04..feb92c5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,13 @@ debug/ target/ frontend/target/ +frontend/dist/ + +frontend/public/styles.css + + +node_modules/ +frontend/node_modules/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 0ddb416..6f7197d 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1,11 +1,12 @@ { - "name": "wordl", + "name": "wordl-frontend", "lockfileVersion": 3, "requires": true, "packages": { "": { + "name": "wordl-frontend", "devDependencies": { - "tailwindcss": "^3.4.3" + "tailwindcss": "^3.4.10" } }, "node_modules/@alloc/quick-lru": { @@ -1176,10 +1177,11 @@ } }, "node_modules/tailwindcss": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.3.tgz", - "integrity": "sha512-U7sxQk/n397Bmx4JHbJx/iSOOv5G+II3f1kpLpY2QeUv5DcPdcTsYLlusZfq1NthHS1c1cZoyFmmkex1rzke0A==", + "version": "3.4.10", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.10.tgz", + "integrity": "sha512-KWZkVPm7yJRhdu4SRSl9d4AK2wM3a50UsvgHZO7xY77NQr2V+fIrEuoDGQcbvswWvFGbS2f6e+jC/6WJm1Dl0w==", "dev": true, + "license": "MIT", "dependencies": { "@alloc/quick-lru": "^5.2.0", "arg": "^5.0.2", diff --git a/frontend/package.json b/frontend/package.json index af38bdf..7a7b3cd 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,5 +1,6 @@ { + "name": "wordl-frontend", "devDependencies": { - "tailwindcss": "^3.4.3" + "tailwindcss": "^3.4.10" } } From c5338a596105b1e5f080d318c4b2e191a7c2bdb1 Mon Sep 17 00:00:00 2001 From: itsscb Date: Sat, 7 Sep 2024 00:53:54 +0200 Subject: [PATCH 5/7] fix(workflow): invalid files in cache key --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d97ec31..80f7d2c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,7 +26,7 @@ jobs: frontend/node_modules/ target/ node_modules/ - key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock', '~/.cargo/bin/trunk', '**/rust-toolchain.toml', '**/rust-toolchain') }} + key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock', '~/.cargo/bin/trunk', './frontend/package-lock.json') }} restore-keys: ${{ runner.os }}-cargo-wordl - name: install rust From 3cb5e208f9e0aa08283bc6e0ca8db8662fddffa4 Mon Sep 17 00:00:00 2001 From: itsscb Date: Sat, 7 Sep 2024 00:56:39 +0200 Subject: [PATCH 6/7] fix(workflow): cache key hash --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 80f7d2c..9cd1812 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,7 +26,7 @@ jobs: frontend/node_modules/ target/ node_modules/ - key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock', '~/.cargo/bin/trunk', './frontend/package-lock.json') }} + key: ${{ runner.os }}-cargo-${{ hashFiles('./Cargo.lock', './frontend/package-lock.json') }} restore-keys: ${{ runner.os }}-cargo-wordl - name: install rust From b4afc56682f1d9679886cea9667532be51118a63 Mon Sep 17 00:00:00 2001 From: itsscb Date: Sat, 7 Sep 2024 01:03:15 +0200 Subject: [PATCH 7/7] fix(workflow): cache not working (#35)