-
Notifications
You must be signed in to change notification settings - Fork 1
add workflow 2 #6
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
Merged
Merged
Changes from all commits
Commits
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
169 changes: 169 additions & 0 deletions
.github/workflows/bb-masking-2.yml
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,169 @@ | ||
| name: Bytebase Masking Policy Update 2 | ||
| on: | ||
| pull_request: | ||
| types: [closed] | ||
| branches: | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| bytebase-masking-2: | ||
| if: github.event.pull_request.merged == true | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| pull-requests: write | ||
| issues: write | ||
| contents: read | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Login Bytebase | ||
| id: bytebase-login | ||
| uses: bytebase/login-action@0.0.2 | ||
| with: | ||
| bytebase-url: ${{ secrets.BYTEBASE_URL }} | ||
| service-key: ${{ secrets.BYTEBASE_SERVICE_KEY }} | ||
| service-secret: ${{ secrets.BYTEBASE_SERVICE_SECRET }} | ||
|
|
||
| - name: Get changed files | ||
| id: changed-files | ||
| uses: tj-actions/changed-files@v42 | ||
| with: | ||
| files: | | ||
| masking/masking-algorithm.json | ||
| masking/semantic-type.json | ||
|
|
||
| - name: Debug changed files in detail | ||
| run: | | ||
| echo "All changed files:" | ||
| echo "${{ steps.changed-files.outputs.all_changed_files }}" | ||
| echo "Contains masking-algorithm.json: ${{ contains(steps.changed-files.outputs.all_changed_files, 'masking-algorithm.json') }}" | ||
| echo "Contains semantic-type.json: ${{ contains(steps.changed-files.outputs.all_changed_files, 'semantic-type.json') }}" | ||
| echo "Raw output:" | ||
| echo "${{ toJSON(steps.changed-files.outputs) }}" | ||
|
|
||
| - name: Apply masking algorithm | ||
| id: apply-masking-algorithm | ||
| if: ${{ steps.changed-files.outputs.any_changed == 'true' && contains(steps.changed-files.outputs.all_changed_files, 'masking-algorithm.json') }} | ||
| run: | | ||
| # Process all masking-algorithm.json files | ||
| echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep "masking-algorithm.json" | while read -r CHANGED_FILE; do | ||
| echo "Processing: $CHANGED_FILE" | ||
|
|
||
| response=$(curl -s -w "\n%{http_code}" --request PATCH "${{ steps.bytebase-login.outputs.api_url }}/settings/bb.workspace.masking-algorithm" \ | ||
| --header "Authorization: Bearer ${{ steps.bytebase-login.outputs.token }}" \ | ||
| --header "Content-Type: application/json" \ | ||
| --data @"$CHANGED_FILE") | ||
|
|
||
| # Extract status code and response body | ||
| status_code=$(echo "$response" | tail -n1) | ||
| body=$(echo "$response" | sed '$d') | ||
| echo "Status code: $status_code" | ||
| echo "Response body: $body" | ||
|
|
||
| # Append to outputs (with unique identifiers) | ||
| echo "status_code=${status_code}" >> $GITHUB_OUTPUT | ||
| echo "${body}" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| if [[ $status_code -lt 200 || $status_code -ge 300 ]]; then | ||
| echo "Failed with status code: $status_code" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| - name: Apply semantic type | ||
| id: apply-semantic-type | ||
| if: ${{ steps.changed-files.outputs.any_changed == 'true' && contains(steps.changed-files.outputs.all_changed_files, '/semantic-type.json') }} | ||
| run: | | ||
| # Process all masking-exception.json files | ||
| echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep "semantic-type.json" | while read -r CHANGED_FILE; do | ||
| echo "Processing: $CHANGED_FILE" | ||
|
|
||
| response=$(curl -s -w "\n%{http_code}" --request PATCH "${{ steps.bytebase-login.outputs.api_url }}/settings/bb.workspace.semantic-types" \ | ||
| --header "Authorization: Bearer ${{ steps.bytebase-login.outputs.token }}" \ | ||
| --header "Content-Type: application/json" \ | ||
| --data @"$CHANGED_FILE") | ||
|
|
||
| # Extract status code and response body | ||
| status_code=$(echo "$response" | tail -n1) | ||
| body=$(echo "$response" | sed '$d') | ||
|
|
||
| echo "Status code: $status_code" | ||
| echo "Response body: $body" | ||
|
|
||
| # Append to outputs (with unique identifiers) | ||
| echo "${body}" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| if [[ $status_code -lt 200 || $status_code -ge 300 ]]; then | ||
| echo "Failed with status code: $status_code" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| - name: Comment on PR | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} | ||
| with: | ||
| script: | | ||
| const changedFiles = process.env.CHANGED_FILES || ''; | ||
| let commentBody = `### Masking Policy Update Summary\n\n`; | ||
|
|
||
| // Add status of merge | ||
| commentBody += `✅ **PR Status:** Merged\n\n`; | ||
|
|
||
| // Add changed files section | ||
| commentBody += `📝 **Changed Files:**\n\n`; | ||
| if (changedFiles.trim()) { | ||
| commentBody += changedFiles.split(' ').map(f => `- ${f}`).join('\n'); | ||
| } else { | ||
| commentBody += `None`; | ||
| } | ||
| commentBody += '\n\n'; | ||
|
|
||
| // Add API calls summary | ||
| commentBody += `🔄 **API Calls:**\n\n`; | ||
| let apiCallsFound = false; | ||
|
|
||
| if (changedFiles.includes('masking-algorithm.json')) { | ||
| const maskingStatuses = Object.keys(${{ toJSON(steps.apply-masking-algorithm.outputs) }} || {}) | ||
| .filter(key => key.startsWith('status_code_')) | ||
| .map(key => ({ | ||
| name: key.replace('status_code_', ''), | ||
| status: ${{ toJSON(steps.apply-masking-algorithm.outputs) }}[key] | ||
| })); | ||
|
|
||
| maskingStatuses.forEach(({name, status}) => { | ||
| apiCallsFound = true; | ||
| const success = status >= 200 && status < 300; | ||
| commentBody += `- Column Masking (${name}): ${success ? '✅' : '❌'} ${status}\n`; | ||
| }); | ||
| } | ||
|
|
||
| if (changedFiles.includes('semantic-type.json')) { | ||
| const exceptionStatuses = Object.keys(${{ toJSON(steps.apply-semantic-type.outputs) }} || {}) | ||
| .filter(key => key.startsWith('status_code_')) | ||
| .map(key => ({ | ||
| name: key.replace('status_code_', ''), | ||
| status: ${{ toJSON(steps.apply-semantic-type.outputs) }}[key] | ||
| })); | ||
|
|
||
| exceptionStatuses.forEach(({name, status}) => { | ||
| apiCallsFound = true; | ||
| const success = status >= 200 && status < 300; | ||
| commentBody += `- Masking Exception (${name}): ${success ? '✅' : '❌'} ${status}\n`; | ||
| }); | ||
| } | ||
|
|
||
| if (!apiCallsFound) { | ||
| commentBody += `None`; | ||
| } | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| ...context.repo, | ||
| issue_number: context.issue.number, | ||
| body: commentBody | ||
| }); |
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.