-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (52 loc) · 2.39 KB
/
database-PR.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: database opens PR
on:
workflow_dispatch:
jobs:
validate-db:
runs-on: ubuntu-latest
steps:
- name: '1. Checkout repo files'
uses: actions/checkout@v2
- name: '2. Set timestamp variable'
id: timestamp
run: echo "branchtimestamp=$(date +'%Y-%m-%d-%H-%M-%S')" >> $GITHUB_OUTPUT
- name: '3. Reset existing database files in repo'
run: rm -f -r AdventureWorks
- name: '4. Deconstruct database objects to files'
run: |
sqlpackage /Action:Extract /SourceConnectionString:"${{ secrets.SQL_CONNECTION }}" /TargetFile:"AdventureWorks" /p:ExtractTarget=ObjectType
- name: '4b. optional - add a sqlproj to folder'
run: |
dotnet new install microsoft.build.sql.templates
dotnet new sqlproj -o AdventureWorks -tp Sql160
- name: '5. Check if there is any changes with git'
id: get_changes
run: echo "changed=$(git status --porcelain | wc -l)" >> $GITHUB_OUTPUT
# if there are changes commit and push
- name: '6. Process changes into a git commit'
if: steps.get_changes.outputs.changed != 0
run: |
git config --global user.email "[email protected]"
git config --global user.name "Database Status Bot"
git switch -c db-deconstruction-${{ steps.timestamp.outputs.branchtimestamp }}
git add AdventureWorks
git commit -m "Update database deconstruction"
git push -u origin db-deconstruction-${{ steps.timestamp.outputs.branchtimestamp }}
# open pull request
- name: '7. open a pull request'
id: pull_request
if: steps.get_changes.outputs.changed != 0
uses: vsoch/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_FROM_BRANCH: "db-deconstruction-${{ steps.timestamp.outputs.branchtimestamp }}"
PULL_REQUEST_BRANCH: "main"
PULL_REQUEST_TITLE: "Update database state"
- name: '8a. output summary with PR link'
if: steps.get_changes.outputs.changed != 0
run: |
echo "### :bell: New pull request ${{ steps.pull_request.outputs.pull_request_url }}" >> $GITHUB_STEP_SUMMARY
- name: '8b. output summary with no changes'
if: steps.get_changes.outputs.changed == 0
run: |
echo "### :tada: No database drift detected" >> $GITHUB_STEP_SUMMARY