|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master, develop] |
| 6 | + pull_request: |
| 7 | + branches: [main, master, develop] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Test and Lint |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + node-version: [20.x] |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Install pnpm |
| 23 | + uses: pnpm/action-setup@v4 |
| 24 | + with: |
| 25 | + version: 8 |
| 26 | + |
| 27 | + - name: Setup Node.js ${{ matrix.node-version }} |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: ${{ matrix.node-version }} |
| 31 | + cache: "pnpm" |
| 32 | + |
| 33 | + - name: Get pnpm store directory |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 37 | +
|
| 38 | + - name: Setup pnpm cache |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ${{ env.STORE_PATH }} |
| 42 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 43 | + restore-keys: | |
| 44 | + ${{ runner.os }}-pnpm-store- |
| 45 | +
|
| 46 | + - name: Install dependencies |
| 47 | + run: pnpm install --frozen-lockfile |
| 48 | + |
| 49 | + - name: Check formatting |
| 50 | + run: pnpm run format:check |
| 51 | + |
| 52 | + - name: Run linter |
| 53 | + run: pnpm run lint |
| 54 | + |
| 55 | + - name: Type check |
| 56 | + run: pnpm run check |
| 57 | + |
| 58 | + - name: Run tests |
| 59 | + run: pnpm run test |
| 60 | + env: |
| 61 | + NODE_ENV: test |
| 62 | + |
| 63 | + - name: Build project |
| 64 | + run: pnpm run build |
| 65 | + |
| 66 | + build: |
| 67 | + name: Build |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: test |
| 70 | + |
| 71 | + steps: |
| 72 | + - name: Checkout code |
| 73 | + uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: Install pnpm |
| 76 | + uses: pnpm/action-setup@v4 |
| 77 | + with: |
| 78 | + version: 8 |
| 79 | + |
| 80 | + - name: Setup Node.js |
| 81 | + uses: actions/setup-node@v4 |
| 82 | + with: |
| 83 | + node-version: 20.x |
| 84 | + cache: "pnpm" |
| 85 | + |
| 86 | + - name: Get pnpm store directory |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 90 | +
|
| 91 | + - name: Setup pnpm cache |
| 92 | + uses: actions/cache@v4 |
| 93 | + with: |
| 94 | + path: ${{ env.STORE_PATH }} |
| 95 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} |
| 96 | + restore-keys: | |
| 97 | + ${{ runner.os }}-pnpm-store- |
| 98 | +
|
| 99 | + - name: Install dependencies |
| 100 | + run: pnpm install --frozen-lockfile |
| 101 | + |
| 102 | + - name: Prepare for build |
| 103 | + run: pnpm run prebuild |
| 104 | + |
| 105 | + - name: Build for production |
| 106 | + run: pnpm run build:prod |
| 107 | + |
| 108 | + - name: Upload build artifacts |
| 109 | + uses: actions/upload-artifact@v4 |
| 110 | + with: |
| 111 | + name: dist |
| 112 | + path: dist/ |
| 113 | + retention-days: 7 |
| 114 | + |
| 115 | + docker: |
| 116 | + name: Docker build |
| 117 | + runs-on: ubuntu-latest |
| 118 | + needs: test |
| 119 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') |
| 120 | + steps: |
| 121 | + - name: Checkout code |
| 122 | + uses: actions/checkout@v4 |
| 123 | + |
| 124 | + - name: Set up Docker Buildx |
| 125 | + uses: docker/setup-buildx-action@v3 |
| 126 | + |
| 127 | + - name: Build Docker image |
| 128 | + uses: docker/build-push-action@v6 |
| 129 | + with: |
| 130 | + context: . |
| 131 | + push: false |
| 132 | + load: true |
| 133 | + tags: museum-management-rest-api:latest |
| 134 | + cache-from: type=gha |
| 135 | + cache-to: type=gha,mode=max |
0 commit comments