init setup uses env var prod from secret while bootstrap paths from a… #14
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: start-preview | |
on: | |
push: | |
branches-ignore: [ "main", "master", "BETA_prod" ] | |
env: | |
DBT_VERSION: "1.8.1" | |
jobs: | |
preview: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: bootstrap environment variables | |
id: load-env | |
run: | | |
# first step init the file | |
. ./bootstrap_env.sh | |
# Check if .env.bootstrap file exists | |
if [ -f .env.bootstrap ]; then | |
# Process each line in the .env.bootstrap file | |
while IFS= read -r line; do | |
# Skip empty lines and lines starting with # | |
if [ -n "$line" ] && [[ ! "$line" =~ ^# ]]; then | |
# Export the variable to $GITHUB_ENV | |
echo "$line" >> $GITHUB_ENV | |
fi | |
done < .env.bootstrap | |
else | |
echo ".env.bootstrap file not found" | |
fi | |
- name: Create .env file from secret | |
run: | | |
echo "$PROD_ENV" > .env | |
env: | |
PROD_ENV: ${{ secrets.PROD_ENV }} | |
- name: Cache Python packages | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cache/pip | |
~/.local | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- uses: actions/setup-python@v1 | |
with: | |
python-version: "3.9.x" | |
- name: Install Python dependencies | |
run: | | |
pip install -r requirements.txt | |
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: Cache npm packages | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.npm | |
~/.cache/npm | |
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-npm- | |
- uses: actions/[email protected] | |
with: | |
node-version: '20' | |
- name: Install npm dependencies | |
run: npm install -g "@lightdash/cli@${{ steps.version.outputs.value }}" || npm install -g @lightdash/cli@latest | |
- 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: 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: 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 }} |