-
Notifications
You must be signed in to change notification settings - Fork 12
python_sql_workflows #74
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
Open
0xnu
wants to merge
7
commits into
main
Choose a base branch
from
feature/python
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5675675
python_sql_workflows
0xnu 0e3c37b
Update python-lint.yaml
0xnu eef11db
Update python-lint.yaml
0xnu 8586d4e
misc(feat): sql_validation
0xnu 59ff7ea
misc(feat): sql_validation
0xnu 8ba37f5
misc(feat): sql_validation
0xnu 22ade72
misc(feat): sql_validation
0xnu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Python Linting | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| python-version: | ||
| required: false | ||
| type: string | ||
| default: "3.x" | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: ${{ inputs.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install ruff | ||
| - name: Run Ruff and save results | ||
| run: | | ||
| mkdir -p logs | ||
| timestamp=$(date +"%Y%m%d_%H%M%S") | ||
| ruff check . > logs/lint_result_${timestamp}.txt | ||
| - name: Run Ruff Format | ||
| run: ruff format --check . | ||
| - name: Upload lint results | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: lint-results | ||
| path: logs/lint_result_*.txt |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| name: Validation, Reporting, and Cleanup | ||
|
|
||
| on: | ||
| push: | ||
| branches: [develop] | ||
| pull_request: | ||
| branches: [main] | ||
| schedule: | ||
| - cron: "0 2 * * 5" # Run every Friday at 2 AM UTC | ||
|
|
||
| jobs: | ||
| validate-and-report: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| actions: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.x" | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install sqlfluff==3.2.0 sqlparse==0.5.1 | ||
|
|
||
| - name: Create reports directory | ||
| run: mkdir -p reports | ||
|
|
||
| - name: Lint Oracle files | ||
| run: | | ||
| echo "Linting Oracle files:" | ||
| if [ -d "oracle" ]; then | ||
| echo "Oracle directory found. Contents:" | ||
| ls -R oracle | ||
| echo "Running SQLFluff on Oracle files:" | ||
| sqlfluff lint --dialect oracle --format yaml oracle || true | ||
| echo "Saving lint results:" | ||
| if sqlfluff lint --dialect oracle --format yaml oracle > reports/oracle_lint_report.yaml; then | ||
| echo "Oracle linting completed successfully" | ||
| else | ||
| echo "Oracle linting encountered issues, check the report for details" | ||
| fi | ||
| echo "Oracle lint report:" | ||
| cat reports/oracle_lint_report.yaml | ||
| else | ||
| echo "No Oracle directory found" | ||
| fi | ||
|
|
||
| - name: Lint MySQL files | ||
| run: | | ||
| echo "Linting MySQL files:" | ||
| if [ -d "mysql" ]; then | ||
| echo "MySQL directory found. Contents:" | ||
| ls -R mysql | ||
| echo "Running SQLFluff on MySQL files:" | ||
| sqlfluff lint --dialect mysql --format yaml mysql || true | ||
| echo "Saving lint results:" | ||
| if sqlfluff lint --dialect mysql --format yaml mysql > reports/mysql_lint_report.yaml; then | ||
| echo "MySQL linting completed successfully" | ||
| else | ||
| echo "MySQL linting encountered issues, check the report for details" | ||
| fi | ||
| echo "MySQL lint report:" | ||
| cat reports/mysql_lint_report.yaml | ||
| else | ||
| echo "No MySQL directory found" | ||
| fi | ||
|
|
||
| - name: Check SQL syntax | ||
| run: | | ||
| echo "Checking SQL syntax:" | ||
| touch reports/syntax_report.txt | ||
| find_output=$(find . -name "*.sql") | ||
| if [ -z "$find_output" ]; then | ||
| echo "No SQL files found" | tee -a reports/syntax_report.txt | ||
| else | ||
| while IFS= read -r file; do | ||
| echo "Checking $file" | tee -a reports/syntax_report.txt | ||
| if ! cat "$file" | sqlparse --validate >> reports/syntax_report.txt 2>&1; then | ||
| echo "Error validating $file" | tee -a reports/syntax_report.txt | ||
| fi | ||
| echo "" >> reports/syntax_report.txt | ||
| done <<< "$find_output" | ||
| fi | ||
| echo "Syntax check complete. Report contents:" | ||
| cat reports/syntax_report.txt | ||
|
|
||
| - name: Generate Markdown Report | ||
| run: | | ||
| report_file="reports/report-$(date +'%Y%m%d-%H%M%S').md" | ||
| echo "# SQL Validation Report" > $report_file | ||
| echo "## MySQL Linting Results" >> $report_file | ||
| echo '```yaml' >> $report_file | ||
| cat reports/mysql_lint_report.yaml >> $report_file | ||
| echo '```' >> $report_file | ||
| echo "## Oracle Linting Results" >> $report_file | ||
| echo '```yaml' >> $report_file | ||
| cat reports/oracle_lint_report.yaml >> $report_file | ||
| echo '```' >> $report_file | ||
| echo "## Syntax Check Results" >> $report_file | ||
| echo '```' >> $report_file | ||
| cat reports/syntax_report.txt >> $report_file | ||
| echo '```' >> $report_file | ||
|
|
||
| - name: Upload report | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: sql-validation-report | ||
| path: reports/report-*.md | ||
| retention-days: 7 | ||
|
|
||
| cleanup-old-reports: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| actions: write | ||
|
|
||
| steps: | ||
| - name: Delete old artifacts | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{secrets.GITHUB_TOKEN}} | ||
| script: | | ||
| const ms_per_day = 86400000; | ||
| const now = new Date(); | ||
| const sevenDaysAgo = new Date(now.getTime() - 7 * ms_per_day); | ||
|
|
||
| console.log(`Fetching artifacts older than ${sevenDaysAgo.toISOString()}`); | ||
|
|
||
| try { | ||
| const { data } = await github.rest.actions.listArtifactsForRepo({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| }); | ||
|
|
||
| if (data && data.artifacts && Array.isArray(data.artifacts)) { | ||
| for (const artifact of data.artifacts) { | ||
| if (new Date(artifact.created_at) < sevenDaysAgo) { | ||
| console.log(`Deleting artifact ${artifact.name} (ID: ${artifact.id})`); | ||
| await github.rest.actions.deleteArtifact({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| artifact_id: artifact.id, | ||
| }); | ||
| } | ||
| } | ||
| } else { | ||
| console.log('No artifacts found or unexpected data structure'); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error occurred while processing artifacts:', error); | ||
| } | ||
This file contains hidden or 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
Empty file.
Empty file.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.