Package #265
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: Package | |
on: | |
workflow_dispatch: | |
inputs: | |
servicename: | |
description: 'Select service to build and deploy' | |
required: true | |
default: 'Aevatar.HttpApi.Host' | |
type: choice | |
options: | |
- Aevatar.Silo | |
- Aevatar.Developer.Host | |
env: | |
DOTNET_INSTALL_DIR: "./.dotnet" | |
concurrency: | |
group: workflow-${{ github.ref }} | |
cancel-in-progress: false | |
jobs: | |
publish: | |
runs-on: aismart-runner | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '9.0.x' | |
- name: Cache NuGet Packages | |
id: nuget-packages | |
uses: actions/cache@v4 | |
env: | |
cache-name: nuget-package-cache | |
with: | |
path: ~/.nuget/packages | |
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.event.inputs.servicename }} | |
- name: List NuGet Packages | |
if: ${{ steps.nuget-packages.outputs.cache-hit == 'true' }} | |
continue-on-error: true | |
run: ls -lh ~/.nuget/packages | |
- run: dotnet publish src/${{ github.event.inputs.servicename}}/${{ github.event.inputs.servicename }}.csproj -o out/${{ github.event.inputs.servicename }} | |
- name: Upload build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ github.event.inputs.servicename }} | |
path: out/${{ github.event.inputs.servicename }} | |
retention-days: 1 | |
build-and-push-image: | |
needs: publish | |
runs-on: aismart-runner | |
permissions: | |
contents: read | |
outputs: | |
short_sha: ${{ steps.vars.outputs.short_sha }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set short git commit SHA | |
id: vars | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
echo "short_sha=$calculatedSha" >> "$GITHUB_OUTPUT" | |
- name: Download a single artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ github.event.inputs.servicename }} | |
path: out/${{ github.event.inputs.servicename }} | |
- name: Create image tag | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ secrets.REPOSITORY_REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ secrets.REPOSITORY }}/${{ github.event.inputs.servicename }} | |
tags: | | |
type=sha | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
build-args: | | |
servicename=${{ github.event.inputs.servicename }} | |
platforms: linux/amd64 | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Determine hostType | |
id: determine_host_type | |
run: | | |
# Default hostType is undefined (-1), only set for specific applications | |
hostType="-1" | |
if [ "${{ github.event.inputs.servicename }}" = "Aevatar.Silo" ]; then | |
hostType="0" | |
elif [ "${{ github.event.inputs.servicename }}" = "Aevatar.Developer.Host" ]; then | |
hostType="1" | |
fi | |
echo "hostType=$hostType" >> $GITHUB_ENV | |
- name: Exit early for unsupported applications | |
if: env.hostType == '-1' | |
run: | | |
echo "Unsupported application: ${{ github.event.inputs.servicename }}. Skipping workflow." | |
exit 0 | |
- name: Request token from auth-station | |
id: auth_token_request | |
run: | | |
response=$(curl -X POST "https://auth-station-staging.aevatar.ai/connect/token" \ | |
-H "Content-Type: application/x-www-form-urlencoded" \ | |
-H "Accept: application/json" \ | |
--data-urlencode "grant_type=client_credentials" \ | |
--data-urlencode "client_id=${{ secrets.AIMINING_CLIENT_ID }}" \ | |
--data-urlencode "client_secret=${{ secrets.AIMINING_CLIENT_SECRET }}" \ | |
--data-urlencode "scope=Aevatar") | |
echo "Response: $response" | |
token=$(echo $response | jq -r '.access_token') | |
echo "access_token=$token" >> $GITHUB_ENV | |
- name: Conditionally Call UpdateDockerImage endpoint | |
run: | | |
echo "Calling UpdateDockerImage for hostType=${{ env.hostType }} with imageName=${{ steps.meta.outputs.tags }}" | |
curl -X 'POST' "https://station-staging.aevatar.ai/api/users/updateDockerImage?hostType=${{ env.hostType }}&imageName=$(echo '${{ steps.meta.outputs.tags }}' | sed 's/:/%3A/g')" \ | |
-H "accept: */*" \ | |
-H "Authorization: Bearer ${{ env.access_token }}" \ | |
-H "X-Requested-With: XMLHttpRequest" \ | |
-d '' | |
echo "Docker image updated successfully." |