Skip to content

Commit

Permalink
push code
Browse files Browse the repository at this point in the history
  • Loading branch information
luutuankiet committed Aug 25, 2024
1 parent da580ff commit 54f42ec
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/close-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

name: close-preview

on:
pull_request:
types: [closed, merged]

jobs:
preview:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]

- name: Get lightdash version
uses: sergeysova/jq-action@v2
id: version
env:
LIGHTDASH_URL: ${{ secrets.LIGHTDASH_URL }}
with:
cmd: curl -s "${LIGHTDASH_URL}/api/v1/health" | jq -r '.results.version'

- name: Install lightdash CLI
run: npm install -g "@lightdash/cli@${{ steps.version.outputs.value }}" || npm install -g @lightdash/cli@latest

- name: Lightdash CLI stop preview
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
LIGHTDASH_PROJECT: ${{ secrets.LIGHTDASH_PROJECT }}
LIGHTDASH_URL: ${{ secrets.LIGHTDASH_URL }}

run: lightdash stop-preview --name ${GITHUB_HEAD_REF##*/}
77 changes: 77 additions & 0 deletions .github/workflows/start-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: start-preview

on:
push:
branches-ignore: [ "main", "master", "BETA_prod" ]

env:
DBT_VERSION: "1.7.10"

jobs:
preview:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
- uses: actions/setup-python@v1
with:
python-version: "3.9.x"

- name: Copy Google credentials file
env:
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
if: "${{ env.GOOGLE_CREDENTIALS != '' }}"
id: create-json
uses: jsdaniell/[email protected]
with:
name: "googlecredentials.json"
json: ${{ env.GOOGLE_CREDENTIALS }}

- name: Move credentials to /tmp
run: mv googlecredentials.json /tmp || true

- name: Locate dbt_project.yml
run: echo "PROJECT_DIR=$(find . -name "dbt_project.yml" | sed 's/dbt_project.yml//g')" >> $GITHUB_ENV

- name: Get lightdash version
uses: sergeysova/jq-action@v2
id: version
env:
LIGHTDASH_URL: ${{ secrets.LIGHTDASH_URL }}
with:
cmd: curl -s "${LIGHTDASH_URL}/api/v1/health" | jq -r '.results.version'

- name: Copy profiles.yml
env:
config: ${{ secrets.DBT_PROFILES }}
run: echo -e "$config" > profiles.yml

- name: Install dbt
run: |
pip install dbt-core==$DBT_VERSION dbt-postgres==$DBT_VERSION dbt-redshift==$DBT_VERSION dbt-snowflake==$DBT_VERSION dbt-bigquery==$DBT_VERSION
dbt deps --project-dir "$PROJECT_DIR"
- name: Install lightdash CLI
run: npm install -g "@lightdash/cli@${{ steps.version.outputs.value }}" || npm install -g @lightdash/cli@latest

- name: Lightdash CLI start preview
id: start-preview
env:
LIGHTDASH_API_KEY: ${{ secrets.LIGHTDASH_API_KEY }}
LIGHTDASH_PROJECT: ${{ secrets.LIGHTDASH_PROJECT }}
LIGHTDASH_URL: ${{ secrets.LIGHTDASH_URL }}
GOOGLE_APPLICATION_CREDENTIALS: '/tmp/googlecredentials.json'

run: lightdash start-preview --project-dir "$PROJECT_DIR" --profiles-dir . --name ${GITHUB_REF##*/}

- uses: jwalton/gh-find-current-pr@v1
id: finder

- name: Leave a comment after deployment
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.finder.outputs.pr }}
message: |
:rocket: Deployed ${{ github.sha }} to ${{ steps.start-preview.outputs.url }}

0 comments on commit 54f42ec

Please sign in to comment.