#34 Изменение frontend.yml для тестов CI/CD #12
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Frontend CI/CD | |
on: | |
pull_request: | |
branches: | |
- frontend | |
types: | |
- opened | |
- synchronize | |
workflow_dispatch: | |
pull_request_target: | |
types: | |
- closed | |
jobs: | |
build-and-analyze: | |
if: github.event.pull_request.merged != true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '18' | |
- name: Cache Node.js dependencies | |
uses: actions/cache@v4 | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: Install dependencies | |
run: | | |
cd frontend | |
npm install | |
- name: Build frontend | |
run: | | |
cd frontend | |
npm run build | |
- name: Upload frontend build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-dist | |
path: frontend/dist/ | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache SonarQube packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: Analyze with SonarQube | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | |
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }} | |
run: | | |
cd frontend | |
npx sonar-scanner -Dsonar.projectKey=$SONAR_PROJECT_KEY -Dsonar.projectName='lenka-messenger' -Dsonar.sources=src -Dsonar.pullrequest.key=${{ github.event.number}} -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -Dsonar.scm.revision=${{ github.event.pull_request.head.sha }} -Dsonar.host.url=$SONAR_HOST_URL | |
deploy-to-dockerhub: | |
if: github.event.pull_request.merged == true && github.event.pull_request.head.ref == 'frontend' | |
runs-on: ubuntu-latest | |
needs: build-and-analyze | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Download frontend build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: frontend-dist | |
path: /frontend/dist | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push frontend image | |
run: | | |
cd frontend | |
docker build -t nickpominov/lm-frontend:latest . | |
docker push nickpominov/lm-frontend:latest |