diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd86a22..e50ad12 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -69,8 +69,8 @@ jobs: matrix: version: - "latest" - - "3.5.0" - - "v3.5.0" + - "4.2.0" + - "v4.2.0" runs-on: ubuntu-latest env: diff --git a/README.md b/README.md index e4cee57..7c50083 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,17 @@ GitHub Actions for running [CodSpeed](https://codspeed.io) in your CI. # Only used if the `mongodb` instrument is enabled. mongo_uri_env_name: "" + # [OPTIONAL] + # Enable caching of instrument installations (like valgrind or perf) to speed up + # subsequent workflow runs. Set to 'false' to disable caching. Defaults to 'true'. + cache-instruments: "true" + + # [OPTIONAL] + # The directory to use for caching installations of instruments (like valgrind or perf). + # This will speed up subsequent workflow runs by reusing previously installed instruments. + # Defaults to $HOME/.cache/codspeed-action if not specified. + instruments-cache-dir: "" + # [OPTIONAL] # A custom upload url, only if you are using an on premise CodSpeed instance upload-url: "" diff --git a/action.yml b/action.yml index e83290c..574a218 100644 --- a/action.yml +++ b/action.yml @@ -46,15 +46,51 @@ inputs: Comma separated list of instruments to enable. The following instruments are available: - `mongodb`: MongoDB instrumentation, requires the MongoDB instrument to be enabled for the organization in CodSpeed required: false + mongo-uri-env-name: description: | The name of the environment variable containing the MongoDB URI. Requires the `mongodb` instrument to be activated in `instruments`. If the instrumentation is enabled and this value is not set, the user will need to dynamically provide the MongoDB URI to the CodSpeed runner. required: false + cache-instruments: + description: | + Enable caching of instrument installations (like valgrind or perf) to speed up subsequent workflow runs. Set to 'false' to disable caching. + required: false + default: "true" + + instruments-cache-dir: + description: | + The directory to use for caching installations of instruments (like valgrind or perf). Defaults to `$HOME/.cache/codspeed-action`. + required: false + default: "~/.cache/codspeed-action" + runs: using: "composite" steps: + - name: Determine runner and kernel version + id: versions + shell: bash + run: | + RUNNER_VERSION="${{ inputs.runner-version }}" + if [ -z "$RUNNER_VERSION" ]; then + RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) + fi + echo "runner-version=$RUNNER_VERSION" >> $GITHUB_OUTPUT + + # Get kernel version for cache key + KERNEL_VERSION=$(uname -r) + echo "kernel-version=$KERNEL_VERSION" >> $GITHUB_OUTPUT + + - name: Cache CodSpeed instruments + if: inputs.cache-instruments == 'true' + uses: actions/cache@v4 + with: + path: ${{ inputs.instruments-cache-dir }} + key: codspeed-instruments-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}-${{ steps.versions.outputs.runner-version }} + restore-keys: | + codspeed-instruments-${{ runner.os }}-${{ runner.arch }}-${{steps.versions.outputs.kernel-version }}- + - shell: bash env: GH_MATRIX: "${{ toJson(matrix) }}" @@ -68,12 +104,48 @@ runs: fi # Configure and run codspeed-runner - RUNNER_VERSION="${{ inputs.runner-version }}" - if [ -z "$RUNNER_VERSION" ]; then - RUNNER_VERSION=$(cat $GITHUB_ACTION_PATH/.codspeed-runner-version) - elif [ "$RUNNER_VERSION" != "latest" ]; then + RUNNER_VERSION="${{ steps.versions.outputs.runner-version }}" + + # Detect version type (priority: latest > version number > branch/rev prefixes) + if [ "$RUNNER_VERSION" = "latest" ]; then + VERSION_TYPE="latest" + elif echo "$RUNNER_VERSION" | grep -qE '^v?[0-9]+\.[0-9]+\.[0-9]+'; then + # Version number (with or without 'v' prefix) + VERSION_TYPE="release" # Strip 'v' prefix if present to normalize version format RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') + elif echo "$RUNNER_VERSION" | grep -q '^branch:'; then + VERSION_TYPE="branch" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^branch://') + elif echo "$RUNNER_VERSION" | grep -q '^rev:'; then + VERSION_TYPE="rev" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^rev://') + else + # Default to release version + VERSION_TYPE="release" + RUNNER_VERSION=$(echo "$RUNNER_VERSION" | sed 's/^v//') + fi + + # Install the CodSpeedHQ/runner + if [ "$VERSION_TYPE" = "latest" ]; then + curl -fsSL http://github.com/CodSpeedHQ/runner/releases/latest/download/codspeed-runner-installer.sh | bash -s -- --quiet + elif [ "$VERSION_TYPE" = "branch" ]; then + # Install from specific branch using cargo + source $HOME/.cargo/env + cargo install --git https://github.com/CodSpeedHQ/runner --branch "$RUNNER_VERSION" + elif [ "$VERSION_TYPE" = "rev" ]; then + # Install from specific commit/rev using cargo + source $HOME/.cargo/env + cargo install --git https://github.com/CodSpeedHQ/runner --rev "$RUNNER_VERSION" + else + # Release version + head_status=$(curl -I -fsSL -w "%{http_code}" -o /dev/null https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh) + if [ "$head_status" -eq 404 ]; then + echo "Error: Version $RUNNER_VERSION is not available in https://github.com/CodSpeedHQ/runner/releases, please a correct version." + exit 1 + else + curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet + fi fi # Get the runner arguments @@ -96,18 +168,8 @@ runs: if [ -n "${{ inputs.mongo-uri-env-name }}" ]; then RUNNER_ARGS="$RUNNER_ARGS --mongo-uri-env-name=${{ inputs.mongo-uri-env-name }}" fi - - # Install the CodSpeedHQ/runner - if [ "$RUNNER_VERSION" = "latest" ]; then - curl -fsSL http://github.com/CodSpeedHQ/runner/releases/latest/download/codspeed-runner-installer.sh | bash -s -- --quiet - else - head_status=$(curl -I -fsSL -w "%{http_code}" -o /dev/null https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh) - if [ "$head_status" -eq 404 ]; then - echo "Error: Version $RUNNER_VERSION is not available in https://github.com/CodSpeedHQ/runner/releases, please a correct version." - exit 1 - else - curl -fsSL https://github.com/CodSpeedHQ/runner/releases/download/v$RUNNER_VERSION/codspeed-runner-installer.sh | bash -s -- --quiet - fi + if [ "${{ inputs.cache-instruments }}" = "true" ] && [ -n "${{ inputs.instruments-cache-dir }}" ]; then + RUNNER_ARGS="$RUNNER_ARGS --setup-cache-dir=${{ inputs.instruments-cache-dir }}" fi # Run the benchmarks