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 option to status command to print just the name or SHA of the last deployed change #569

Open
dlawrences opened this issue Mar 31, 2021 · 5 comments
Labels

Comments

@dlawrences
Copy link

dlawrences commented Mar 31, 2021

Hey team

Is there any specific argument or command that one can use to achieve the following steps without writing additional shell logic?

  1. Deploy changes from a sqitch plan to a target
  2. Verify them
  3. Always revert to the initial starting change before deployment (which may not be @root)

I know one could do:

sqitch deploy <target> --verify
<shell cmd to determine the first change to rollback to>
sqitch revert --to <change determined above>

But I am trying to circumvent writing the additional shell logic to parse the deploy/plan output if not 100% required. I am trying to bake this into CI logic for Snowflake Pull Requests.

Thank you,
Laurentiu

@dlawrences dlawrences changed the title Deploy, verify deployment and revert immediately Deploy, verify deployment and revert immediately (even if it does not fail) Mar 31, 2021
@theory
Copy link
Collaborator

theory commented Apr 1, 2021

No, but you can use sqitch log to capture the currently-deployed change before you run sqitch deploy, something like:

change=$(sqitch log --event deploy -f format:%H -n 1)
sqitch deploy <target> --verify
if [-z "$change" ]; then
    sqitch revert -y <target>
else
    sqitch revert -y <target> --to $change
fi

@theory theory closed this as completed Apr 1, 2021
@dlawrences
Copy link
Author

Thanks @theory, very helpful!

@dlawrences
Copy link
Author

I wanted to just add my resolution on this one: I had to move away from using sqitch log --event deploy as this reads from SQITCH.EVENTS records with EVENT = "deploy" which is obviously not going to always point to the state of the environment to which we would want to auto-revert (the latest deploy event may not point to the actual latest changeset active on the environment as that may have already been reverted).

I've been able to identify the environment state prior to deployment by doing:

change=$(sqitch status --target <target> | sed -n -e 's/^.*Change: //p' | awk '{$1=$1;print}')

Which is basically extracting the latest changeset hash active on the environment prior to deployment. And from then onwards, it's the same you added above @theory, thanks for the guidance!

@theory
Copy link
Collaborator

theory commented Apr 6, 2021

the latest deploy event may not point to the actual latest changeset active on the environment as that may have already been reverted

🤦🏻 Oh, right.

Would be nice to have an option on --status to just emit the name or sha of the last deployed change. I'm gonna make this ticket a feature request for that.

@theory theory reopened this Apr 6, 2021
@theory theory changed the title Deploy, verify deployment and revert immediately (even if it does not fail) Add option to status command to print just the name or SHA of the last deployed change Apr 6, 2021
@theory theory added the feature label Apr 6, 2021
@dlawrences
Copy link
Author

Great stuff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants