diff --git a/.github/workflows/deploy-laravel.yml b/.github/workflows/deploy-laravel.yml index 57d9436..d4246ac 100644 --- a/.github/workflows/deploy-laravel.yml +++ b/.github/workflows/deploy-laravel.yml @@ -68,6 +68,9 @@ on: type: string default: main secrets: + BWS_ACCESS_TOKEN: + description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); without it, the secrets below come from GitHub as before + required: false RASGO_CORE_DEPLOY_TOKEN: description: Core token of the deploy actor (ops 1) required: false @@ -107,13 +110,18 @@ jobs: uses: rasgo-studio/.github/actions/deploy-core@main with: command: contract + # From Bitwarden when the environment has BWS_ACCESS_TOKEN, from the GitHub secrets otherwise (D-109, RINF-55). + # The values are masked and left for the next steps of this job, which read them from env. - name: Secrets uses: rasgo-studio/.github/actions/deploy-core@main env: + BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }} + BWS_PROJECT_ID: ${{ vars.BWS_PROJECT_ID }} + BWS_SERVER_URL: ${{ vars.BWS_SERVER_URL || 'https://vault.bitwarden.eu' }} RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} PLOI_DEPLOY_WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }} with: - command: require + command: secrets args: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK # Ploi pulls the head of its branch, not a commit: only that head can be the approved commit. - name: Branch the server pulls @@ -123,12 +131,12 @@ jobs: - name: Start (Core checks the approval) uses: rasgo-studio/.github/actions/deploy-core@main env: - CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }} with: command: start - name: Deploy (Ploi) env: - WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }} + WEBHOOK: ${{ env.PLOI_DEPLOY_WEBHOOK }} run: | curl -fsS -X POST --max-time 30 -o /dev/null "$WEBHOOK" echo "Despliegue pedido a Ploi." @@ -140,6 +148,6 @@ jobs: if: always() uses: rasgo-studio/.github/actions/deploy-core@main env: - CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }} with: command: finish diff --git a/.github/workflows/deploy-static.yml b/.github/workflows/deploy-static.yml index abfb9a4..934a71b 100644 --- a/.github/workflows/deploy-static.yml +++ b/.github/workflows/deploy-static.yml @@ -83,6 +83,9 @@ on: type: string default: 4.151.0 secrets: + BWS_ACCESS_TOKEN: + description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); without it, the secrets below come from GitHub as before + required: false RASGO_CORE_DEPLOY_TOKEN: description: Core token of the deploy actor (ops 1) required: false @@ -120,16 +123,7 @@ jobs: uses: rasgo-studio/.github/actions/deploy-core@main with: command: contract - - name: Secrets - uses: rasgo-studio/.github/actions/deploy-core@main - env: - RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - with: - command: require - args: RASGO_CORE_DEPLOY_TOKEN CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID - # The build comes before deploy-start, so a broken build does not spend the approval. + # The build comes before the secrets and deploy-start, so a broken build does not spend the approval. - uses: actions/setup-node@v4 with: node-version: ${{ inputs.node-version }} @@ -141,16 +135,30 @@ jobs: uses: rasgo-studio/.github/actions/deploy-core@main with: command: version-file + # From Bitwarden when the environment has BWS_ACCESS_TOKEN, from the GitHub secrets otherwise (D-109, RINF-55). + # After the build, so the build never sees a secret. The values are masked and left for the next steps of this job, which read them from env. + - name: Secrets + uses: rasgo-studio/.github/actions/deploy-core@main + env: + BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }} + BWS_PROJECT_ID: ${{ vars.BWS_PROJECT_ID }} + BWS_SERVER_URL: ${{ vars.BWS_SERVER_URL || 'https://vault.bitwarden.eu' }} + RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + with: + command: secrets + args: RASGO_CORE_DEPLOY_TOKEN CLOUDFLARE_API_TOKEN CLOUDFLARE_ACCOUNT_ID - name: Start (Core checks the approval) uses: rasgo-studio/.github/actions/deploy-core@main env: - CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }} with: command: start - name: Deploy (Cloudflare Pages) env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + CLOUDFLARE_API_TOKEN: ${{ env.CLOUDFLARE_API_TOKEN }} + CLOUDFLARE_ACCOUNT_ID: ${{ env.CLOUDFLARE_ACCOUNT_ID }} PAGES_PROJECT: ${{ inputs.pages-project }} PAGES_BRANCH: ${{ inputs.environment == 'production' && inputs.production-branch || inputs.staging-branch }} WRANGLER_VERSION: ${{ inputs.wrangler-version }} @@ -165,6 +173,6 @@ jobs: if: always() uses: rasgo-studio/.github/actions/deploy-core@main env: - CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }} with: command: finish diff --git a/.github/workflows/deploy-wordpress.yml b/.github/workflows/deploy-wordpress.yml index f91918f..6b6901b 100644 --- a/.github/workflows/deploy-wordpress.yml +++ b/.github/workflows/deploy-wordpress.yml @@ -56,6 +56,9 @@ on: type: string default: main secrets: + BWS_ACCESS_TOKEN: + description: Token of the Bitwarden Secrets Manager machine account that reads the actions project (D-109); without it, the secrets below come from GitHub as before + required: false RASGO_CORE_DEPLOY_TOKEN: description: Core token of the deploy actor (ops 1) required: false @@ -93,13 +96,18 @@ jobs: uses: rasgo-studio/.github/actions/deploy-core@main with: command: contract + # From Bitwarden when the environment has BWS_ACCESS_TOKEN, from the GitHub secrets otherwise (D-109, RINF-55). + # The values are masked and left for the next steps of this job, which read them from env. - name: Secrets uses: rasgo-studio/.github/actions/deploy-core@main env: + BWS_ACCESS_TOKEN: ${{ secrets.BWS_ACCESS_TOKEN }} + BWS_PROJECT_ID: ${{ vars.BWS_PROJECT_ID }} + BWS_SERVER_URL: ${{ vars.BWS_SERVER_URL || 'https://vault.bitwarden.eu' }} RASGO_CORE_DEPLOY_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} PLOI_DEPLOY_WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }} with: - command: require + command: secrets args: RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK # Ploi pulls the head of its branch, not a commit: only that head can be the approved commit. - name: Branch the server pulls @@ -109,12 +117,12 @@ jobs: - name: Start (Core checks the approval) uses: rasgo-studio/.github/actions/deploy-core@main env: - CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }} with: command: start - name: Deploy (Ploi) env: - WEBHOOK: ${{ secrets.PLOI_DEPLOY_WEBHOOK }} + WEBHOOK: ${{ env.PLOI_DEPLOY_WEBHOOK }} run: | curl -fsS -X POST --max-time 30 -o /dev/null "$WEBHOOK" echo "Despliegue pedido a Ploi." @@ -126,6 +134,6 @@ jobs: if: always() uses: rasgo-studio/.github/actions/deploy-core@main env: - CORE_TOKEN: ${{ secrets.RASGO_CORE_DEPLOY_TOKEN }} + CORE_TOKEN: ${{ env.RASGO_CORE_DEPLOY_TOKEN }} with: command: finish diff --git a/README.md b/README.md index e914e64..b6de097 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,8 @@ Every deploy follows the same order, and stops at the first step that fails: 1. **Contract.** Reads `rasgo.deploy.yml` and checks it against the run: the adapter is the one of the workflow, the environment exists, production has `approval: core`, an environment with `approval: core` got an `approval_id`, and the run comes from what the environment deploys (its branch, or a tag when `ref: tag`). -2. **Secrets.** The secrets the adapter reads are set in the environment of the calling repository. +2. **Secrets.** The secrets the adapter reads come from Bitwarden Secrets Manager or, while they have not moved, from + the environment of the calling repository (see Secrets below). In `deploy-static.yml` this step runs after the build. 3. **deploy-start.** Asks RASGO Core with the repository, app, environment, commit and `approval_id`. Core answers with a `deployment_id`, or with 403 and the reason (`pending`, `expired`, `used`, `mismatch`…), and then nothing touches the server (WFA-01.1, D-104). If Core does not answer, nothing deploys: there is no emergency exit. @@ -139,10 +140,24 @@ Calling them: deploy in `deployments.run_id`, as an artifact of that run (RCOR-45). Only digits are accepted, and the Contract step stops on anything else. Without it, neither request carries the header and the deploy works as before. Core ignores a number that is not one of its runs. -- **Secrets** live in the `staging` and `production` environments of the calling repository, with the names its - contract lists (DEV-07): `RASGO_CORE_DEPLOY_TOKEN` always (the Core token of the deploy actor, ops 1), then - `PLOI_DEPLOY_WEBHOOK`, or `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. The repository variable - `RASGO_CORE_URL` points to another Core, for tests. +- **Secrets** have the names the contract lists (DEV-07): `RASGO_CORE_DEPLOY_TOKEN` always (the Core token of the + deploy actor, ops 1), then `PLOI_DEPLOY_WEBHOOK`, or `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`. They live in + Bitwarden Secrets Manager, project `actions`, EU region (D-109). The `staging` and `production` environments of the + calling repository keep only `BWS_ACCESS_TOKEN`, the token of the read-only machine account of that project. + - **Keys.** One project holds every repository, so the Secrets step looks for the most specific key first: + `NAME____`, then `NAME__`, then `NAME`. The component of the contract and the + environment go in capitals, with anything else as `_`: the production webhook of `acme-portal` is + `PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION`; a token shared by all, such as `RASGO_CORE_DEPLOY_TOKEN`, keeps + its plain name. + - **While they move (RINF-55).** A name not found in Bitwarden is taken from the GitHub secret of the same name, and + the run warns with its name. Without `BWS_ACCESS_TOKEN` everything comes from GitHub, as before. A name in + neither place stops the deploy. + - **How.** `bws` (bitwarden/sdk-sm 2.1.0, checked against the sha256 pinned in `core.sh`, the same as rasgo-motor) reads the project with the + machine account. Each value is masked and left for the next steps of the job, and the run names the keys it + used, never a value. If Bitwarden does not answer, nothing deploys. Optional repository variables: + `BWS_PROJECT_ID` (read only that project) and `BWS_SERVER_URL` (another region). + - **Calling.** With `secrets: inherit`, or passing `BWS_ACCESS_TOKEN` explicitly under `secrets:`. +- The repository variable `RASGO_CORE_URL` points to another Core, for tests. - **Production** runs from `workflow_dispatch` once Sergio has approved it in the Hub, on the tag it deploys: `gh workflow run deploy.yml --ref acme-v1.4.0 -f environment=production -f approval_id=`. Each approval serves one deploy of one commit and lasts 24 hours (spec 003 of rasgo-core). Staging with `approval: none` can deploy on diff --git a/actions/deploy-core/core.sh b/actions/deploy-core/core.sh index 8553366..d6c7bdb 100755 --- a/actions/deploy-core/core.sh +++ b/actions/deploy-core/core.sh @@ -2,6 +2,7 @@ # Steps shared by the reusable deploy workflows of rasgo-studio (RINF-54, WFA-01.1, D-104). # # core.sh require NAME... the named environment variables (the secrets the adapter reads) are set +# core.sh secrets NAME... the same, read from Bitwarden Secrets Manager when BWS_ACCESS_TOKEN is set (D-109) # core.sh contract reads rasgo.deploy.yml, checks it against this run and saves the deploy state # core.sh branch-head the branch the Ploi site pulls is still at the commit of this run # core.sh version-file [DIR] writes DIR (or OUTPUT_DIR)/version.json with component, version and commit @@ -79,6 +80,102 @@ cmd_require() { note "Secretos presentes: $*" } +# Key of NAME in Bitwarden for this deploy, most specific first: NAME____, NAME__, +# NAME. One project (actions) holds the secrets of every repository, so a value that differs per site carries its +# component and environment in the key, in capitals with anything else as _ (acme-portal, production: +# PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION). +bws_keys() { + local name="$1" component environment + component="$(state_get component 2> /dev/null | tr '[:lower:]' '[:upper:]' | tr -c 'A-Z0-9\n' '_' || true)" + environment="$(printf '%s' "${DEPLOY_ENVIRONMENT:-}" | tr '[:lower:]' '[:upper:]' | tr -c 'A-Z0-9' '_')" + if [ -n "$component" ] && [ -n "$environment" ]; then printf '%s\n' "${name}__${component}__${environment}"; fi + if [ -n "$component" ]; then printf '%s\n' "${name}__${component}"; fi + printf '%s\n' "$name" +} + +# bws on the PATH, or the pinned release of bitwarden/sdk-sm checked against its sha256: the one pinned here for +# 2.1.0 (from bws-sha256-checksums-2.1.0.txt, the same as rasgo-motor), BWS_SHA256 when it is set, or for another +# BWS_VERSION the checksum file of that release. +BWS_PINNED_VERSION=2.1.0 +BWS_PINNED_SHA256=ba8233c3a4aee5d43e3c73bbd04d99e9bc5aba13bbbfd06d89b073abe732b860 +ensure_bws() { + command -v bws > /dev/null 2>&1 && return 0 + local version="${BWS_VERSION:-$BWS_PINNED_VERSION}" dir base url sum expected + dir="${RUNNER_TEMP:-/tmp}/bws-$version" + base="https://github.com/bitwarden/sdk-sm/releases/download/bws-v$version" + mkdir -p "$dir" + url="$base/bws-x86_64-unknown-linux-gnu-$version.zip" + curl -fsSL --max-time 60 -o "$dir/bws.zip" "$url" || fail "No se pudo descargar bws $version de bitwarden/sdk-sm." + sum="$(sha256sum "$dir/bws.zip" | cut -d' ' -f1)" + if [ -n "${BWS_SHA256:-}" ]; then + expected="$BWS_SHA256" + elif [ "$version" = "$BWS_PINNED_VERSION" ]; then + expected="$BWS_PINNED_SHA256" + else + curl -fsSL --max-time 30 -o "$dir/sums.txt" "$base/bws-sha256-checksums-$version.txt" || + fail "No se pudo descargar la suma sha256 de bws $version." + expected="$(grep "bws-x86_64-unknown-linux-gnu-$version.zip" "$dir/sums.txt" | cut -d' ' -f1)" + fi + [ -n "$expected" ] && [ "$sum" = "$expected" ] || fail "La suma sha256 de bws $version no coincide; no se usa." + unzip -oq "$dir/bws.zip" -d "$dir" + chmod +x "$dir/bws" + PATH="$dir:$PATH" + note "bws $version comprobado (sha256 $sum)." +} + +# NAME=value for the next steps of the job: every line masked first, then written with a delimiter of its own. +export_secret() { + local name="$1" value="$2" line delimiter + while IFS= read -r line; do + if [ -n "$line" ]; then printf '::add-mask::%s\n' "$line"; fi + done <<< "$value" + delimiter="rasgo_$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')" + if [ -n "${GITHUB_ENV:-}" ]; then printf '%s<<%s\n%s\n%s\n' "$name" "$delimiter" "$value" "$delimiter" >> "$GITHUB_ENV"; fi +} + +# Each NAME from Bitwarden Secrets Manager (the machine account of BWS_ACCESS_TOKEN, EU region), or else from the +# GitHub secret of the same name while it has not been moved (RINF-55): the run says which, never the value. +cmd_secrets() { + local name list key value missing="" from_bws="" from_github="" + if [ -n "${BWS_ACCESS_TOKEN:-}" ]; then + ensure_bws + list="$(mktemp)" + chmod 600 "$list" + if [ -n "${BWS_PROJECT_ID:-}" ]; then + BWS_SERVER_URL="${BWS_SERVER_URL:-https://vault.bitwarden.eu}" bws secret list "$BWS_PROJECT_ID" --output json > "$list" 2> /dev/null || + { rm -f "$list"; fail "Bitwarden Secrets Manager no responde con el token de este entorno; no se despliega."; } + else + BWS_SERVER_URL="${BWS_SERVER_URL:-https://vault.bitwarden.eu}" bws secret list --output json > "$list" 2> /dev/null || + { rm -f "$list"; fail "Bitwarden Secrets Manager no responde con el token de este entorno; no se despliega."; } + fi + fi + for name in "$@"; do + value="" + if [ -n "${list:-}" ]; then + while IFS= read -r key; do + if jq -e --arg k "$key" 'any(.[]; .key == $k)' "$list" > /dev/null; then + value="$(jq -r --arg k "$key" '[.[] | select(.key == $k)][0].value' "$list")" + from_bws="$from_bws $key" + break + fi + done < <(bws_keys "$name") + fi + if [ -z "$value" ] && [ -n "${!name:-}" ]; then + value="${!name}" + from_github="$from_github $name" + fi + if [ -z "$value" ]; then missing="$missing $name"; continue; fi + export_secret "$name" "$value" + done + if [ -n "${list:-}" ]; then rm -f "$list"; fi + [ -z "$missing" ] || fail "Faltan secretos en el entorno ${DEPLOY_ENVIRONMENT:-}:$missing. Van en Bitwarden Secrets Manager, proyecto actions, con el nombre que lista rasgo.deploy.yml (D-109)." + if [ -n "$from_bws" ]; then note "Desde Bitwarden:$from_bws"; fi + if [ -n "$from_github" ]; then + note "Desde los secrets de GitHub:$from_github" + if [ -n "${BWS_ACCESS_TOKEN:-}" ]; then printf '::warning::Aún no están en Bitwarden:%s (RINF-55).\n' "$from_github"; fi + fi +} + cmd_contract() { local file="${CONTRACT_FILE:-rasgo.deploy.yml}" env="${DEPLOY_ENVIRONMENT:-}" json local adapter component ref url approval path expect timeout version app branch public tag run_id @@ -340,6 +437,7 @@ main() { shift || true case "$command" in require) cmd_require "$@" ;; + secrets) cmd_secrets "$@" ;; contract) cmd_contract ;; branch-head) cmd_branch_head ;; version-file) cmd_version_file "$@" ;; @@ -347,7 +445,7 @@ main() { health) cmd_health ;; finish) cmd_finish ;; *) - note "Uso: core.sh require|contract|branch-head|version-file|start|health|finish" + note "Uso: core.sh require|secrets|contract|branch-head|version-file|start|health|finish" exit 2 ;; esac diff --git a/tests/deploy-core.test.sh b/tests/deploy-core.test.sh index f1ae18f..3793fc3 100644 --- a/tests/deploy-core.test.sh +++ b/tests/deploy-core.test.sh @@ -207,6 +207,67 @@ expect_ok "require: all secrets present" require RASGO_CORE_DEPLOY_TOKEN PLOI_DE check "require: the values are not printed" test "$(grep -c '^x$\|^y$' "$OUT")" = 0 unset PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN +# --- secrets ---------------------------------------------------------------------------------------------------- + +# A fake bws: answers `bws secret list [project] --output json` from bws.json and records its server and arguments. +fake_bws() { + cat > "$FAKE/bin/bws" << 'EOF' +#!/usr/bin/env bash +printf '%s|%s|%s\n' "${BWS_SERVER_URL:-}" "${BWS_ACCESS_TOKEN:+token}" "$*" >> "$FAKE_DIR/bws.calls" +[ ! -f "$FAKE_DIR/bws.down" ] || exit 1 +cat "$FAKE_DIR/bws.json" +EOF + chmod +x "$FAKE/bin/bws" + printf '%s' "$1" > "$FAKE/bws.json" +} +env_value() { # name: the value the step left for the next ones in GITHUB_ENV + awk -v n="$1" '$0 ~ "^"n"<<" { split($0, a, "<<"); d = a[2]; on = 1; next } on && $0 == d { on = 0; next } on { print }' "$GITHUB_ENV" +} + +setup +core contract +export DEPLOY_ENVIRONMENT=production GITHUB_ENV="$WORK/github_env" BWS_ACCESS_TOKEN=bootstrap +unset BWS_SERVER_URL BWS_PROJECT_ID PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN +fake_bws '[{"key":"RASGO_CORE_DEPLOY_TOKEN","value":"core-token"},{"key":"PLOI_DEPLOY_WEBHOOK","value":"generic"},{"key":"PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION","value":"site-hook"}]' +expect_ok "secrets: all from Bitwarden" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK +check "secrets: the key of the component and environment wins" test "$(env_value PLOI_DEPLOY_WEBHOOK)" = site-hook +check "secrets: a shared key by its plain name" test "$(env_value RASGO_CORE_DEPLOY_TOKEN)" = core-token +check "secrets: each value is masked" grep -Fq '::add-mask::site-hook' "$OUT" +check "secrets: no value is printed outside the mask" test "$(grep -v '::add-mask::' "$OUT" | grep -c 'site-hook\|core-token')" = 0 +check "secrets: bws asks the EU region" grep -Fq 'https://vault.bitwarden.eu|token|secret list --output json' "$FAKE/bws.calls" +check "secrets: the run names the keys it used" has "PLOI_DEPLOY_WEBHOOK__ACME_PORTAL__PRODUCTION" + +setup +core contract +export DEPLOY_ENVIRONMENT=staging GITHUB_ENV="$WORK/github_env" BWS_ACCESS_TOKEN=bootstrap BWS_PROJECT_ID=p1 +export PLOI_DEPLOY_WEBHOOK=from-github +unset RASGO_CORE_DEPLOY_TOKEN +fake_bws '[{"key":"RASGO_CORE_DEPLOY_TOKEN__ACME_PORTAL","value":"component-token"}]' +expect_ok "secrets: one in Bitwarden, one still in GitHub" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK +check "secrets: the key of the component" test "$(env_value RASGO_CORE_DEPLOY_TOKEN)" = component-token +check "secrets: the GitHub secret while it is not moved" test "$(env_value PLOI_DEPLOY_WEBHOOK)" = from-github +check "secrets: a warning names what is still in GitHub" has "Aún no están en Bitwarden: PLOI_DEPLOY_WEBHOOK" +check "secrets: the project id goes to bws" grep -Fq 'secret list p1 --output json' "$FAKE/bws.calls" + +setup +core contract +export GITHUB_ENV="$WORK/github_env" BWS_ACCESS_TOKEN=bootstrap +unset BWS_PROJECT_ID PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN +fake_bws '[]' +expect_fail "secrets: missing in Bitwarden and in GitHub" "Faltan secretos en el entorno staging: RASGO_CORE_DEPLOY_TOKEN" secrets RASGO_CORE_DEPLOY_TOKEN +touch "$FAKE/bws.down" +expect_fail "secrets: Bitwarden down stops the deploy" "no responde" secrets RASGO_CORE_DEPLOY_TOKEN + +setup +export GITHUB_ENV="$WORK/github_env" PLOI_DEPLOY_WEBHOOK=x RASGO_CORE_DEPLOY_TOKEN=y +unset BWS_ACCESS_TOKEN BWS_PROJECT_ID +fake_bws '[]' +expect_ok "secrets: without a token, the GitHub secrets as before" secrets RASGO_CORE_DEPLOY_TOKEN PLOI_DEPLOY_WEBHOOK +check "secrets: without a token bws is not called" test ! -f "$FAKE/bws.calls" +check "secrets: without a token there is no warning" test "$(grep -c '::warning::' "$OUT")" = 0 +check "secrets: the values reach the next steps" test "$(env_value RASGO_CORE_DEPLOY_TOKEN)" = y +unset PLOI_DEPLOY_WEBHOOK RASGO_CORE_DEPLOY_TOKEN GITHUB_ENV + # --- branch-head ------------------------------------------------------------------------------------------------ setup