From d3ff070210641746ff8f0d5f91455ef6950bf0c2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 15 Nov 2024 12:20:03 +0300 Subject: [PATCH 1/4] ci: add test workflow for GitHub Action (template workfrom from actions-rust-lang) --- .github/workflows/test.yaml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/test.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..1adac06 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,26 @@ +name: "Test Suite" +on: + push: + pull_request: + +jobs: + test: + name: cargo test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - run: cargo test --all-features + + # Check formatting with rustfmt + formatting: + name: cargo fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Ensure rustfmt is installed and setup problem matcher + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + - name: Rustfmt Check + uses: actions-rust-lang/rustfmt@v1 From 3f3b1aa6d70d2ff629eed23d5e80d6e25b5477b7 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 15 Nov 2024 12:44:55 +0300 Subject: [PATCH 2/4] ci: add building for all devices I have (that's supported by upstream Rust) --- .github/workflows/test.yaml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1adac06..e960ec1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,22 +5,36 @@ on: jobs: test: - name: cargo test runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 - - run: cargo test --all-features + - run: cargo t --all --all-features - # Check formatting with rustfmt formatting: - name: cargo fmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - # Ensure rustfmt is installed and setup problem matcher - uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: rustfmt - name: Rustfmt Check uses: actions-rust-lang/rustfmt@v1 + + compile: + runs-on: ubuntu-latest + needs: test + continue-on-error: true + strategy: + fail-fast: false + matrix: + include: + - target: aarch64-unknown-linux-gnu + - target: riscv64gc-unknown-linux-gnu + - target: x86_64-unknown-linux-gnu + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: ${{ matrix.target }} + - run: cargo b --all --release From 7c720bd8bc002f95d0d89060f4c6c729855ed94e Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 15 Nov 2024 14:37:47 +0300 Subject: [PATCH 3/4] ci: add clippy job --- .github/workflows/test.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e960ec1..1b3d61f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,9 +9,16 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 - - run: cargo t --all --all-features + - run: cargo t --workspace --all-features - formatting: + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + - run: cargo c --workspace --all-features + + rustfmt: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From e5c304826ad00fb6de9bbf75024e9df84ae9dedc Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Fri, 15 Nov 2024 13:14:37 +0300 Subject: [PATCH 4/4] ci: finally, add deploying to prereleases --- .github/workflows/test.yaml | 61 +++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1b3d61f..5400413 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,4 @@ -name: "Test Suite" +name: "test, compile and deploy" on: push: pull_request: @@ -28,7 +28,7 @@ jobs: - name: Rustfmt Check uses: actions-rust-lang/rustfmt@v1 - compile: + build: runs-on: ubuntu-latest needs: test continue-on-error: true @@ -37,11 +37,66 @@ jobs: matrix: include: - target: aarch64-unknown-linux-gnu + build-essential: crossbuild-essential-arm64 + cargoflags: --config=target.aarch64-unknown-linux-gnu.linker=\"aarch64-linux-gnu-gcc\" + cross: true - target: riscv64gc-unknown-linux-gnu + build-essential: crossbuild-essential-riscv64 + cargoflags: --config=target.riscv64gc-unknown-linux-gnu.linker=\"riscv64-linux-gnu-gcc\" + cross: true - target: x86_64-unknown-linux-gnu + cross: false steps: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: target: ${{ matrix.target }} - - run: cargo b --all --release + cache-key: compile-release-${{ matrix.target }} + - if: ${{ matrix.cross }} + run: sudo apt install ${{ matrix.build-essential }} + - run: cargo b --workspace --release --target=${{ matrix.target }} ${{ matrix.cargoflags }} + - run: | + mkdir -p staging/ artifacts/ + cp master/config/default.toml staging/config.toml + find target/${{ matrix.target }}/release -maxdepth 1 -type f -executable -exec cp {} staging/ ';' + pushd staging/ + tar --zstd -cvf ../artifacts/xash3d-master-${{ matrix.target }}.tar.zst * + popd + - uses: actions/upload-artifact@v4 + with: + name: artifact-${{ matrix.target }} + path: artifacts/* + + release: + runs-on: ubuntu-latest + needs: build + if: ${{ github.event_name == 'push' }} + steps: + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_TAG: ${{ github.ref_name == 'master' && 'continuous' || format('continuous-{0}', github.ref_name) }} + run: | + gh release delete "$RELEASE_TAG" \ + --yes \ + --cleanup-tag \ + --repo "$GITHUB_REPOSITORY" || true + sleep 20s + gh run download "$GITHUB_RUN_ID" \ + --dir artifacts/ \ + --repo "$GITHUB_REPOSITORY" + pushd artifacts/ + echo "Found artifacts:" + ls + for i in $(find -mindepth 1 -maxdepth 1 -type d); do + mv "$i"/* . + rm -rf "$i" + done + echo "Repackaged artifacts:" + ls -R + popd + sleep 20s + gh release create "$RELEASE_TAG" artifacts/* \ + --title "xash3d-master Continuous ${{ github.ref_name }} Build" \ + --target $GITHUB_SHA \ + --repo "$GITHUB_REPOSITORY" \ + --prerelease