Skip to content

Commit c096837

Browse files
AliSoftwaremokagio
andauthored
Add git-conceal-unlock wrapper (#195)
* Introduce `git-conceal-unlock` wrapper script That auto-downloads the binary from GitHub Release (using the `install.sh` script of the `git-conceal` repo) if it doesn't exist locally, before running `git-conceal unlock` on the current repo to decrypt the secrets * Add CHANGELOG entry * Update doc header Co-authored-by: Gio Lodi <[email protected]> * Wording adjustment Co-authored-by: Gio Lodi <[email protected]> * Use `exec` instead of subprocess + `exit $?` Co-authored-by: Gio Lodi <[email protected]> * Add a note about the default env var To indicate its name having the `_SECRET_KEY` suffix was chosen purposely so its value would be redacted in the Buildkite logs if it were accidentally leaked. --------- Co-authored-by: Gio Lodi <[email protected]>
1 parent 5dd4b6a commit c096837

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _None._
4040

4141
### New Features
4242

43-
_None._
43+
- Add `git-conceal-unlock` helper script to download & install [`git-conceal`](https://github.com/Automattic/git-conceal) if not present, then run `git-conceal unlock`. [#195]
4444

4545
### Bug Fixes
4646

bin/git-conceal-unlock

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Description:
4+
# A wrapper script to run `git-conceal unlock` on CI
5+
# See https://github.com/Automattic/git-conceal
6+
#
7+
# The wrapper automatically runs the `install.sh` script of `git-conceal`
8+
# if it's not already installed locally before running `git-conceal unlock env:…`.
9+
#
10+
# By default, it uses the `GIT_CONCEAL_SECRET_KEY` environment variable as the key source.
11+
# You can override it by passing the environment variable name as the first argument.
12+
13+
set -euo pipefail
14+
15+
# Note: this default env var name has been purposely chosen with a `_SECRET_KEY` suffix
16+
# so that Buildkite will automatically redact any accidental leak of its value in CI logs.
17+
# See https://buildkite.com/docs/agent/v3/cli-pipeline#redacted-vars
18+
# See https://github.com/buildkite/elastic-ci-stack-s3-secrets-hooks/blob/cb27042/s3secrets-helper/secrets/secrets.go#L31-L38
19+
env_var_name=${1:-GIT_CONCEAL_SECRET_KEY}
20+
21+
# If installed in the $PATH, execute it (replacing this current process)
22+
if command -v git-conceal &> /dev/null; then
23+
exec git-conceal unlock "env:${env_var_name}"
24+
fi
25+
26+
INSTALL_DIR="${PWD}"
27+
# If already installed in INSTALL_DIR, execute it (replacing this current process)
28+
if [[ -x "${INSTALL_DIR}/git-conceal" ]]; then
29+
exec "${INSTALL_DIR}/git-conceal" unlock "env:${env_var_name}"
30+
fi
31+
32+
# Otherwise, install it locally and execute it
33+
echo "git-conceal binary not found. Installing it..."
34+
mkdir -p "${INSTALL_DIR}"
35+
curl -fsSL https://raw.githubusercontent.com/Automattic/git-conceal/trunk/install.sh | bash -s -- --prefix "${INSTALL_DIR}"
36+
"${INSTALL_DIR}/git-conceal" unlock "env:${env_var_name}"

0 commit comments

Comments
 (0)