From fe1796cfa7914400ac950a6ae9ee791c02cab699 Mon Sep 17 00:00:00 2001 From: En-En <39373446+En-En-Code@users.noreply.github.com> Date: Tue, 26 Aug 2025 01:37:08 +0000 Subject: [PATCH] ci: restore dependency-storing dockerfile --- .github/workflows/ci.yml | 90 ++++++++++++++++++++--------- .github/workflows/set-vars.sh | 23 ++++++++ .github/workflows/ubuntu.dockerfile | 9 +++ tests/integration.rs | 2 +- 4 files changed, 95 insertions(+), 29 deletions(-) create mode 100755 .github/workflows/set-vars.sh create mode 100644 .github/workflows/ubuntu.dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd81baf..6dcabfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,51 +3,85 @@ name: CI on: push: branches: [ "main" ] + tags: [ '*' ] + paths-ignore: [ '*.md' ] pull_request: branches: [ "main" ] env: CARGO_TERM_COLOR: always + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + UBUNTU_DOCKERFILE: .github/workflows/ubuntu.dockerfile + +permissions: + pull-requests: read + contents: read + packages: read jobs: - ci: + set-vars: runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 2 + sparse-checkout: | + .github + Cargo.toml + sparse-checkout-cone-mode: false + - id: set-vars + run: ./.github/workflows/set-vars.sh ${GITHUB_REPOSITORY@L} + outputs: + msrv: ${{ steps.set-vars.outputs.msrv }} + should-build: ${{ steps.set-vars.outputs.should_build == 'true' && github.event_name == 'push' }} + container-path: ${{ steps.set-vars.outputs.container_path }} + + container-build: + runs-on: ubuntu-latest + needs: set-vars + if: ${{ needs.set-vars.outputs.should-build == 'true' }} permissions: - contents: read - packages: read + packages: write + id-token: write steps: - - uses: actions/checkout@v4 - - name: Get MSRV - id: msrv - run: | - echo "msrv=$( - awk '/^rust-version = "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"$/ { - print substr($NF, 2, length($NF) - 2) - }' Cargo.toml)" >> "$GITHUB_OUTPUT" - - name: Set XDG_RUNTIME_DIR - id: xrd - run: echo "testdir=$PWD/test-xwls" >> "$GITHUB_OUTPUT" - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install -y xwayland clang libxcb1 libxcb-cursor0 libxcb-cursor-dev pkg-config libegl1 - env: - DEBIAN_FRONTEND: noninteractive + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v6 + with: + file: ${{ env.UBUNTU_DOCKERFILE }} + push: true + tags: ${{ needs.set-vars.outputs.container-path }}-ubuntu:latest + labels: org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + cache-from: type=gha + cache-to: type=gha,mode=max + + xwls-build-test: + needs: [container-build, set-vars] + if: ${{ always() && (needs.container-build.result == 'success' || needs.container-build.result == 'skipped') }} + runs-on: ubuntu-latest + container: + image: ${{ needs.set-vars.outputs.container-path }}-ubuntu:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v5 - uses: dtolnay/rust-toolchain@master with: - toolchain: ${{ steps.msrv.outputs.msrv }} + toolchain: ${{ needs.set-vars.outputs.msrv }} components: clippy, rustfmt - - uses: Swatinem/rust-cache@v2 - name: Build run: cargo build --all-targets --profile ci --locked --verbose - name: Run tests - run: | - mkdir "$XDG_RUNTIME_DIR" - cargo test --profile ci --locked --verbose -- --test-threads 1 --nocapture - env: - XDG_RUNTIME_DIR: ${{ steps.xrd.outputs.testdir }} + run: cargo test --profile ci --locked --verbose -- --test-threads 1 --nocapture - name: Format check run: cargo fmt --check - name: Clippy - run: cargo clippy --profile ci --locked --workspace --all-targets + run: cargo clippy --all-targets --profile ci --locked --workspace diff --git a/.github/workflows/set-vars.sh b/.github/workflows/set-vars.sh new file mode 100755 index 0000000..3db73aa --- /dev/null +++ b/.github/workflows/set-vars.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +msrv=$( + awk '/^rust-version = "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+"$/ { + print substr($NF, 2, length($NF) - 2) + }' Cargo.toml +) +if [ -z $msrv ]; then + printf "Could not determine Rust toolchain version\n" + exit 1 +fi + +git fetch --depth=1 origin +refs/tags/*:refs/tags/* +if ! git diff HEAD~1 --quiet -- "$UBUNTU_DOCKERFILE" || + git describe --candidates=0; then + should_build=true +else + should_build=false +fi + +echo "msrv=$msrv" >> "$GITHUB_OUTPUT" +echo "should_build=$should_build" >> "$GITHUB_OUTPUT" +echo "container_path=$REGISTRY/$1" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/ubuntu.dockerfile b/.github/workflows/ubuntu.dockerfile new file mode 100644 index 0000000..4484ed4 --- /dev/null +++ b/.github/workflows/ubuntu.dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:latest + +ARG DEBIAN_FRONTEND=noninteractive +ENV TZ=Etc/UTC +RUN apt-get update \ + && apt-get install -y xwayland libxcb1 clang libxcb-cursor0 libxcb-cursor-dev curl pkg-config libegl1 \ + && rm -r /var/lib/apt/lists/* +RUN mkdir /run/xwls-test +ENV XDG_RUNTIME_DIR="/run/xwls-test" diff --git a/tests/integration.rs b/tests/integration.rs index 41b6075..06af29c 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -131,7 +131,7 @@ impl Fixture { // wait for connection let fd = unsafe { BorrowedFd::borrow_raw(testwl.poll_fd().as_raw_fd()) }; let pollfd = PollFd::from_borrowed_fd(fd, PollFlags::IN); - assert!(poll(&mut [pollfd.clone()], -1).unwrap() > 0); + assert!(poll(&mut [pollfd.clone()], 1000).unwrap() > 0); testwl.dispatch(); let try_bool_timeout = |b: &AtomicBool| {