Yml frontend update (#3) #25
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: | |
push: | |
branches: | |
- main | |
- production | |
pull_request: | |
branches: | |
- main | |
- production | |
jobs: | |
# Gradnja frontenda | |
build-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: 04_DevOps_Deploying/primer/frontend/node_modules | |
key: ${{ runner.os }}-frontend-${{ hashFiles('04_DevOps_Deploying/primer/frontend/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-frontend- | |
- name: Install dependencies | |
run: | | |
cd 04_DevOps_Deploying/primer/frontend | |
npm ci | |
- name: Build application | |
run: | | |
cd 04_DevOps_Deploying/primer/frontend | |
npm run build | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-build | |
path: 04_DevOps_Deploying/primer/frontend/build/ | |
# Testiranje frontenda | |
test-frontend: | |
needs: build-frontend | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
- name: Cache node_modules | |
uses: actions/cache@v3 | |
with: | |
path: 04_DevOps_Deploying/primer/frontend/node_modules | |
key: ${{ runner.os }}-frontend-${{ hashFiles('04_DevOps_Deploying/primer/frontend/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-frontend- | |
- name: Install dependencies | |
run: | | |
cd 04_DevOps_Deploying/primer/frontend | |
npm install | |
- name: Run tests with coverage | |
run: | | |
cd 04_DevOps_Deploying/primer/frontend | |
npm run test:ci | |
- name: Upload coverage report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: frontend-coverage | |
path: 04_DevOps_Deploying/primer/frontend/coverage/ | |
# Gradnja Docker slike in nalaganje na Docker Hub - Development | |
dockerize-and-push-dev: | |
needs: test-frontend | |
runs-on: ubuntu-latest | |
environment: Development | |
if: github.ref == 'refs/heads/main' # Ensure this job only runs on the main branch | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Build Docker image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:dev ./04_DevOps_Deploying/primer/frontend | |
docker tag ${{ secrets.DOCKER_USERNAME }}/frontend:dev ${{ secrets.DOCKER_USERNAME }}/frontend:${{ github.sha }} | |
- name: Push Docker image to Docker Hub | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:dev | |
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:${{ github.sha }} | |
# Gradnja Docker slike in nalaganje na Docker Hub - Production | |
dockerize-and-push-prod: | |
needs: test-frontend | |
runs-on: ubuntu-latest | |
environment: | |
name: Production | |
if: github.ref == 'refs/heads/production' # Ensure this job only runs on the production branch | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Build Docker image | |
run: | | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:prod ./04_DevOps_Deploying/primer/frontend | |
docker tag ${{ secrets.DOCKER_USERNAME }}/frontend:prod ${{ secrets.DOCKER_USERNAME }}/frontend:${{ github.sha }} | |
- name: Push Docker image to Docker Hub | |
run: | | |
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:prod | |
docker push ${{ secrets.DOCKER_USERNAME }}/frontend:${{ github.sha }} | |
# Deploy na Firebase Hosting | |
deploy-to-firebase: | |
needs: test-frontend | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download build artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: frontend-build | |
path: 04_DevOps_Deploying/primer/frontend/build/ | |
- name: Setup Firebase CLI | |
run: | | |
cd 04_DevOps_Deploying/primer/frontend | |
npm install -g firebase-tools | |
- name: Deploy to Firebase Hosting | |
run: | | |
cd 04_DevOps_Deploying/primer/frontend | |
firebase deploy --only hosting --token ${{ secrets.FIREBASE_TOKEN }} | |
# Uvedba na GitHub Pages | |
deploy-pages: | |
needs: test-frontend | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Deploy to GitHub Pages | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: ./docs |