Skip to content

Update the toolctl API #560

Update the toolctl API

Update the toolctl API #560

Workflow file for this run

name: CI
on:
pull_request:
branches: [main]
jobs:
detect-updated-tools:
runs-on: ubuntu-latest
outputs:
any_updated: ${{steps.updated-tools.outputs.any_updated}}
tools: ${{steps.updated-tools.outputs.tools}}
env:
TOOL_GLOB: v0/*/**
TOOL_REGEX: v0/([^/]+)/
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
- name: Check out the API
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Detect all changed files
id: changed-files
uses: tj-actions/changed-files@1c938490c880156b746568a518594309cfb3f66b # v40.2.1
with:
files: |
${{env.TOOL_GLOB}}
- name: Detect all updated tools
id: updated-tools
if: ${{steps.changed-files.outputs.any_changed == 'true'}}
run: |
# Check if we're running Bash 4 or higher
if [ -z "$BASH_VERSION" ] || [ "${BASH_VERSION:0:1}" -lt "4" ]; then
echo "Bash 4 or higher is required."
exit 1
fi
# Extract the names of all updated tools
declare -A tools
for path in ${{steps.changed-files.outputs.all_changed_files}}; do
if [[ $path =~ ${{env.TOOL_REGEX}} ]]; then
tools["${BASH_REMATCH[1]}"]=""
else
echo "$path doesn't match" >&2
fi
done
# Set the GitHub Actions output
echo "any_updated=true" >> $GITHUB_OUTPUT
echo "tools=${!tools[@]}" >> $GITHUB_OUTPUT
install-test:
needs: [detect-updated-tools]
if: ${{needs.detect-updated-tools.outputs.any_updated == 'true'}}
strategy:
matrix:
os: [ubuntu-latest, macos-12]
runs-on: ${{matrix.os}}
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
- name: Add ~/.local/bin to the PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Install toolctl
run: curl -fsSL https://raw.githubusercontent.com/toolctl/install/main/install | sh
- name: Set the LocalAPIBasePath
env:
TOOLCTL_API_VERSION: v0
run: |
config_dir="$HOME/.config/toolctl"
mkdir -p "${config_dir}"
echo LocalAPIBasePath: "${GITHUB_WORKSPACE}/${TOOLCTL_API_VERSION}" > "${config_dir}/config.yaml"
- name: Check out the repo
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install the latest version of each tool
run: toolctl install ${{needs.detect-updated-tools.outputs.tools}} --local
- name: Test the discover mechanism for each tool on Linux
if: runner.os == 'Linux'
run: toolctl api discover ${{needs.detect-updated-tools.outputs.tools}} --os linux
- name: Test the discover mechanism for each tool on macOS
if: runner.os == 'macOS'
run: toolctl api discover ${{needs.detect-updated-tools.outputs.tools}} --os darwin