This commit is contained in:
kittapath-Jool 2025-10-12 13:42:09 +07:00
parent ff547470b2
commit 8766eb3b1f
2 changed files with 114 additions and 97 deletions

View file

@ -1,106 +1,106 @@
name: release name: release
run-name: release ${{ github.actor }} run-name: release ${{ github.actor }}
on: on:
push: push:
tags: tags:
- "version-[0-9]+.[0-9]+.[0-9]+" - "version-[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch: workflow_dispatch:
env: env:
REGISTRY: docker.frappet.com REGISTRY: docker.frappet.com
IMAGE_NAME: ehr/bma-ehr-recruit-service IMAGE_NAME: ehr/bma-ehr-recruit-service
DEPLOY_HOST: frappet.com DEPLOY_HOST: frappet.com
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-recruit COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-recruit
jobs: jobs:
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357 # act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# skip Set up QEMU because it fail on act and container # skip Set up QEMU because it fail on act and container
# Gen Version try to get version from tag or inut # Gen Version try to get version from tag or inut
- name: Set output tags - name: Set output tags
id: vars id: vars
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
- name: Gen Version - name: Gen Version
id: gen_ver id: gen_ver
run: | run: |
if [[ $GITHUB_REF == 'refs/tags/'* ]]; then if [[ $GITHUB_REF == 'refs/tags/'* ]]; then
IMAGE_VER=${{ steps.vars.outputs.tag }} IMAGE_VER=${{ steps.vars.outputs.tag }}
else else
IMAGE_VER=${{ github.event.inputs.IMAGE_VER }} IMAGE_VER=${{ github.event.inputs.IMAGE_VER }}
fi fi
if [[ $IMAGE_VER == '' ]]; then if [[ $IMAGE_VER == '' ]]; then
IMAGE_VER='test-vBeta' IMAGE_VER='test-vBeta'
fi fi
echo '::set-output name=image_ver::'$IMAGE_VER echo '::set-output name=image_ver::'$IMAGE_VER
- name: Check Version - name: Check Version
run: | run: |
echo $GITHUB_REF echo $GITHUB_REF
echo ${{ steps.gen_ver.outputs.image_ver }} echo ${{ steps.gen_ver.outputs.image_ver }}
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
- name: Login in to registry - name: Login in to registry
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
registry: ${{env.REGISTRY}} registry: ${{env.REGISTRY}}
username: ${{secrets.DOCKER_USER}} username: ${{secrets.DOCKER_USER}}
password: ${{secrets.DOCKER_PASS}} password: ${{secrets.DOCKER_PASS}}
- name: Build and push docker image - name: Build and push docker image
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
context: . context: .
platforms: linux/amd64 platforms: linux/amd64
push: true push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Reload docker compose - name: Reload docker compose
uses: appleboy/ssh-action@v0.1.8 uses: appleboy/ssh-action@v0.1.8
with: with:
host: ${{env.DEPLOY_HOST}} host: ${{env.DEPLOY_HOST}}
username: frappet username: frappet
password: ${{ secrets.SSH_PASSWORD }} password: ${{ secrets.SSH_PASSWORD }}
port: 10102 port: 10102
script: | script: |
cd "${{env.COMPOSE_PATH}}" cd "${{env.COMPOSE_PATH}}"
docker compose pull docker compose pull
docker compose up -d docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- name: Notify Discord Success # - name: Notify Discord Success
if: success() # if: success()
run: | # run: |
curl -H "Content-Type: application/json" \ # curl -H "Content-Type: application/json" \
-X POST \ # -X POST \
-d '{ # -d '{
"embeds": [{ # "embeds": [{
"title": "✅ Deployment Success!", # "title": "✅ Deployment Success!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`", # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
"color": 3066993, # "color": 3066993,
"footer": { # "footer": {
"text": "Release Notification", # "text": "Release Notification",
"icon_url": "https://example.com/success-icon.png" # "icon_url": "https://example.com/success-icon.png"
}, # },
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" # "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}] # }]
}' \ # }' \
${{ secrets.DISCORD_WEBHOOK }} # ${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Discord Failure # - name: Notify Discord Failure
if: failure() # if: failure()
run: | # run: |
curl -H "Content-Type: application/json" \ # curl -H "Content-Type: application/json" \
-X POST \ # -X POST \
-d '{ # -d '{
"embeds": [{ # "embeds": [{
"title": "❌ Deployment Failed!", # "title": "❌ Deployment Failed!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`", # "description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
"color": 15158332, # "color": 15158332,
"footer": { # "footer": {
"text": "Release Notification", # "text": "Release Notification",
"icon_url": "https://example.com/failure-icon.png" # "icon_url": "https://example.com/failure-icon.png"
}, # },
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" # "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}] # }]
}' \ # }' \
${{ secrets.DISCORD_WEBHOOK }} # ${{ secrets.DISCORD_WEBHOOK }}

View file

