Skip to content

Commit

Permalink
simplified tf_lock_release
Browse files Browse the repository at this point in the history
  • Loading branch information
kneeyo1 committed Apr 4, 2024
1 parent 36d7ca4 commit 12b868f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tacos_unlock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ jobs:
id: main
run: |
# release all tfstate locks currently held
quietly \
echo "$SLICES" | jq -r '.[]' | ./tacos-gha/lib/ci/unlock
- name: update PR
if: always()
Expand Down
5 changes: 2 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

- ending phase 1

- combined messages, like plan
- @neo unlock
- @neo apply
- @ellison fix test suite -- update to new tag style, used in combined plan
summary
- @buck datadog ops events
Expand Down Expand Up @@ -184,6 +181,8 @@ P2
- [x] explain declined apply due to missing review
- [x] @buck TODO: roll up "commands" in PR comments when exit code is 0
- [x] @buck TODO: roll up init / refresh phases from tf log
- [ ] Unlock label deprecation -> on label trigger, reply that only draft PR can
be unlocked

## Testing

Expand Down
15 changes: 7 additions & 8 deletions lib/tf_lock/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ def get_lock_info(root_module: Path) -> Tuple[bool, dict[str, str]]:
return lock, assert_dict_of_strings(result)


def tf_lock_release(root_module: Path, env: Environ) -> UserError | None:
def tf_lock_release(root_module: Path, env: Environ) -> bool:
lock, lock_info = get_lock_info(root_module)
if not lock:
info(f"tf-lock-release: success: {root_module}")
return None
return True

tf_user = f"{get_current_user(env)}@{get_current_host(env)}"
lock_user = lock_info["Who"]
Expand All @@ -141,15 +141,15 @@ def tf_lock_release(root_module: Path, env: Environ) -> UserError | None:
lock_info["ID"],
)
)
except sh.CalledProcessError as error:
except sh.CalledProcessError:
# error message was already printed by subcommand
return UserError(code=error.returncode)
return False

info(f"tf-lock-release: success: {root_module}({lock_user})")
return None
return True

else:
return UserError(
raise UserError(
f"""\
tf-lock-release: failure: not {lock_user}: {root_module}({tf_user})
{TFLockUser.from_string(lock_user).eheld_message()}
Expand Down Expand Up @@ -189,8 +189,7 @@ def main() -> None:
with sh.quiet():
successes = 0
for path in paths:
if tf_lock_release(path, env=environ.copy()) is None:
successes += 1
successes += tf_lock_release(path, env=environ.copy())
failures = len(paths) - successes
sh.info(f"Successfully unlocked {successes} slices.")
sh.info(f"Failed to unlock {failures} slices.")
Expand Down

0 comments on commit 12b868f

Please sign in to comment.