Fix import #449
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: lexbox api | |
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#on | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- 'backend/**' | |
- '.github/workflows/lexbox-api.yaml' | |
- '.github/workflows/deploy.yaml' | |
- 'deployment/lexbox-deployment.yaml' | |
branches: | |
- main | |
- develop | |
pull_request: | |
paths: | |
- 'backend/**' | |
- '.github/workflows/lexbox-api.yaml' | |
- '.github/workflows/deploy.yaml' | |
- 'deployment/lexbox-deployment.yaml' | |
branches: | |
- main | |
- develop | |
env: | |
PROD_RELEASE: ${{github.ref == vars.PROD_BRANCH}} | |
IMAGE_NAME: ghcr.io/sillsdev/lexbox-api | |
jobs: | |
publish-api: | |
timeout-minutes: 60 | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.setVersion.outputs.VERSION }} | |
# postgres db is for automated tests | |
services: | |
postgres: | |
image: postgres:15-alpine | |
env: | |
POSTGRES_PASSWORD: 972b722e63f549938d07bd8c4ee5086c | |
POSTGRES_DB: lexbox-tests | |
# Set health checks to wait until postgres has started | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
ports: | |
# Maps tcp port 5432 on service container to the host | |
- 5433:5432 | |
env: | |
# https://docs.docker.com/develop/develop-images/build_enhancements/ | |
DOCKER_BUILDKIT: 1 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Dotnet build | |
run: dotnet build | |
- name: Unit tests | |
run: dotnet test --logger xunit --results-directory ./test-results --filter "Category!=Integration" --blame-hang-timeout 10m | |
- name: Upload test results | |
uses: EnricoMi/publish-unit-test-result-action@v2 | |
if: always() | |
with: | |
check_name: C# Unit Tests | |
files: ./test-results/*.xml | |
- name: Set Version | |
id: setVersion | |
# set version to date in vYYYY-MM-DD format | |
run: | | |
shortSha=$(echo ${{ github.sha }} | cut -c1-8) | |
echo "VERSION=v$(date --rfc-3339=date)-$shortSha" >> ${GITHUB_ENV} | |
echo "VERSION=v$(date --rfc-3339=date)-$shortSha" >> ${GITHUB_OUTPUT} | |
- name: Docker meta | |
id: meta | |
if: ${{ !env.ACT }} | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=raw,enable=${{ env.PROD_RELEASE }},value=latest | |
type=raw,enable=${{ env.PROD_RELEASE }},value=${{ env.VERSION }} | |
- name: ghcr.io login | |
uses: docker/login-action@v2 | |
if: ${{ !env.ACT }} | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- uses: docker/build-push-action@v4 | |
with: | |
context: backend | |
build-args: | | |
APP_VERSION=${{ env.VERSION }} | |
push: ${{ !env.ACT && github.repository == 'sillsdev/languageforge-lexbox' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy-api: | |
name: Deploy to k8s | |
uses: ./.github/workflows/deploy.yaml | |
with: | |
version: ${{ needs.publish-api.outputs.version }} | |
image: 'ghcr.io/sillsdev/lexbox-api' | |
secrets: inherit | |
needs: publish-api | |
if: ${{ github.ref == vars.PROD_BRANCH }} | |
verify-published: | |
runs-on: ubuntu-latest | |
needs: [deploy-api, publish-api] | |
steps: | |
- name: Verify Version | |
env: | |
TARGET_HOST: https://staging.languagedepot.org | |
EXPECTED_VERSION: ${{ needs.publish-api.outputs.version }} | |
run: | | |
IterateCount=10 | |
DelayMultiplier=5 | |
n=0 | |
until [ $n -ge $IterateCount ] | |
do | |
curl -s --head "$TARGET_HOST/api/healthz" > response.txt | |
# get version from response, trim off the header and fix the line endings | |
versionHeader=$((grep "lexbox-version" response.txt || echo VersionNotFound) | cut -d' ' -f 2 | tr -d '[:space:]') | |
if [[ "$versionHeader" == "$EXPECTED_VERSION" ]]; then | |
echo "Version is correct" | |
exit 0 | |
else | |
echo "Version '$versionHeader' is incorrect, expected '$EXPECTED_VERSION'" | |
echo "response was:" | |
cat response.txt | |
n=$((n+1)) | |
sleep $((DelayMultiplier * n)) | |
fi | |
done | |
echo "Version $versionHeader is still incorrect after waiting" | |
exit 1 | |
integration-tests: | |
name: Integration tests | |
uses: ./.github/workflows/integration-test.yaml | |
permissions: | |
checks: write | |
secrets: inherit | |
needs: verify-published |