Skip to content

Helm deployments

Helm deployments #38

Workflow file for this run

name: Schema Diff
on:
pull_request:
paths:
- 'src/Database/**'
jobs:
generate-diff:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout PR branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
path: pr
- name: Checkout target branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ github.base_ref }}
path: base
- name: Setup .NET
uses: actions/setup-dotnet@c2fa09f4bde5ebb9d1777cf28262a3eb3db3ced7
with:
global-json-file: pr/global.json
- name: Install sqlpackage
run: dotnet tool install --global microsoft.sqlpackage
- name: Build PR DACPAC
working-directory: pr
run: dotnet build src/Database/CatsDb/CatsDb.sqlproj --configuration Release
- name: Build baseline DACPAC
working-directory: base
run: dotnet build src/Database/CatsDb/CatsDb.sqlproj --configuration Release
- name: Generate schema diff
working-directory: pr
run: |
PR_HASH=$(unzip -p src/Database/CatsDb/bin/Release/CatsDb.dacpac model.xml | sha256sum | cut -d' ' -f1)
BASE_HASH=$(unzip -p ../base/src/Database/CatsDb/bin/Release/CatsDb.dacpac model.xml | sha256sum | cut -d' ' -f1)
if [ "$PR_HASH" != "$BASE_HASH" ]; then
sqlpackage /Action:Script \
/SourceFile:src/Database/CatsDb/bin/Release/CatsDb.dacpac \
/TargetFile:../base/src/Database/CatsDb/bin/Release/CatsDb.dacpac \
/TargetDatabaseName:CatsDb \
/OutputPath:schema-diff.sql
echo "has_changes=true" >> $GITHUB_ENV
else
echo "has_changes=false" >> $GITHUB_ENV
fi
- name: Comment on PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const hasChanges = process.env.has_changes === 'true';
let body;
if (hasChanges) {
const diff = fs.readFileSync('pr/schema-diff.sql', 'utf8');
body = `<!-- schema-diff -->\n#### ⚠️ Schema Changes Detected\n<details><summary>Show SQL</summary>\n\n\`\`\`sql\n${diff}\n\`\`\`\n\n</details>`;
} else {
body = `<!-- schema-diff -->\n#### ✅ No Schema Changes\n\nNo schema changes detected in this PR.`;
}
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const existing = comments.find(c => c.body.includes('<!-- schema-diff -->'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
}