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

Warn about migrations #15824

Merged
merged 2 commits into from Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 0 additions & 87 deletions .github/workflows/isolated_migrations.yml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/set_warnings_about_migrations.yml
@@ -0,0 +1,67 @@
name: Set warnings about migrations

on:
pull_request

permissions:
contents: read

jobs:
comment_on_pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Group files that have changed
id: changed-files-yaml
uses: tj-actions/changed-files@v43
with:
files_yaml: |
migrations:
- src/api/db/migrate/**
- src/api/db/data/**
not_migrations:
- '!src/api/db/migrate/**'
- '!src/api/db/data/**'
- '!src/api/db/schema.rb'
- '!src/api/db/data_schema.rb'
db_migrations:
- src/api/db/migrate/**
data_migrations:
- src/api/db/data/**
db_schema:
- src/api/db/schema.rb
data_schema:
- src/api/db/data_schema.rb

- name: Store PR number as artifact
run: |
mkdir ./artifacts
echo ${{ github.event.number }} > ./artifacts/pr_number.txt

- name: Store warning text about migrations
if: (steps.changed-files-yaml.outputs.migrations_any_changed == 'true') && (steps.changed-files-yaml.outputs.not_migrations_all_changed_files_count > 0)
run: |
COMMENT_TEXT_MIGRATIONS=":warning: Please make sure the migration is shipped in an independent Pull Request. :warning:"$'\n'
COMMENT_TEXT_MIGRATIONS+=":heavy_check_mark: You can include schema changes, annotations and validations for consistency but :x: avoid committing other changes with it."$'\n'
echo "$COMMENT_TEXT_MIGRATIONS" > ./artifacts/comment_text_migrations.txt

- name: Store warning text about missing db schema
if: (steps.changed-files-yaml.outputs.db_migrations_any_changed == 'true') && (steps.changed-files-yaml.outputs.db_schema_any_changed == 'false')
run: |
COMMENT_TEXT_DB_SCHEMA=":warning: There is a db migration but not a db schema. Please commit it."$'\n'
echo "$COMMENT_TEXT_DB_SCHEMA" > ./artifacts/comment_text_db_schema.txt

- name: Store warning text about missing data schema
if: (steps.changed-files-yaml.outputs.data_migrations_any_changed == 'true') && (steps.changed-files-yaml.outputs.data_schema_any_changed == 'false')
run: |
COMMENT_TEXT_DATA_SCHEMA=":warning: There is a data migration but not a data schema. Please commit it."$'\n'
echo "$COMMENT_TEXT_DATA_SCHEMA" > ./artifacts/comment_text_data_schema.txt

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: migrations_artifacts
path: artifacts/
48 changes: 48 additions & 0 deletions .github/workflows/warn_about_migrations.yml
@@ -0,0 +1,48 @@
name: Warn about migrations
on:
workflow_run:
workflows: ['Set warnings about migrations']
types:
- completed
permissions:
contents: read
jobs:
comment_on_pr:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Download artifacts
uses: dawidd6/action-download-artifact@v3
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success

- name: Fetch PR number from artifacts
run: |
echo "pr_number=$(cat migrations_artifacts/pr_number.txt)" >> $GITHUB_ENV

- name: Add comment about migration to PR
uses: thollander/actions-comment-pull-request@v2
if: ${{ hashFiles('migrations_artifacts/comment_text_migrations.txt') != '' }}
with:
filePath: migrations_artifacts/comment_text_migrations.txt
pr_number: ${{ env.pr_number }}
comment_tag: comment_about_migrations

- name: Add comment about missing db schema to PR
uses: thollander/actions-comment-pull-request@v2
if: ${{ hashFiles('migrations_artifacts/comment_text_db_schema.txt') != '' }}
with:
filePath: migrations_artifacts/comment_text_db_schema.txt
pr_number: ${{ env.pr_number }}
comment_tag: comment_about_db_schema

- name: Add comment about missing data schema to PR
uses: thollander/actions-comment-pull-request@v2
if: ${{ hashFiles('migrations_artifacts/comment_text_data_schema.txt') != '' }}
with:
filePath: migrations_artifacts/comment_text_data_schema.txt
pr_number: ${{ env.pr_number }}
comment_tag: comment_about_data_schema