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

provide way to check for changes programmatically #254

Open
afeld opened this issue Jun 4, 2024 · 0 comments
Open

provide way to check for changes programmatically #254

afeld opened this issue Jun 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@afeld
Copy link

afeld commented Jun 4, 2024

Is your feature request related to a problem? Please describe.
We are using schemachange as part of a continuous deployment pipeline (in Azure DevOps, specifically). We want to manually review scripts that are going to be run against production, but only notify people to do so if there are any to be run.

Describe the solution you'd like
I'd like a way to reliably have code determine if schemachange finds any scripts to be run. Options that come to mind are having flags for:

  • JSON output
  • Having the exit code indicate whether there are changes, like Terraform does

Describe alternatives you've considered
Here's the solution I came up with is to parse the "Successfully applied N change scripts" line of the schemachange output.

The pipeline job

- bash: |
    schemachange --config-folder config/${{ parameters.env }} -f . --dry-run | \
      tee >(python3 azure/schemachange_check.py)

schemachange_check.py

import re
import sys

output = sys.stdin.read()

match = re.search(r"Successfully applied (\d+) change scripts", output)
if match:
    num_changes = int(match.group(1))
    has_changes = num_changes > 0
    HAS_CHANGES_STR = "true" if has_changes else "false"
    print(f"Changes detected: {HAS_CHANGES_STR}")

    # Azure Pipeline control statements
    print(
        f"##vso[task.setvariable variable=HAS_CHANGES;isOutput=true]{HAS_CHANGES_STR}"
    )
    if has_changes:
        print(
            "##vso[task.logissue type=warning]👍 - Changes detected, pipeline will require a manual approval to proceed"
        )
    else:
        print("##vso[task.logissue type=warning]ℹ️ - No changes detected")
else:
    raise RuntimeError("Failed to parse the number of applied change scripts.")

Additional context
none

@afeld afeld added the enhancement New feature or request label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant