|
1 | | -name: Build & Deploy |
| 1 | +name: Build & Publish Docker Image |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
| 5 | + branches: |
| 6 | + - main |
5 | 7 | workflow_dispatch: |
6 | 8 |
|
7 | 9 | jobs: |
8 | | - build: |
| 10 | + build-and-push: |
9 | 11 | runs-on: ubuntu-latest |
10 | | - strategy: |
11 | | - matrix: |
12 | | - node-version: ['20'] |
13 | | - name: Build using Node v${{ matrix.node-version }} |
14 | 12 | steps: |
15 | | - - name: Checkout |
| 13 | + - name: Checkout repository |
16 | 14 | uses: actions/checkout@v4 |
17 | 15 |
|
18 | | - - name: Use Node.js ${{ matrix.node-version }} |
19 | | - uses: actions/setup-node@v4 |
| 16 | + - name: Log in to Docker Hub |
| 17 | + uses: docker/login-action@v3 |
20 | 18 | with: |
21 | | - node-version: ${{ matrix.node-version }} |
22 | | - cache: npm |
| 19 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 20 | + password: ${{ secrets.DOCKER_PASSWORD }} |
23 | 21 |
|
24 | | - - name: Install dependencies |
25 | | - run: npm install |
26 | | - |
27 | | - - name: Build project |
28 | | - run: npm run build |
29 | | - env: |
30 | | - CI: true |
31 | | - |
32 | | - - name: Upload build artifacts |
33 | | - uses: actions/upload-artifact@v4 |
34 | | - with: |
35 | | - name: dist |
36 | | - path: dist |
37 | | - retention-days: 1 # نگهداری فایلها برای ۱ روز |
38 | | - |
39 | | - deploy: |
40 | | - needs: build |
41 | | - runs-on: ubuntu-latest |
42 | | - steps: |
43 | | - - name: Checkout |
44 | | - uses: actions/checkout@v4 |
45 | | - |
46 | | - - name: Download build artifacts |
47 | | - uses: actions/download-artifact@v4 |
| 22 | + - name: Extract metadata for Docker |
| 23 | + id: meta |
| 24 | + uses: docker/metadata-action@v5 |
48 | 25 | with: |
49 | | - name: dist |
50 | | - path: dist |
| 26 | + images: pymmdrza/blockhub |
51 | 27 |
|
52 | | - - name: Deploy to GitHub Pages |
53 | | - uses: peaceiris/actions-gh-pages@v4 |
| 28 | + - name: Build and push Docker image |
| 29 | + uses: docker/build-push-action@v5 |
54 | 30 | with: |
55 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
56 | | - publish_dir: dist |
57 | | - branch: gh-pages |
| 31 | + context: . |
| 32 | + push: true |
| 33 | + tags: pymmdrza/blockhub:latest |
| 34 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments