Skip to content

ED-4000 feat: Github actions instead of Jenkins-test-sonar-fix #4

ED-4000 feat: Github actions instead of Jenkins-test-sonar-fix

ED-4000 feat: Github actions instead of Jenkins-test-sonar-fix #4

name: Build and Upload Artifact
on:
push:
branches:
- "*" # Trigger on push to the "deploy" branch
pull_request:
branches:
- "*" # Trigger on pull request to the "deploy" branch
jobs:
build_and_deploy:
name: Build and Upload Artifact Job # Define the name of the job
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2 # Checkout the repository code
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18.20.2" # Set up Node.js version 18
- name: Customize dependencies
if: ${{ env.WL_Customization != null }} # Conditional step execution
run: |
git clone --recurse-submodules ${WL_Customization} sunbirded-portal # Clone repository with submodules
cp -r sunbirded-portal/images/ src/app/client/src/assets # Copy images to client assets
cp -r sunbirded-portal/resourceBundles/data/ src/app/resourcebundles/ # Copy resource bundle data
env:
WL_Customization: ${{ github.event.inputs.WL_Customization }} # Set environment variable WL_Customization
- name: Build and Create Docker Image
id: build_docker_image
run: |
commit_hash=$(git rev-parse --short HEAD) # Get commit hash
build_tag=$(echo "${{ github.ref }}" | rev | cut -d/ -f1 | rev)_${commit_hash}_${GITHUB_RUN_NUMBER} # Generate build tag
echo "build_tag=$build_tag" >> $GITHUB_ENV # Save build tag to environment variable
bash ./build.sh "${build_tag}" "${{ env.NODE_NAME }}" "test" true false "" # Run build script with parameters
env:
NODE_NAME: "18.20.2" # Set environment variable NODE_NAME
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# - name: Push Docker Image
# run: |
# docker tag my-app:${{ env.build_tag }} ${{ secrets.DOCKER_USERNAME }}/my-app:${{ env.build_tag }}
# docker push ${{ secrets.DOCKER_USERNAME }}/my-app:${{ env.build_tag }}
- name: Push Docker Image
uses: docker/build-push-action@v4
with:
context: .
# file: ./Dockerfile # Path to your Dockerfile
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/my-app:${{ env.build_tag }}
- name: Archive Artifacts
uses: actions/upload-artifact@v2
with:
name: metadata
path: metadata.json
- name: Archive CDN assets if required
if: ${{ github.event.inputs.buildCdnAssests == 'true' }} # Conditional step execution
run: |
rm -rf cdn_assets # Remove existing CDN assets directory
mkdir cdn_assets # Create CDN assets directory
cp -r src/app/dist-cdn/* cdn_assets/ # Copy CDN assets
zip -Jr cdn_assets.zip cdn_assets # Create zip file of CDN assets
echo "##vso[task.uploadfile]cdn_assets.zip" # Upload CDN assets zip file