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

Added action for env-loader #285

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/reusable-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: "${{ inputs.tool-directory }}/go.mod"
cache-dependency-path: '${{ inputs.tool-directory }}/go.sum'

# Linting
- name: Install golangci-lint
Expand Down
78 changes: 78 additions & 0 deletions tools/env-loader/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
name: Load environment values
description: Load environment values

inputs:
environments-directory:
description: Path to the directory containing environments files, defaulting to repo root
environment-name:
description: Name of the environment to load
value-sets:
description: Name of the value sets to load, separated by new line
tool-version:
description: Version of the tool to use

runs:
using: "composite"
steps:
# This cannot be implemented within another tool unless it is written as a
# typescript action. This logic must be able to run on all platforms,
# with only the tools already available on the system.
- name: Install the tool
shell: bash
env:
DEFAULT_TOOL_VERSION: ${{ github.action_ref }}
TOOL_VERSION: ${{ inputs.tool-version }}
INSTALL_DIR: /opt/bin
TOOL_NAME: env-loader
run: |
# Build the download URL
case "${RUNNER_OS}" in
Linux) OS='linux' ;;
Windows) OS='windows' ;;
macOS) OS='darwin' ;;
*) echo "Unsupported runner OS ${RUNNER_OS}" >&2; exit 1 ;;
esac

case "${RUNNER_ARCH}" in
X86) ARCH='i386' ;;
X64) ARCH='amd64' ;;
ARM) ARCH='arm' ;;
ARM64) ARCH='arm64' ;;
*) echo "Unsupported runner architecture ${RUNNER_ARCH}" >&2; exit 1 ;;
esac

if [[ -z "${TOOL_VERSION}" ]]; then
TOOL_VERSION="${DEFAULT_TOOL_VERSION##tools/${TOOL_NAME}/}"
fi

TAG="tools/${TOOL_NAME}/${TOOL_VERSION}"
URL_ENCODED_TAG="$(jq -rn --arg TAG "${TAG}" '$TAG|@uri')"
FILE_NAME="${TOOL_NAME}-${TOOL_VERSION}-${OS}-${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/gravitational/shared-workflows/releases/download/${URL_ENCODED_TAG}/${FILE_NAME}"

# Download the tool
export TMPDIR="${RUNNER_TEMP}"
DOWNLOAD_DIR="$(mktemp -d -t "${TOOL_NAME}-XXXXXX")"
DOWNLOAD_PATH="${DOWNLOAD_DIR}/${TOOL_NAME}.tar.gz"
echo "Downloading ${TOOL_NAME} ${TOOL_VERSION} for ${OS}/${ARCH} from ${DOWNLOAD_URL} to ${DOWNLOAD_PATH}..."
curl -fsSL -o "${DOWNLOAD_PATH}" "${DOWNLOAD_URL}"
echo "Download complete"

# Install the tool
echo "Installing to ${INSTALL_DIR}..."
mkdir -pv "${INSTALL_DIR}"
tar -xzvf "${DOWNLOAD_PATH}" -C "${INSTALL_DIR}" "${TOOL_NAME}"
echo "${INSTALL_DIR}" >> "${GITHUB_PATH}"
echo "Installation complete!"

# Cleanup
rm -rf "${DOWNLOAD_DIR}"

- name: Load environment values into environment variables
shell: bash
env:
ENV_LOADER_ENVIRONMENTS_DIRECTORY: "${{ inputs.environments-directory }}"
ENV_LOADER_ENVIRONMENT: "${{ inputs.environment-name }}"
ENV_LOADER_VALUE_SETS: "${{ inputs.value-set }}"
run: env-loader >> "${GITHUB_ENV}"
Loading