Skip to content

8.0.0 GitHub action

8.0.0 GitHub action #5

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
docker build -t myapp:${build_tag} . # Build Docker image
env:
NODE_NAME: "18.20.2" # Set environment variable NODE_NAME
- name: Save Docker image as a file
run: |
docker save myapp:${{ env.build_tag }} -o myapp_${{ env.build_tag }}.tar # Save Docker image to a file
- name: Upload to Azure Blob Storage
if: env.AZURE_STORAGE_ACCOUNT
uses: azure/CLI@v1
with:
inlineScript: |
az storage blob upload \
--account-name $AZURE_STORAGE_ACCOUNT \
--container-name my-container \
--file myapp_${{ env.build_tag }}.tar \
--name myapp_${{ env.build_tag }}.tar > upload_result.txt
upload_status=$?
if [ $upload_status -ne 0 ]; then
echo "Azure Blob Storage upload failed."
cat upload_result.txt
exit 1
else
echo "Azure Blob Storage upload succeeded."
fi
env:
AZURE_STORAGE_ACCOUNT: ${{ secrets.AZURE_STORAGE_ACCOUNT }}
AZURE_STORAGE_KEY: ${{ secrets.AZURE_STORAGE_KEY }}
- name: Archive Artifacts
uses: actions/upload-artifact@v2
with:
name: metadata
path: myapp_${{ env.build_tag }}.tar