|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: ["main"] |
| 6 | + push: |
| 7 | + branches: ["main"] |
| 8 | + tags: ["*"] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + packages: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + compute-base-build-tag: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + image_tag: ${{ steps.out.outputs.tag }} |
| 20 | + steps: |
| 21 | + - name: Checkout Repository |
| 22 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 23 | + - name: Create Tag |
| 24 | + id: out |
| 25 | + run: echo "tag=${{ hashFiles('Dockerfile','rust-toolchain.toml') }}" >> "$GITHUB_OUTPUT" |
| 26 | + |
| 27 | + build-base: |
| 28 | + needs: compute-base-build-tag |
| 29 | + runs-on: ubuntu-latest |
| 30 | + env: |
| 31 | + CACHE_HIT: false |
| 32 | + IMAGE: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }} |
| 33 | + steps: |
| 34 | + - name: Checkout Repository |
| 35 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 36 | + - name: Log in to GitHub Container Registry |
| 37 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4 |
| 38 | + with: |
| 39 | + registry: ghcr.io |
| 40 | + username: ${{ github.actor }} |
| 41 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + - name: Pull Cached base Image |
| 43 | + run: | |
| 44 | + if docker manifest inspect "$IMAGE" > /dev/null 2>&1; then |
| 45 | + echo "CACHE_HIT=true" >> $GITHUB_ENV |
| 46 | + else |
| 47 | + echo "CACHE_HIT=false" >> $GITHUB_ENV |
| 48 | + fi |
| 49 | + - name: Set up Docker Buildx |
| 50 | + if: env.CACHE_HIT == 'false' |
| 51 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4 |
| 52 | + - name: Build and Push base Image (if not cached) |
| 53 | + if: env.CACHE_HIT == 'false' |
| 54 | + uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7 |
| 55 | + with: |
| 56 | + context: . |
| 57 | + file: Dockerfile |
| 58 | + target: base |
| 59 | + push: true |
| 60 | + tags: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }} |
| 61 | + |
| 62 | + fmt: |
| 63 | + needs: [compute-base-build-tag, build-base] |
| 64 | + runs-on: ubuntu-latest |
| 65 | + container: |
| 66 | + image: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }} |
| 67 | + concurrency: |
| 68 | + group: ${{ github.workflow }}-${{ github.ref }}-fmt |
| 69 | + cancel-in-progress: true |
| 70 | + steps: |
| 71 | + - name: Checkout Repository |
| 72 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 73 | + - name: Check formatting |
| 74 | + run: cargo fmt -- --check |
| 75 | + |
| 76 | + clippy: |
| 77 | + needs: [compute-base-build-tag, build-base] |
| 78 | + runs-on: ubuntu-latest |
| 79 | + container: |
| 80 | + image: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }} |
| 81 | + concurrency: |
| 82 | + group: ${{ github.workflow }}-${{ github.ref }}-clippy |
| 83 | + cancel-in-progress: true |
| 84 | + steps: |
| 85 | + - name: Checkout Repository |
| 86 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 87 | + - name: Cache Cargo Target Directory |
| 88 | + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5 |
| 89 | + with: |
| 90 | + path: target |
| 91 | + key: clippy-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-${{ hashFiles('**/Cargo.lock') }} |
| 92 | + restore-keys: | |
| 93 | + clippy-base-${{ needs.compute-base-build-tag.outputs.image_tag }}- |
| 94 | + - name: Clippy |
| 95 | + run: cargo clippy --all-targets -- -Dclippy::all -D warnings |
| 96 | + |
| 97 | + tests: |
| 98 | + needs: [compute-base-build-tag, build-base] |
| 99 | + runs-on: ubuntu-latest |
| 100 | + container: |
| 101 | + image: ghcr.io/${{ github.repository }}/base:${{ needs.compute-base-build-tag.outputs.image_tag }} |
| 102 | + concurrency: |
| 103 | + group: ${{ github.workflow }}-${{ github.ref }}-tests |
| 104 | + cancel-in-progress: true |
| 105 | + steps: |
| 106 | + - name: Checkout Repository |
| 107 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 108 | + - name: Cache Cargo Target Directory |
| 109 | + uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5 |
| 110 | + with: |
| 111 | + path: target |
| 112 | + key: tests-base-${{ needs.compute-base-build-tag.outputs.image_tag }}-${{ hashFiles('**/Cargo.lock') }} |
| 113 | + restore-keys: | |
| 114 | + tests-base-${{ needs.compute-base-build-tag.outputs.image_tag }}- |
| 115 | + - name: Run tests |
| 116 | + run: cargo test |
| 117 | + |
| 118 | + build-package: |
| 119 | + if: startsWith(github.ref, 'refs/tags/') |
| 120 | + needs: [fmt, clippy, tests] |
| 121 | + runs-on: ubuntu-latest |
| 122 | + concurrency: |
| 123 | + group: ${{ github.workflow }}-${{ github.ref }}-build-package |
| 124 | + cancel-in-progress: true |
| 125 | + steps: |
| 126 | + - name: Checkout Repository |
| 127 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 128 | + - name: Debian packaging |
| 129 | + env: |
| 130 | + PACKAGECLOUD_API_KEY: ${{ secrets.PACKAGECLOUD_API_KEY }} |
| 131 | + run: | |
| 132 | + chmod +x ./.github/scripts/make_debian.sh |
| 133 | + ./.github/scripts/make_debian.sh |
| 134 | +
|
| 135 | + build-image: |
| 136 | + if: startsWith(github.ref, 'refs/tags/') |
| 137 | + needs: [fmt, clippy, tests] |
| 138 | + runs-on: ubuntu-latest |
| 139 | + concurrency: |
| 140 | + group: ${{ github.workflow }}-${{ github.ref }}-build-image |
| 141 | + cancel-in-progress: true |
| 142 | + steps: |
| 143 | + - name: Checkout Repository |
| 144 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 145 | + - name: Log in to GitHub Container Registry |
| 146 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4 |
| 147 | + with: |
| 148 | + registry: ghcr.io |
| 149 | + username: ${{ github.actor }} |
| 150 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 151 | + - name: Set up Docker Buildx |
| 152 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4 |
| 153 | + - name: Build and Push base Image |
| 154 | + uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7 |
| 155 | + with: |
| 156 | + context: . |
| 157 | + file: Dockerfile |
| 158 | + target: runner |
| 159 | + push: true |
| 160 | + tags: ghcr.io/${{ github.repository }}/multi_buy_service:${{ github.ref_name }} |
0 commit comments