diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 25cb32e..034b93b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -432,3 +432,34 @@ jobs: - name: Verify Gomplate Installation run: | gomplate --version + + test-setup-gomplate-custom-version: + name: Test Setup Gomplate (custom version) + runs-on: ubuntu-latest + steps: + - name: Harden Runner + id: harden-runner + uses: step-security/harden-runner@ab7a9404c0f3da075243ca237b5fac12c98deaa5 # v2.19.3 + with: + egress-policy: audit + + - name: Checkout Repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + + - name: Run Setup Gomplate Action (non-default version) + uses: ./ + with: + setup-gomplate: true + gomplate-version: v4.3.3 + + - name: Verify Gomplate Version Matches Input + env: + EXPECTED_VERSION: 4.3.3 + run: | + ACTUAL="$(gomplate --version)" + ESCAPED_EXPECTED_VERSION="$(printf '%s\n' "${EXPECTED_VERSION}" | sed 's/[][(){}.^$*+?|\\]/\\&/g')" + echo "gomplate reported: ${ACTUAL}" + if ! echo "${ACTUAL}" | grep -qE "(^|[^0-9.])${ESCAPED_EXPECTED_VERSION}([^0-9.]|$)"; then + echo "Expected gomplate version ${EXPECTED_VERSION}, got: ${ACTUAL}" + exit 1 + fi diff --git a/README.md b/README.md index 093c79c..b2fd06b 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,10 @@ Common steps for initializing a job for GitHub actions. This composite action co **Gomplate** -| Input | Description | Required | Default | -|----------------|---------------------------|----------|---------| -| setup-gomplate | Whether to setup gomplate | No | false | +| Input | Description | Required | Default | +|------------------|---------------------------------------|----------|---------| +| setup-gomplate | Whether to setup gomplate | No | false | +| gomplate-version | Gomplate version to use (e.g. v5.0.0) | No | v5.0.0 | > [!NOTE] > `setup-gomplate` currently installs the Linux AMD64 gomplate release artifact. diff --git a/action.yml b/action.yml index e0016ba..3ff1904 100644 --- a/action.yml +++ b/action.yml @@ -143,6 +143,10 @@ inputs: description: 'Whether to setup gomplate' required: false default: 'false' + gomplate-version: + description: 'Gomplate version to use (e.g. v5.0.0)' + required: false + default: 'v5.0.0' task-version: description: 'Task version to use' required: false @@ -438,17 +442,24 @@ runs: id: setup-gomplate-params if: ${{ inputs.setup-gomplate == 'true' }} shell: bash + env: + GOMPLATE_VERSION: ${{ inputs.gomplate-version }} run: | echo "::group::Setting up gomplate" - echo "Version: v5.0.0" + echo "Version: ${GOMPLATE_VERSION}" echo "::endgroup::" - name: Install Gomplate id: setup-gomplate if: ${{ inputs.setup-gomplate == 'true' }} shell: bash + env: + GOMPLATE_VERSION: ${{ inputs.gomplate-version }} run: | - GOMPLATE_VERSION="v5.0.0" + if [[ ! "${GOMPLATE_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Invalid gomplate-version: '${GOMPLATE_VERSION}' (expected format vMAJOR.MINOR.PATCH, e.g. v5.0.0)" + exit 1 + fi GOMPLATE_RELEASE_URL="https://github.com/hairyhenderson/gomplate/releases/download/${GOMPLATE_VERSION}" curl -sSfL "${GOMPLATE_RELEASE_URL}/gomplate_linux-amd64" \