@ -183,19 +183,26 @@ namespace BMA.EHR.Recruit.Service.Services
// 🚀 Prepare HTTP client once // 🚀 Prepare HTTP client once
var httpClient1 = new HttpClient(); var httpClient1 = new HttpClient();
httpClient1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", "")); httpClient1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
Console.WriteLine("118");
httpClient1.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); httpClient1.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
Console.WriteLine("117");
var apiUrl1 = $"{_configuration["API"]}/api/v1/org/pos/level"; var apiUrl1 = $"{_configuration["API"]}/api/v1/org/pos/level";
Console.WriteLine("116");
var response1 = await httpClient1.GetStringAsync(apiUrl1); var response1 = await httpClient1.GetStringAsync(apiUrl1);
Console.WriteLine("115");
var posOptions = JsonConvert.DeserializeObject<RecruitPosRequest>(response1); var posOptions = JsonConvert.DeserializeObject<RecruitPosRequest>(response1);
Console.WriteLine("114");
var recruitImport = await _context.RecruitImports.AsQueryable() var recruitImport = await _context.RecruitImports.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == examId); .FirstOrDefaultAsync(x => x.Id == examId);
Console.WriteLine("113");
if (recruitImport == null) if (recruitImport == null)
throw new Exception(GlobalMessages.DataNotFound); throw new Exception(GlobalMessages.DataNotFound);
var _placement = await _contextMetadata.Placements.AsQueryable() var _placement = await _contextMetadata.Placements.AsQueryable()
.FirstOrDefaultAsync(x => x.PlacementType.Name == "สอบแข่งขัน" && x.RefId == recruitImport.Id); .FirstOrDefaultAsync(x => x.PlacementType.Name == "สอบแข่งขัน" && x.RefId == recruitImport.Id);
Console.WriteLine("112");
// if (_placement != null) // if (_placement != null)
// throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว"); // throw new Exception("รอบการสอบนี้ได้ทำการบรรจุไปแล้ว");
@ -205,6 +212,7 @@ namespace BMA.EHR.Recruit.Service.Services
var districtsCache = await _contextOrg.district.ToListAsync(); var districtsCache = await _contextOrg.district.ToListAsync();
var subDistrictsCache = await _contextOrg.subDistrict.ToListAsync(); var subDistrictsCache = await _contextOrg.subDistrict.ToListAsync();
var educationLevelsCache = await _contextOrg.educationLevel.ToListAsync(); var educationLevelsCache = await _contextOrg.educationLevel.ToListAsync();
Console.WriteLine("101");
var placement = new Placement var placement = new Placement
{ {
@ -224,6 +232,7 @@ namespace BMA.EHR.Recruit.Service.Services
LastUpdateFullName = FullName ?? "", LastUpdateFullName = FullName ?? "",
}; };
await _contextMetadata.Placements.AddAsync(placement); await _contextMetadata.Placements.AddAsync(placement);
Console.WriteLine("191");
// 🚀 Load all related data with single queries // 🚀 Load all related data with single queries
var candidates = await _context.Recruits.AsQueryable() var candidates = await _context.Recruits.AsQueryable()
@ -250,6 +259,7 @@ namespace BMA.EHR.Recruit.Service.Services
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", "")); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", ""));
httpClient.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); httpClient.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
Console.WriteLine("181");
// 🚀 Batch HTTP requests // 🚀 Batch HTTP requests
var orgTasks = candidates.Select(async candidate => var orgTasks = candidates.Select(async candidate =>
{ {
@ -267,6 +277,7 @@ namespace BMA.EHR.Recruit.Service.Services
return new { CitizenId = candidate.CitizenId ?? "", org = (dynamic?)null }; return new { CitizenId = candidate.CitizenId ?? "", org = (dynamic?)null };
} }
}).ToList(); }).ToList();
Console.WriteLine("171");
var orgResults = await Task.WhenAll(orgTasks); var orgResults = await Task.WhenAll(orgTasks);
var orgDict = orgResults.ToDictionary(x => x.CitizenId ?? "", x => x.org); var orgDict = orgResults.ToDictionary(x => x.CitizenId ?? "", x => x.org);
@ -275,6 +286,7 @@ namespace BMA.EHR.Recruit.Service.Services
var placementProfiles = new List<PlacementProfile>(); var placementProfiles = new List<PlacementProfile>();
var placementEducations = new List<PlacementEducation>(); var placementEducations = new List<PlacementEducation>();
var placementCertificates = new List<PlacementCertificate>(); var placementCertificates = new List<PlacementCertificate>();
Console.WriteLine("161");
foreach (var candidate in candidates) foreach (var candidate in candidates)
{ {
@ -433,12 +445,17 @@ namespace BMA.EHR.Recruit.Service.Services
LastUpdateFullName = FullName ?? "", LastUpdateFullName = FullName ?? "",
}; };
placementCertificates.Add(placementCertificate); placementCertificates.Add(placementCertificate);
Console.WriteLine("511");
} }
Console.WriteLine("141");
// 🚀 Batch insert all records // 🚀 Batch insert all records
await _contextMetadata.PlacementProfiles.AddRangeAsync(placementProfiles); await _contextMetadata.PlacementProfiles.AddRangeAsync(placementProfiles);
Console.WriteLine("131");
await _contextMetadata.PlacementEducations.AddRangeAsync(placementEducations); await _contextMetadata.PlacementEducations.AddRangeAsync(placementEducations);
Console.WriteLine("121");
await _contextMetadata.PlacementCertificates.AddRangeAsync(placementCertificates); await _contextMetadata.PlacementCertificates.AddRangeAsync(placementCertificates);
Console.WriteLine("111");
// 🚀 Single SaveChanges at the end // 🚀 Single SaveChanges at the end
await _contextMetadata.SaveChangesAsync(); await _contextMetadata.SaveChangesAsync();