From 0f36d4102cfd13c6532eafe694e595ee4155254c Mon Sep 17 00:00:00 2001 From: Jover Date: Tue, 23 May 2023 16:14:20 -0700 Subject: [PATCH] Add bin/interpolate-text-template MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modifies the "Generate summary" step from the conda-base repo CI workflow¹ into a separate script that can be used to interpolate any text template with environment variables. I will be using this in the reusable run-build workflow to create the GitHub Action summary for AWS Batch builds. I also see this being useful for creating Slack messages for automated builds such as the onstart and onerror notifications that we use in ncov² if we decide to move the notifications out of the pathogen workflows and into the GitHub Action workflows. ¹ https://github.com/nextstrain/conda-base/blob/5655133be6864ede0acbf40b6b06222f9f2dc031/.github/workflows/ci.yaml#L107-L112 ² https://github.com/nextstrain/ncov/blob/fcac1d16410b1b119a9af70afe7b9325a6e25083/workflow/snakemake_rules/export_for_nextstrain.smk#L499-L519 --- README.md | 1 + bin/interpolate-text-template | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100755 bin/interpolate-text-template diff --git a/README.md b/README.md index cdbfd0a..40bd820 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ See also GitHub's [documentation on starter workflows](https://docs.github.com/e Executable scripts that are used in our workflows. +- [interpolate-text-template](bin/interpolate-text-template) - [write-envdir](bin/write-envdir) - [json-to-envvars](bin/json-to-envvars) - [yaml-to-envvars](bin/yaml-to-envvars) diff --git a/bin/interpolate-text-template b/bin/interpolate-text-template new file mode 100755 index 0000000..45938b8 --- /dev/null +++ b/bin/interpolate-text-template @@ -0,0 +1,12 @@ +#!/bin/bash +# usage: interpolate-text-template +# +# Replaces ${x} in with value of environment variable "x" and +# outputs the updated text to stdout. +# +# Modified from the conda-base repo's CI workflow: +# https://github.com/nextstrain/conda-base/blob/a2da0f5ef7e95f9db31678c2df00bd312c7b754a/.github/workflows/ci.yaml#L109-L111 +# +set -eou pipefail + +perl -pe 's/\$\{(.+?)\}/$ENV{$1}/ge' < "$1" \