Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitLab Actions to Lineage Extractor docs #483

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions docs/metadata/lineage/lineage-extractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ python -m prophecy_lineage_extractor --project-id <PROJECT_ID> --pipeline-id <PI
| `--send-email` | flag | If specified, sends an email with the generated lineage report to the environment variable `RECEIVER_EMAIL`. You must set the following environment variables for this option if passed: <br /><br /> <ul><li>`SMTP_HOST`</li><li>`SMTP_PORT`</li><li>`SMTP_USERNAME`</li><li>`SMTP_PASSWORD`</li><li>`RECEIVER_EMAIL`</li></ul> | False |
| `--branch` | str | Branch to run the lineage extractor on. <br /> The default branch in Prophecy is generally 'main'. | True |

## Integrate with GitHub Actions
## Integrate with GitHub Actions or GitLab Actions

The lineage extractor can be integrated with your GitHub Actions. The steps for setting up the lineage extractor with GitHub Actions on your repository containing a Prophecy project are mentioned below.
The lineage extractor can be integrated with your GitHub Actions or GitLab Actions. The steps for setting up the lineage extractor on your repository containing a Prophecy project are mentioned below.

### Prerequisite

Expand All @@ -44,7 +44,9 @@ Optionally, if you choose to set up email notifications, you must also set secre

These environment variables can be set as secrets inside the GitHub repository of the project. For more information, see [Set up environment variables and secrets](../../deployment/prophecy-build-tool/pbt-github-actions.md#set-up-environment-variables-and-secrets).

The environment variables can also be set within the GitHub actions YML file as follows:
The environment variables can also be set within the GitHub Actions or GitLab Actions YML file.

For GitHub Actions:

```yaml
env:
Expand All @@ -53,6 +55,14 @@ SMTP_USERNAME: ${{ secrets.SMTP_USERNAME}}
SMTP_PASSWORD: ${{ secrets.SMTP_PASSWORD }}
```

For GitLab Actions:

```yaml
export PROPHECY_PAT="$PROPHECY_PAT"
export SMTP_USERNAME="$SMTP_USERNAME"
export SMTP_PASSWORD="$SMTP_PASSWORD"
```

The complete YML file definition is discussed in the next section.

### Run the lineage extractor
Expand Down Expand Up @@ -80,6 +90,8 @@ export [email protected]
python -m prophecy_lineage_extractor --project-id 36587 --pipeline-id 36587/pipelines/customer_orders_demo --send-email --branch dev
```

#### GitHub Actions file

- Create a .YML file in the project repository at the below location (relative to root):

```
Expand Down Expand Up @@ -232,6 +244,66 @@ python -m prophecy_lineage_extractor --project-id 36587 --pipeline-id 36587/pipe

</details>

#### GitLab Actions file

- Create a .YML file in the project repository.

- Add the below contents with your own environment variables to `.gitlab-ci.yml`:

<details>
<summary>GitLab action</summary>

```
stages:
- extract

variables:
GIT_COMMIT: "1" # to enable committing report file to git
OUTPUT_DIR: "output_dev"
extract_and_mail:
stage: extract
image: python:3.9
script:
- pip install --no-cache-dir prophecy-lineage-extractor
- |
# gitlab ci/cd variables, access_token also need to be defined if using git commit
export PROPHECY_URL="$PROPHECY_URL"
export PROPHECY_PAT="$PROPHECY_PAT"
export SMTP_USERNAME="$SMTP_USERNAME"
export SMTP_PASSWORD="$SMTP_PASSWORD"
export SMTP_HOST="smtp.gmail.com"
export SMTP_PORT="587"
export RECEIVER_EMAIL="[email protected]"
# value in seconds for monitoring, this might be increased depending on pipeline size
export MONITOR_TIME_ENV="50"
- |
BRANCH="dev"
python -m prophecy_lineage_extractor \
--project-id 36587 \
--pipeline-id 36587/pipelines/customer_orders_demo \
--send-email \
--output-dir $OUTPUT_DIR \
--branch $BRANCH
- |
if [ "$GIT_COMMIT" == "1" ]; then
echo "Git commit is enabled, output directory '$OUTPUT_DIR'"
git config --global user.name 'pateash'
git config --global user.email '[email protected]'
git add $OUTPUT_DIR/*
git commit -m "[GitLab CI - $BRANCH] Adding excel lineage report"
git remote add gitlab_origin https://oauth2:[email protected]/pateash/ProphecyHelloWorld.git
echo "Pushing changes to git branch $BRANCH"
git push gitlab_origin HEAD:$BRANCH -o ci.skip # prevent triggering pipeline again
else
echo "Committing to git is not enabled"
fi
only:
refs:
- dev
```

</details>

## Output example

The lineage extractor output is in the form of an XLSX file.
Expand Down
Loading