Update publishProjectFactory.yml #47
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: Project Factory Service Test Builder | |
on: | |
push: | |
branches: | |
- "console" | |
- "master" | |
- "buildFixProjectFactory" | |
paths: | |
- 'health-services/project-factory/**' | |
pull_request: | |
branches: | |
- "console" | |
- "master" | |
- "buildFixProjectFactory" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetch all history for tags and branches | |
# Step 2: Set up environment variables with clean BRANCH_NAME | |
- name: Set up environment variables | |
id: env | |
run: | | |
echo "ACTION_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV | |
# Check if it's a pull request | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
BRANCH_NAME="${{ github.base_ref }}" | |
else | |
BRANCH_NAME="${GITHUB_REF#refs/heads/}" | |
fi | |
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | |
echo "COMMIT_ID=${GITHUB_SHA: -8}" >> $GITHUB_ENV | |
echo "Branch name is set to ${BRANCH_NAME}" | |
# Step 3: Build the service Docker image | |
- name: Build the service Docker image | |
id: docker_build | |
working-directory: ./health-services/project-factory | |
run: | | |
IMAGE_TAG=egovio/project-factory:${{ env.BRANCH_NAME }}-${{ env.COMMIT_ID }}-${{ env.ACTION_NUMBER }} | |
docker build . \ | |
--file Dockerfile \ | |
--tag $IMAGE_TAG | |
echo "::set-output name=image_name::$IMAGE_TAG" | |
echo "Service Docker image built successfully" | |
# Step 4: Build the database migration Docker image | |
- name: Build the DB migration Docker image | |
id: docker_db_build | |
working-directory: ./health-services/project-factory/migration | |
run: | | |
IMAGE_TAG=egovio/project-factory-db:${{ env.BRANCH_NAME }}-${{ env.ACTION_NUMBER }} | |
docker build . \ | |
--file Dockerfile \ | |
--tag $IMAGE_TAG | |
echo "::set-output name=db_image_name::$IMAGE_TAG" | |
echo "DB migration Docker image built successfully" | |
# Step 5: Login to Docker Hub and Push the service Docker image | |
- name: Login to Docker Hub and Push Docker Image | |
working-directory: ./health-services/project-factory | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
IMAGE_NAME: ${{ steps.docker_build.outputs.image_name }} | |
run: | | |
# Authenticate with Docker Hub | |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | |
# Push the image to Docker Hub | |
docker push $IMAGE_NAME | |
echo "Docker image pushed: $IMAGE_NAME" | |
# Step 6: Login to Docker Hub and Push the DB migration Docker image | |
- name: Login to Docker Hub and Push DB Migration Docker Image | |
working-directory: ./health-services/project-factory/migration | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
DB_IMAGE_NAME: ${{ steps.docker_db_build.outputs.db_image_name }} | |
run: | | |
# Authenticate with Docker Hub | |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | |
# Push the image to Docker Hub | |
docker push $DB_IMAGE_NAME | |
echo "DB migration Docker image pushed: $DB_IMAGE_NAME" | |
node_build: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- uses: actions/checkout@v3 | |
# Step 2: Set up Node.js environment | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: 20 | |
# Step 3: Install dependencies and build for production | |
- name: Install dependencies and build | |
working-directory: ./health-services/project-factory | |
run: | | |
yarn install | |
yarn build |