|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + |
| 6 | +env: |
| 7 | + RUST_TOOLCHAIN: '1.91' |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Build and Test |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Rust |
| 18 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 19 | + with: |
| 20 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 21 | + cache: true |
| 22 | + |
| 23 | + - name: Show versions |
| 24 | + run: rustc --version && cargo --version |
| 25 | + |
| 26 | + - name: Build |
| 27 | + run: cargo build |
| 28 | + |
| 29 | + - name: Run tests |
| 30 | + run: cargo test |
| 31 | + |
| 32 | + clippy: |
| 33 | + name: Clippy |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Setup Rust |
| 40 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 41 | + with: |
| 42 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 43 | + components: clippy |
| 44 | + cache: true |
| 45 | + |
| 46 | + - name: Run clippy |
| 47 | + run: cargo clippy --all-targets --all-features -- -D warnings |
| 48 | + |
| 49 | + fmt: |
| 50 | + name: Format Check |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - name: Checkout code |
| 54 | + uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Setup Rust |
| 57 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 58 | + with: |
| 59 | + toolchain: ${{ env.RUST_TOOLCHAIN }} |
| 60 | + components: rustfmt |
| 61 | + cache: true |
| 62 | + |
| 63 | + - name: Check formatting |
| 64 | + run: cargo fmt -- --check |
| 65 | + |
| 66 | + audit: |
| 67 | + name: Security Audit |
| 68 | + runs-on: ubuntu-latest |
| 69 | + steps: |
| 70 | + - name: Checkout code |
| 71 | + uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - name: Run cargo-audit |
| 74 | + uses: rustsec/audit-check@v2 |
| 75 | + with: |
| 76 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + |
| 78 | + docker-publish: |
| 79 | + name: Build and Publish Docker Image |
| 80 | + runs-on: ubuntu-latest |
| 81 | + needs: [test, clippy, fmt] |
| 82 | + if: github.ref == 'refs/heads/main' |
| 83 | + steps: |
| 84 | + - name: Checkout code |
| 85 | + uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Extract version from Cargo.toml |
| 88 | + id: version |
| 89 | + run: | |
| 90 | + VERSION=$(grep "^version =" Cargo.toml | sed 's/.*"\([^"]*\)".*/\1/') |
| 91 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 92 | + echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT |
| 93 | +
|
| 94 | + - name: Set up Docker Buildx |
| 95 | + uses: docker/setup-buildx-action@v3 |
| 96 | + |
| 97 | + - name: Login to Docker Hub |
| 98 | + uses: docker/login-action@v3 |
| 99 | + with: |
| 100 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 101 | + password: ${{ secrets.DOCKER_TOKEN }} |
| 102 | + |
| 103 | + - name: Build and push |
| 104 | + uses: docker/build-push-action@v5 |
| 105 | + with: |
| 106 | + context: . |
| 107 | + push: true |
| 108 | + no-cache: true |
| 109 | + tags: | |
| 110 | + dbrgn/xc-bot:${{ steps.version.outputs.branch }} |
| 111 | + dbrgn/xc-bot:${{ steps.version.outputs.version }} |
0 commit comments