Skip to content

Commit 72e2ddb

Browse files
workflows
1 parent f20f5c5 commit 72e2ddb

File tree

5 files changed

+107
-159
lines changed

5 files changed

+107
-159
lines changed

.github/workflows/dabs/prod.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/dabs/qa.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/dabs/test.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: 'Deploy to environments'
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*/*'
9+
pull_request:
10+
types: [opened, reopened, synchronize]
11+
12+
jobs:
13+
deploy-test:
14+
name: 'Deploy to test'
15+
uses: ./.github/workflows/templates/dabs.yml
16+
if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/')
17+
with:
18+
workflow_name: 'Test deployment'
19+
environment: 'test'
20+
target: 'test'
21+
env_vars: |
22+
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
23+
DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
24+
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
25+
DATABRICKS_BUNDLE_ENV: test
26+
secrets: inherit
27+
28+
deploy-qa:
29+
name: 'Deploy to QA'
30+
uses: ./.github/workflows/templates/dabs.yml
31+
needs: deploy-test
32+
if: github.event_name == 'pull_request' || startsWith(github.ref, 'refs/tags/')
33+
with:
34+
workflow_name: 'QA deployment'
35+
environment: 'qa'
36+
target: 'qa'
37+
env_vars: |
38+
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
39+
DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
40+
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
41+
DATABRICKS_BUNDLE_ENV: qa
42+
secrets: inherit
43+
44+
deploy-prod:
45+
name: 'Deploy to prod'
46+
uses: ./.github/workflows/templates/dabs.yml
47+
needs: deploy-qa
48+
if: github.ref == 'refs/heads/main'
49+
with:
50+
workflow_name: 'Prod deployment'
51+
environment: 'prod'
52+
target: 'prod'
53+
env_vars: |
54+
DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
55+
DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
56+
DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
57+
DATABRICKS_BUNDLE_ENV: prod
58+
secrets: inherit
Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
name: ${{ inputs.workflow_name }}
2-
3-
concurrency: 1
4-
51
on:
6-
${{ inputs.trigger_type }}:
7-
${{ inputs.trigger_config }}
2+
workflow_call:
3+
inputs:
4+
workflow_name:
5+
type: string
6+
required: true
7+
environment:
8+
type: string
9+
required: true
10+
target:
11+
type: string
12+
required: true
13+
env_vars:
14+
type: string
15+
required: true
816

917
jobs:
1018
detect-changes:
@@ -18,19 +26,17 @@ jobs:
1826
steps:
1927
- uses: actions/checkout@v3
2028
with:
21-
fetch-depth: 2 # Only need 2 commits for squash commit comparison
29+
fetch-depth: 2
2230

2331
- name: Detect changes in apps folder
2432
id: changes
2533
run: |
26-
# Check if apps folder has changes
2734
if git diff --name-only HEAD~1 | grep -q "^apps/"; then
2835
echo "apps=true" >> $GITHUB_OUTPUT
2936
else
3037
echo "apps=false" >> $GITHUB_OUTPUT
3138
fi
3239
33-
# Check if packages folder has changes
3440
if git diff --name-only HEAD~1 | grep -q "^packages/"; then
3541
echo "packages=true" >> $GITHUB_OUTPUT
3642
else
@@ -40,7 +46,6 @@ jobs:
4046
- name: Detect which specific apps changed
4147
id: changed-apps
4248
run: |
43-
# Get list of changed app directories
4449
CHANGED_APPS=$(git diff --name-only HEAD~1 | grep "^apps/" | cut -d'/' -f2 | sort -u | tr '\n' ',' | sed 's/,$//')
4550
if [ -n "$CHANGED_APPS" ]; then
4651
echo "list=$CHANGED_APPS" >> $GITHUB_OUTPUT
@@ -51,7 +56,6 @@ jobs:
5156
- name: Detect which specific packages changed
5257
id: changed-packages
5358
run: |
54-
# Get list of changed package directories
5559
CHANGED_PACKAGES=$(git diff --name-only HEAD~1 | grep "^packages/" | cut -d'/' -f2 | sort -u | tr '\n' ',' | sed 's/,$//')
5660
if [ -n "$CHANGED_PACKAGES" ]; then
5761
echo "list=$CHANGED_PACKAGES" >> $GITHUB_OUTPUT
@@ -69,20 +73,7 @@ jobs:
6973
app: ${{ fromJson(format('[{0}]', needs.detect-changes.outputs.changed-apps)) }}
7074
steps:
7175
- uses: actions/checkout@v3
72-
7376
- uses: databricks/setup-cli@main
74-
75-
- name: Validate Bundle app ${{ matrix.app }}
76-
run: |
77-
databricks bundle validate \
78-
--target ${{ inputs.target }} \
79-
--var="type_of_deployment=apps" \
80-
--var="deployment_name=${{ matrix.app }}"
81-
working-directory: .
82-
env:
83-
${{ inputs.env_vars }}
84-
85-
8677
- name: Deploy app ${{ matrix.app }}
8778
run: |
8879
databricks bundle deploy \
@@ -103,26 +94,47 @@ jobs:
10394
package: ${{ fromJson(format('[{0}]', needs.detect-changes.outputs.changed-packages)) }}
10495
steps:
10596
- uses: actions/checkout@v3
106-
10797
- uses: databricks/setup-cli@main
108-
109-
- name: Validate Bundle package ${{ matrix.package }}
110-
98+
- name: Deploy package ${{ matrix.package }}
11199
run: |
112-
databricks bundle validate \
100+
databricks bundle deploy \
113101
--target ${{ inputs.target }} \
114102
--var="type_of_deployment=packages" \
115103
--var="deployment_name=${{ matrix.package }}"
116104
working-directory: .
117105
env:
118106
${{ inputs.env_vars }}
119107

120-
- name: Deploy package ${{ matrix.package }}
108+
generate-tags:
109+
name: 'Generate tags for ${{ matrix.item }}'
110+
runs-on: ubuntu-latest
111+
needs: [detect-changes, deploy-apps, deploy-packages]
112+
if: github.ref == 'refs/heads/main' && (needs.detect-changes.outputs.apps-changed == 'true' || needs.detect-changes.outputs.packages-changed == 'true')
113+
strategy:
114+
matrix:
115+
item: ${{ concat(needs.detect-changes.outputs.changed-apps, needs.detect-changes.outputs.changed-packages) }}
116+
steps:
117+
- uses: actions/checkout@v3
118+
with:
119+
fetch-depth: 0
120+
token: ${{ secrets.GITHUB_TOKEN }}
121+
122+
- name: Generate semantic version
123+
id: version
121124
run: |
122-
databricks bundle deploy \
123-
--target ${{ inputs.target }} \
124-
--var="type_of_deployment=packages" \
125-
--var="deployment_name=${{ matrix.package }}"
126-
working-directory: .
127-
env:
128-
${{ inputs.env_vars }}
125+
# Get current timestamp for patch version
126+
TIMESTAMP=$(date +%s)
127+
PATCH_VERSION=$((TIMESTAMP % 1000))
128+
129+
# Generate semantic version
130+
VERSION="1.0.${PATCH_VERSION}"
131+
132+
echo "version=$VERSION" >> $GITHUB_OUTPUT
133+
echo "Generated version: $VERSION"
134+
135+
- name: Create and push tag
136+
run: |
137+
TAG_NAME="${{ matrix.item }}-v${{ steps.version.outputs.version }}"
138+
git tag $TAG_NAME
139+
git push origin $TAG_NAME
140+
echo "Created tag: $TAG_NAME"

0 commit comments

Comments
 (0)