diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1cdb47f..eb572ff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,6 +64,7 @@ jobs: task-retries: '3' setup-gomplate: true setup-jq: true + setup-semver: true - name: Verify Setup run: | @@ -124,6 +125,9 @@ jobs: echo "::group::Verify JQ Installation" jq --version echo "::endgroup::" + echo "::group::Verify SemVer Installation" + semver --version + echo "::endgroup::" test-egress-policy: name: Test Egress Policy Input @@ -523,3 +527,33 @@ jobs: echo "Expected jq version ${EXPECTED_VERSION}, got: ${ACTUAL}" exit 1 fi + + test-setup-semver: + name: Test Setup SemVer Tools + runs-on: ubuntu-latest + steps: + - name: Harden Runner + id: harden-runner + uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 + with: + egress-policy: audit + + - name: Checkout Repository + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - name: Run Setup Semver + id: test-setup-semver + uses: ./ + with: + setup-semver: true + + - name: Verify SemVer Installation + run: | + INSTALLED_VERSION="$(semver --version)" + OUTPUT_VERSION="${{ steps.test-setup-semver.outputs.semver-version }}" + echo "semver reported: ${INSTALLED_VERSION}" + echo "semver output: ${OUTPUT_VERSION}" + if [[ "${INSTALLED_VERSION}" != "${OUTPUT_VERSION}" ]]; then + echo "Expected semver version ${OUTPUT_VERSION}, got: ${INSTALLED_VERSION}" + exit 1 + fi diff --git a/README.md b/README.md index f75e7cf..a7beaf5 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,17 @@ Common steps for initializing a job for GitHub actions. This composite action co > binary itself is the exact requested version, but the reported version > string cannot distinguish 1.7.0 from 1.7.1. +**SemVer** + +| Input | Description | Required | Default | +|--------------|---------------------------------|----------|---------| +| setup-semver | Whether to setup semver | No | false | + +> [!NOTE] +> `setup-semver` downloads the semver script directly from +> https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver +> and installs it to `/usr/local/bin/semver`. + ### Outputs **Checkout Outputs** @@ -198,6 +209,10 @@ Common steps for initializing a job for GitHub actions. This composite action co - `swift-toolchain`: JSON formatted toolchain snapshot metadata - `swift-sdks`: JSON formatted SDK snapshots metadata +**SemVer Outputs** + +- `semver-version`: The installed semver version + ## Examples **Node.js Project** @@ -246,6 +261,7 @@ Common steps for initializing a job for GitHub actions. This composite action co setup-python: 'true' python-version: '3.12' python-cache: 'pip' + setup-semver: 'true' ``` **Blocking Egress Traffic** diff --git a/action.yml b/action.yml index 323722b..aa7cf1f 100644 --- a/action.yml +++ b/action.yml @@ -163,6 +163,10 @@ inputs: description: 'Desired jq version (e.g. 1.8.1)' required: false default: '1.8.1' + setup-semver: + description: 'Whether to setup semver tool' + required: false + default: 'false' # expose outputs from the sub-actions outputs: @@ -232,6 +236,9 @@ outputs: swift-sdks: description: 'JSON formatted SDK snapshots metadata that were configured.' value: ${{ steps.setup-swift.outputs.sdks }} + semver-version: + description: 'The installed semver version.' + value: ${{ steps.setup-semver.outputs.version }} runs: using: 'composite' @@ -540,6 +547,26 @@ runs: jq --version echo "::endgroup::" + - name: Setup Semver + id: setup-semver + if: ${{ inputs.setup-semver == 'true' }} + shell: bash + run: | + echo "::group::Download SemVer Binary" + sudo curl -sSfL https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver \ + -o /tmp/semver || { echo "Failed to download semver binary"; exit 1; } + echo "::endgroup::" + + echo "::group::Change SemVer Binary Permissions" + sudo install -m 755 /tmp/semver /usr/local/bin/semver + echo "::endgroup::" + + echo "::group::Show SemVer Binary Version Info" + VERSION="$(/usr/local/bin/semver --version | tr -d '\n')" + echo "semver version: ${VERSION}" + echo "version=${VERSION}" >> "${GITHUB_OUTPUT}" + echo "::endgroup::" + branding: icon: 'arrow-up-right' color: 'green'