mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
refactor(api): simplify build action
This commit is contained in:
parent
af2607e251
commit
853821130c
2 changed files with 3 additions and 145 deletions
131
.github/workflows/directory-migrate.yml
vendored
131
.github/workflows/directory-migrate.yml
vendored
|
|
@ -1,131 +0,0 @@
|
|||
name: Directory API - Apply Data Changes
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- .github/workflows/directory-migrate.yml
|
||||
- services/Directory/data/**
|
||||
- services/Directory/FilterLists.Directory.Infrastructure.Migrations/**
|
||||
|
||||
jobs:
|
||||
add_migration:
|
||||
name: Add EF Core Migration
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
env:
|
||||
USER_NAME: github-actions[bot]
|
||||
USER_EMAIL: github-actions[bot]@users.noreply.github.com
|
||||
LINT_MESSAGE: "chore(dir-data): 🎨 lint PR #${{ github.event.number }}"
|
||||
MIGRATION_MESSAGE: "chore(dir-data): ♻️ migrate PR #${{ github.event.number }}"
|
||||
TEST_MSSQL_IMAGE: mcr.microsoft.com/mssql/server:2022-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
||||
ref: ${{ github.event.pull_request.head.ref }}
|
||||
fetch-depth: 50 # guess max depth for data migration branch to avoid fetching all while still allowing sync w/upstream
|
||||
|
||||
- name: Lint
|
||||
run: ./lint.sh
|
||||
working-directory: ./services/Directory/data
|
||||
|
||||
- name: git config
|
||||
run: |
|
||||
git config --global user.name "$USER_NAME"
|
||||
git config --global user.email "$USER_EMAIL"
|
||||
|
||||
- name: git commit
|
||||
run: |
|
||||
LINT_PENDING_CHANGES=$(git status -s -- .)
|
||||
if [ -n "$LINT_PENDING_CHANGES" ]; then
|
||||
git commit -am "$LINT_MESSAGE"
|
||||
fi
|
||||
|
||||
- name: Sync with Upstream
|
||||
run: |
|
||||
git remote add upstream https://github.com/${{ github.repository }}.git
|
||||
git fetch upstream
|
||||
git merge upstream/${{ github.event.pull_request.base.ref }}
|
||||
|
||||
- name: Revert Any Previous Migration for PR
|
||||
run: |
|
||||
PREVIOUS_MIGRATION_HASH=$(git log --grep="$MIGRATION_MESSAGE" --pretty=format:"%H" -n 1)
|
||||
if [ -n "$PREVIOUS_MIGRATION_HASH" ]; then
|
||||
git revert --no-edit $PREVIOUS_MIGRATION_HASH
|
||||
fi
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "9.0.x"
|
||||
|
||||
# Disabled GH Actions cache for Dependabot. https://github.com/dependabot/dependabot-core/issues/1303
|
||||
# cache-dependency-path: services/Directory/FilterLists.Directory.Api/packages.lock.json
|
||||
# cache: true
|
||||
|
||||
- name: Install dotnet-ef
|
||||
run: dotnet tool install --global dotnet-ef
|
||||
|
||||
# - name: Restore
|
||||
# run: dotnet restore --locked-mode
|
||||
# working-directory: ./services/Directory/FilterLists.Directory.Api
|
||||
|
||||
- name: Add Migration
|
||||
run: >
|
||||
dotnet ef migrations add ${{ github.event.number }}
|
||||
-p FilterLists.Directory.Infrastructure.Migrations
|
||||
-s FilterLists.Directory.Api
|
||||
working-directory: ./services/Directory
|
||||
env:
|
||||
DOTNET_RUNNING_EF_CORE_TOOLS: true
|
||||
|
||||
- name: Commit Effective Migration
|
||||
run: |
|
||||
MIGRATION_CHANGED_FILE_COUNT=$(git status -s -- . | wc -l)
|
||||
if [ "$MIGRATION_CHANGED_FILE_COUNT" -eq 3 ]; then
|
||||
git add .
|
||||
git commit -m "$MIGRATION_MESSAGE"
|
||||
else
|
||||
git clean -fd
|
||||
fi
|
||||
|
||||
- name: Run Test SQL Server
|
||||
run: >
|
||||
docker run --name sql-server
|
||||
-e 'ACCEPT_EULA=Y'
|
||||
-e 'SA_PASSWORD=Your_password123'
|
||||
-p 1433:1433
|
||||
-d $TEST_MSSQL_IMAGE
|
||||
|
||||
- name: Wait for Test SQL Server
|
||||
run: |
|
||||
echo "Waiting for SQL Server to start..."
|
||||
for i in {1..30}; do
|
||||
if docker exec sql-server /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P Your_password123 -Q "SELECT 1" &> /dev/null; then
|
||||
echo "SQL Server is up and running."
|
||||
exit 0
|
||||
fi
|
||||
echo "Waiting..."
|
||||
sleep 2
|
||||
done
|
||||
echo "SQL Server did not start in time."
|
||||
exit 1
|
||||
|
||||
- name: Test Migrations
|
||||
run: >
|
||||
dotnet ef database update
|
||||
--connection "Server=localhost,1433;Database=DirectoryDb;User Id=sa;Password=Your_password123;TrustServerCertificate=True;"
|
||||
-p FilterLists.Directory.Infrastructure.Migrations
|
||||
-s FilterLists.Directory.Api
|
||||
working-directory: ./services/Directory
|
||||
|
||||
- name: git push
|
||||
run: git push
|
||||
17
.github/workflows/directory.yml
vendored
17
.github/workflows/directory.yml
vendored
|
|
@ -14,6 +14,7 @@ on:
|
|||
- main
|
||||
paths:
|
||||
- .github/workflows/directory.yml
|
||||
- services/Directory.Build.props
|
||||
- services/Directory/**
|
||||
- services/FilterLists.ServiceDefaults/**
|
||||
|
||||
|
|
@ -42,19 +43,7 @@ jobs:
|
|||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: "9.0.x"
|
||||
|
||||
# Disabled GH Actions cache for Dependabot. https://github.com/dependabot/dependabot-core/issues/1303
|
||||
# cache-dependency-path: services/Directory/FilterLists.Directory.Api/packages.lock.json
|
||||
# cache: true
|
||||
|
||||
# - name: Restore
|
||||
# run: dotnet restore --locked-mode
|
||||
# working-directory: ./services/Directory/FilterLists.Directory.Api
|
||||
|
||||
- name: Build
|
||||
run: dotnet build -c Release
|
||||
working-directory: ./services/Directory/FilterLists.Directory.Api
|
||||
|
||||
|
||||
- name: Login to Container Registry
|
||||
if: github.event_name == 'push'
|
||||
uses: docker/login-action@v3
|
||||
|
|
@ -66,7 +55,7 @@ jobs:
|
|||
- name: Publish & Push
|
||||
if: github.event_name == 'push'
|
||||
run: >
|
||||
dotnet publish --sc
|
||||
dotnet publish
|
||||
-p:PublishProfile=DefaultContainer
|
||||
-p:ContainerRegistry=${{ env.CONTAINER_REGISTRY }}
|
||||
-p:ContainerRepository=${{ env.CONTAINER_REPOSITORY }}
|
||||
|
|
|
|||
Loading…
Reference in a new issue