From 8ae22b9f1709551d3f0c46c1deac1b2ae7778e8b Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Mon, 5 Jun 2023 10:20:58 -0400 Subject: [PATCH 01/16] wip gh action build --- .github/workflows/rust.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 07860e0..4d756d1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -18,11 +18,21 @@ jobs: path: target key: ${{ runner.os }}-rust-target - - run: sudo npm install -g sass - + - name: Install sass + run: sudo npm install -g sass + - name: Check run: cargo check --verbose --all-targets --locked - name: Run tests run: cargo test --verbose - name: Clippy run: cargo clippy --verbose --no-deps --all-targets --locked + - name: Build + run: cargo build --bin=server --release --locked --verbose + + - name: GH Release + uses: softprops/action-gh-release@v0.1.15 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + From 2c1c57108af7532fc1fbd0d9288e9452e8a5d9e4 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 09:53:37 -0700 Subject: [PATCH 02/16] Upload build artifact and release --- .github/workflows/rust.yml | 50 ++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4d756d1..08e6813 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -5,34 +5,64 @@ on: pull_request: jobs: - build: - + validate: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3.5.2 - + - name: Cache rust target files uses: actions/cache@v3.3.1 with: path: target key: ${{ runner.os }}-rust-target - - name: Install sass - run: sudo npm install -g sass - - name: Check run: cargo check --verbose --all-targets --locked - name: Run tests run: cargo test --verbose - name: Clippy run: cargo clippy --verbose --no-deps --all-targets --locked + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3.5.2 + + - name: Cache rust target files + uses: actions/cache@v3.3.1 + with: + path: target + key: ${{ runner.os }}-rust-target + + - name: Install sass + run: sudo npm install -g sass + - name: Build run: cargo build --bin=server --release --locked --verbose + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: build-output + path: | + target/production/server + public/ + if-no-files-found: error + + release: + runs-on: ubuntu-latest + needs: [validate, build] + if: startsWith(github.ref, 'refs/tags/') + steps: + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: build-output + - name: GH Release - uses: softprops/action-gh-release@v0.1.15 - if: startsWith(github.ref, 'refs/tags/') + uses: softprops/action-gh-release@v2 with: files: | - + target/production/server + public/ + generate_release_notes: true From e70117c063d9656418656676d2bbeeb1f470b860 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 09:55:55 -0700 Subject: [PATCH 03/16] Need sass for tests --- .github/workflows/rust.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 08e6813..03d806e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,6 +16,9 @@ jobs: path: target key: ${{ runner.os }}-rust-target + - name: Install sass + run: sudo npm install -g sass + - name: Check run: cargo check --verbose --all-targets --locked - name: Run tests From 263c5d6d37918a2687153d005dd53e960919276a Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 09:58:52 -0700 Subject: [PATCH 04/16] Only run on push, not pr --- .github/workflows/rust.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 03d806e..1fd6d74 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,7 +2,6 @@ name: Rust build, test and clippy on: push: - pull_request: jobs: validate: From 4ea85fbeb5ae0797497d4e63589f4b579e6e7137 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 10:03:01 -0700 Subject: [PATCH 05/16] Update cache action --- .github/workflows/rust.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1fd6d74..4e6afa5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,10 +10,16 @@ jobs: - uses: actions/checkout@v3.5.2 - name: Cache rust target files - uses: actions/cache@v3.3.1 + uses: actions/cache@v4 with: - path: target - key: ${{ runner.os }}-rust-target + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + save-always: true - name: Install sass run: sudo npm install -g sass @@ -31,10 +37,16 @@ jobs: - uses: actions/checkout@v3.5.2 - name: Cache rust target files - uses: actions/cache@v3.3.1 + uses: actions/cache@v4 with: - path: target - key: ${{ runner.os }}-rust-target + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + save-always: true - name: Install sass run: sudo npm install -g sass From 11df112844f663df56353ecdb5393912b5ebca9b Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 10:08:51 -0700 Subject: [PATCH 06/16] Update checkout action --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4e6afa5..4cb67bc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,7 +7,7 @@ jobs: validate: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.5.2 + - uses: actions/checkout@v4 - name: Cache rust target files uses: actions/cache@v4 @@ -34,7 +34,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3.5.2 + - uses: actions/checkout@v4 - name: Cache rust target files uses: actions/cache@v4 From 4d2d93b46708049c0d939078d6a17b2e963632a6 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 11:24:56 -0700 Subject: [PATCH 07/16] debug output of artifact --- .github/workflows/rust.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4cb67bc..13c070d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -73,6 +73,9 @@ jobs: with: name: build-output + - name: Display structure of downloaded files + run: ls -R + - name: GH Release uses: softprops/action-gh-release@v2 with: @@ -80,3 +83,4 @@ jobs: target/production/server public/ generate_release_notes: true + fail_on_unmatched_files: true From 12977c8af0e6cd245fcc6e75ea2a7b4f6f52e0ca Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 11:49:00 -0700 Subject: [PATCH 08/16] Concurrency group for build --- .github/workflows/rust.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 13c070d..8109d66 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,8 +1,12 @@ -name: Rust build, test and clippy +name: Rust Build on: push: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: validate: runs-on: ubuntu-latest From 0c58a1f81dd3b36a774545c723b73eff4bad68aa Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 11:52:53 -0700 Subject: [PATCH 09/16] Fix executable path --- .github/workflows/rust.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8109d66..a90c58c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -63,7 +63,7 @@ jobs: with: name: build-output path: | - target/production/server + target/release/server public/ if-no-files-found: error @@ -84,7 +84,7 @@ jobs: uses: softprops/action-gh-release@v2 with: files: | - target/production/server + target/release/server public/ generate_release_notes: true fail_on_unmatched_files: true From 6b8056a009ba9887066d8fff273684f93486804a Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 12:15:08 -0700 Subject: [PATCH 10/16] Maybe file globs for action action --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a90c58c..2e0fe26 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -85,6 +85,6 @@ jobs: with: files: | target/release/server - public/ + public/**/* generate_release_notes: true fail_on_unmatched_files: true From f9c2577458eda37a69925507085d22a3ebee63d2 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 12:58:15 -0700 Subject: [PATCH 11/16] Zip release artifact and serialize in one job --- .github/workflows/rust.yml | 58 ++++---------------------------------- 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2e0fe26..0e06cae 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -4,15 +4,14 @@ on: push: concurrency: - group: ${{ github.workflow }}-${{ github.ref }} + group: ${{ github.workflow }} cancel-in-progress: true jobs: - validate: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Cache rust target files uses: actions/cache@v4 with: @@ -24,67 +23,22 @@ jobs: target/ key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} save-always: true - - name: Install sass run: sudo npm install -g sass - - name: Check run: cargo check --verbose --all-targets --locked - name: Run tests run: cargo test --verbose - name: Clippy run: cargo clippy --verbose --no-deps --all-targets --locked - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Cache rust target files - uses: actions/cache@v4 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - save-always: true - - - name: Install sass - run: sudo npm install -g sass - - name: Build run: cargo build --bin=server --release --locked --verbose - - - name: Upload build artifact - uses: actions/upload-artifact@v4 - with: - name: build-output - path: | - target/release/server - public/ - if-no-files-found: error - - release: - runs-on: ubuntu-latest - needs: [validate, build] - if: startsWith(github.ref, 'refs/tags/') - steps: - - name: Download build artifact - uses: actions/download-artifact@v4 - with: - name: build-output - - - name: Display structure of downloaded files - run: ls -R - + - name: Zip archive + run: tar -cvzf kachiclash.tar.gz target/release/server public - name: GH Release uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') with: - files: | - target/release/server - public/**/* + files: kachiclash.tar.gz generate_release_notes: true fail_on_unmatched_files: true From 08216a5ad328c2dc8328bc78818d383909c987a8 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 13:05:55 -0700 Subject: [PATCH 12/16] Upload artifact only, no release --- .github/workflows/rust.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0e06cae..d313547 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -4,7 +4,7 @@ on: push: concurrency: - group: ${{ github.workflow }} + group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: @@ -33,12 +33,11 @@ jobs: run: cargo clippy --verbose --no-deps --all-targets --locked - name: Build run: cargo build --bin=server --release --locked --verbose - - name: Zip archive - run: tar -cvzf kachiclash.tar.gz target/release/server public - - name: GH Release - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') + - name: Upload build artifact + uses: actions/upload-artifact@v4 with: - files: kachiclash.tar.gz - generate_release_notes: true - fail_on_unmatched_files: true + name: build-output + path: | + target/release/server + public/ + if-no-files-found: error From fe132f7374d55c685bd5f66ab3df5af4d9e204e5 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 13:09:09 -0700 Subject: [PATCH 13/16] No need to do a separate cargo check build takes care of that --- .github/workflows/rust.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d313547..e5f250f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,10 +25,8 @@ jobs: save-always: true - name: Install sass run: sudo npm install -g sass - - name: Check - run: cargo check --verbose --all-targets --locked - name: Run tests - run: cargo test --verbose + run: cargo test --verbose --all-targets --locked - name: Clippy run: cargo clippy --verbose --no-deps --all-targets --locked - name: Build From 479d3dd89f7877020aab2fee6b521e64a2410a8a Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 13:44:50 -0700 Subject: [PATCH 14/16] Use -r to install from gh action artifact --- scripts/install.sh | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 6d13cd2..b047773 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -7,20 +7,34 @@ PUBLIC=$KC_HOME/public SERVER=$KC_HOME/server SERVICE=kachiclash -case $1 in ---beta) - PUBLIC=$KC_HOME/public-beta - SERVER=$KC_HOME/server-beta - SERVICE=kachiclash-beta - ;; -'') ;; -*) - echo "Unknown option: $1" - exit 3 - ;; -esac +while [[ $# -gt 0 ]]; do + case $1 in + --beta) + shift + PUBLIC=$KC_HOME/public-beta + SERVER=$KC_HOME/server-beta + SERVICE=kachiclash-beta + ;; + -r|--run) + GH_RUN_ID="$2" + shift + shift + ;; + *) + echo "Unknown option: $1" + exit 3 + ;; + esac +done -cargo build --bin=server --release --locked || exit +if $GH_RUN_ID; then + echo "Using artifact from GH Action run ID: $GH_RUN_ID" + gh run download $GH_RUN_ID -n build-output -d gh-artifact || exit + cd gh-artifact +else + echo "Building locally" + cargo build --bin=server --release --locked || exit +fi sudo rsync -rv public/ $PUBLIC sudo chown -R kachiclash:nogroup $PUBLIC @@ -32,3 +46,8 @@ sudo install -vb \ $SERVER sudo systemctl restart $SERVICE + +if $GH_RUN_ID; then + cd .. + rm -rf gh-artifact +fi From 42c900fd2f767f465b979036fe62b34414a50844 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 13:46:50 -0700 Subject: [PATCH 15/16] fix check --- scripts/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index b047773..088c140 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -27,7 +27,7 @@ while [[ $# -gt 0 ]]; do esac done -if $GH_RUN_ID; then +if [ -n "$GH_RUN_ID" ]; then echo "Using artifact from GH Action run ID: $GH_RUN_ID" gh run download $GH_RUN_ID -n build-output -d gh-artifact || exit cd gh-artifact @@ -47,7 +47,7 @@ sudo install -vb \ sudo systemctl restart $SERVICE -if $GH_RUN_ID; then +if [ -n "$GH_RUN_ID" ]; then cd .. rm -rf gh-artifact fi From 0bbb042b0a10a8ea9173954d131864e39493e968 Mon Sep 17 00:00:00 2001 From: Daniel Dickison Date: Sat, 28 Sep 2024 13:55:47 -0700 Subject: [PATCH 16/16] Fix gh run download args --- scripts/install.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 088c140..65fb18b 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -29,11 +29,12 @@ done if [ -n "$GH_RUN_ID" ]; then echo "Using artifact from GH Action run ID: $GH_RUN_ID" - gh run download $GH_RUN_ID -n build-output -d gh-artifact || exit - cd gh-artifact + mkdir -p var + gh run download $GH_RUN_ID --name build-output --dir var/build-output + cd var/build-output else echo "Building locally" - cargo build --bin=server --release --locked || exit + cargo build --bin=server --release --locked fi sudo rsync -rv public/ $PUBLIC @@ -49,5 +50,5 @@ sudo systemctl restart $SERVICE if [ -n "$GH_RUN_ID" ]; then cd .. - rm -rf gh-artifact + rm -rf build-output fi