|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + tags: |
| 11 | + - "v*" |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + packages: write |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + validate-helm: |
| 24 | + name: Validate Helm chart |
| 25 | + runs-on: ubuntu-latest |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Checkout repository |
| 29 | + uses: actions/checkout@v6 |
| 30 | + |
| 31 | + - name: Set up Helm |
| 32 | + uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4 |
| 33 | + |
| 34 | + - name: Lint chart |
| 35 | + run: helm lint deploy/helm/newsletter-maker |
| 36 | + |
| 37 | + - name: Render chart |
| 38 | + run: helm template newsletter-maker deploy/helm/newsletter-maker -f |
| 39 | + deploy/helm/newsletter-maker/values-minikube.yaml > |
| 40 | + /tmp/newsletter-maker-chart.yaml |
| 41 | + |
| 42 | + build-frontend: |
| 43 | + name: Build frontend |
| 44 | + runs-on: ubuntu-latest |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v6 |
| 49 | + |
| 50 | + - name: Set up Node.js |
| 51 | + uses: actions/setup-node@v6 |
| 52 | + with: |
| 53 | + node-version: "22" |
| 54 | + cache: npm |
| 55 | + cache-dependency-path: frontend/package-lock.json |
| 56 | + |
| 57 | + - name: Install frontend dependencies |
| 58 | + working-directory: frontend |
| 59 | + run: npm ci |
| 60 | + |
| 61 | + - name: Prepare frontend env |
| 62 | + working-directory: frontend |
| 63 | + run: | |
| 64 | + cp .env.example .env.local |
| 65 | + echo "NEXTAUTH_SECRET=ci-build-secret" >> .env.local |
| 66 | +
|
| 67 | + - name: Build frontend |
| 68 | + working-directory: frontend |
| 69 | + env: |
| 70 | + NEXT_PUBLIC_API_URL: http://localhost:8000 |
| 71 | + NEXTAUTH_URL: http://localhost:3000 |
| 72 | + NEXTAUTH_SECRET: ci-build-secret |
| 73 | + run: npm run build |
| 74 | + |
| 75 | + build-backend: |
| 76 | + name: Build and scan backend image |
| 77 | + runs-on: ubuntu-latest |
| 78 | + |
| 79 | + steps: |
| 80 | + - name: Checkout repository |
| 81 | + uses: actions/checkout@v6 |
| 82 | + |
| 83 | + - name: Build backend image |
| 84 | + env: |
| 85 | + DOCKER_BUILDKIT: "1" |
| 86 | + run: docker build -t newsletter-maker-ci:${{ github.sha }} -f |
| 87 | + docker/web/Dockerfile . |
| 88 | + |
| 89 | + - name: Scan backend image with Trivy |
| 90 | + uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0 |
| 91 | + with: |
| 92 | + image-ref: newsletter-maker-ci:${{ github.sha }} |
| 93 | + scan-type: image |
| 94 | + severity: HIGH,CRITICAL |
| 95 | + ignore-unfixed: true |
| 96 | + exit-code: "1" |
| 97 | + |
| 98 | + - name: Log in to GHCR |
| 99 | + if: github.event_name == 'push' |
| 100 | + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 |
| 101 | + with: |
| 102 | + registry: ghcr.io |
| 103 | + username: ${{ github.actor }} |
| 104 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + |
| 106 | + - name: Publish backend image |
| 107 | + if: github.event_name == 'push' |
| 108 | + env: |
| 109 | + IMAGE_REPOSITORY: ghcr.io/${{ github.repository_owner }}/newsletter-maker |
| 110 | + run: | |
| 111 | + set -euo pipefail |
| 112 | +
|
| 113 | + docker tag newsletter-maker-ci:${GITHUB_SHA} ${IMAGE_REPOSITORY}:${GITHUB_SHA} |
| 114 | + docker push ${IMAGE_REPOSITORY}:${GITHUB_SHA} |
| 115 | +
|
| 116 | + if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then |
| 117 | + docker tag newsletter-maker-ci:${GITHUB_SHA} ${IMAGE_REPOSITORY}:main |
| 118 | + docker push ${IMAGE_REPOSITORY}:main |
| 119 | + fi |
| 120 | +
|
| 121 | + if [[ "${GITHUB_REF}" == refs/tags/* ]]; then |
| 122 | + version_tag="${GITHUB_REF#refs/tags/}" |
| 123 | + docker tag newsletter-maker-ci:${GITHUB_SHA} ${IMAGE_REPOSITORY}:${version_tag} |
| 124 | + docker push ${IMAGE_REPOSITORY}:${version_tag} |
| 125 | + docker tag newsletter-maker-ci:${GITHUB_SHA} ${IMAGE_REPOSITORY}:latest |
| 126 | + docker push ${IMAGE_REPOSITORY}:latest |
| 127 | + fi |
0 commit comments