Skip to content

Commit 1a64151

Browse files
isometrymkushakov
andauthored
fix: private runner compatibility (#17)
* fix: use curl instead of github-cli * feat: add test action * fix: exclude man pages for compatibility with cli/cli * ci: add Makefile for local testing --------- Co-authored-by: Misha Kushakov <misha.kushakov@nexthink.com>
1 parent 66cc846 commit 1a64151

3 files changed

Lines changed: 84 additions & 7 deletions

File tree

.github/workflows/test.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test action
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
timeout-minutes: 5
10+
container:
11+
image: ubuntu:20.04
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- run: apt update && apt install -y curl jq unzip
16+
17+
- uses: ./
18+
with:
19+
name: cli/cli
20+
tool: gh
21+
- run: gh --version
22+
23+
- uses: ./
24+
with:
25+
name: aquasecurity/trivy
26+
- run: trivy --version
27+
28+
- uses: ./
29+
with:
30+
name: mikefarah/yq
31+
- run: yq --version
32+
33+
- uses: ./
34+
with:
35+
name: chainguard-dev/apko
36+
version: v0.19.0
37+
- run: apko version
38+
39+
- uses: ./
40+
with:
41+
name: nexthink-oss/ghup
42+
version: v0.12.0
43+
- run: ghup --version
44+
45+
- uses: ./
46+
with:
47+
name: gruntwork-io/terragrunt
48+
version: v0.67.16
49+
- run: terragrunt --version
50+
51+
- uses: ./
52+
with:
53+
name: yannh/kubeconform
54+
- run: kubeconform -v

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export GITHUB_TOKEN=$(shell gh auth token)
2+
3+
.PHONY: test
4+
test:
5+
@act push -j test --container-architecture=linux/$(shell uname -m) --secret GITHUB_TOKEN=${GITHUB_TOKEN}

setup.sh

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ info() {
1414
}
1515

1616
# Check for required commands
17-
command -v gh >/dev/null 2>&1 || error "GitHub CLI (gh) is required but not installed"
17+
command -v curl >/dev/null 2>&1 || error "curl is required but not installed"
1818
command -v jq >/dev/null 2>&1 || error "jq is required but not installed"
1919

2020
# Get inputs
@@ -53,13 +53,28 @@ case "${ARCH}" in
5353
;;
5454
esac
5555

56+
v3_api_call() {
57+
curl -sfL \
58+
-H "Accept: application/vnd.github+json" \
59+
-H "Authorization: Bearer ${GH_TOKEN}" \
60+
-H "X-GitHub-Api-Version: 2022-11-28" \
61+
"https://api.github.com/$1"
62+
}
63+
64+
download_release() {
65+
local url="${1:?download url required}"
66+
local out="${2:?asset name required}"
67+
info "Downloading ${url} to ${out}"
68+
curl -sSL -H "Authorization: token ${GH_TOKEN}" -o "${out}" "${url}"
69+
}
70+
5671
# Get release information using GitHub CLI
57-
if [ "${VERSION}" = "latest" ]; then
58-
RELEASE_DATA=$(gh api "repos/${OWNER}/${REPO}/releases/latest")
72+
if [[ "${VERSION}" = "latest" ]]; then
73+
RELEASE_DATA=$(v3_api_call "repos/${OWNER}/${REPO}/releases/latest")
5974
VERSION=$(jq -r '.tag_name' <<< "${RELEASE_DATA}")
6075
info "Resolved latest version: ${VERSION}"
6176
else
62-
RELEASE_DATA=$(gh api "repos/${OWNER}/${REPO}/releases/tags/${VERSION}")
77+
RELEASE_DATA=$(v3_api_call "repos/${OWNER}/${REPO}/releases/tags/${VERSION}")
6378
fi
6479

6580
# Create cache directory
@@ -85,23 +100,26 @@ else
85100

86101
# Create temporary directory
87102
TMP_DIR=$(mktemp -d)
88-
echo "Temporary directory: ${TMP_DIR}"
103+
info "Temporary directory: ${TMP_DIR}"
89104
cd "${TMP_DIR}"
90105

91106
# Download and extract asset using gh cli
92107
info "Fetching ${ASSET_NAME} from ${OWNER}/${REPO}#${VERSION}"
93-
gh release download "${VERSION}" -R "${OWNER}/${REPO}" -p "${ASSET_NAME}"
108+
DOWNLOAD_URL=$(jq -r --arg asset "${ASSET_NAME}" '.assets[] | select(.name == $asset) | .browser_download_url' <<< "${RELEASE_DATA}")
109+
download_release "${DOWNLOAD_URL}" "${ASSET_NAME}"
94110

95111
if [[ "${ASSET_NAME}" == *.zip ]]; then
96112
info "Extracting ${ASSET_NAME}"
97113
unzip -q "${ASSET_NAME}"
98114
elif [[ "${ASSET_NAME}" == *.tar.gz ]]; then
99115
info "Extracting ${ASSET_NAME}"
116+
tar tzf "${ASSET_NAME}"
100117
tar xzf "${ASSET_NAME}"
101118
fi
102119

103120
# Find tool binary
104-
TOOL_PATH=$(find . -type f -name "${TOOL_NAME}*" | grep -Ev '[.](tar[.]gz|zip)$' | head -n1)
121+
TOOL_PATH=$(find . -type f -name "${TOOL_NAME}*" -a \! -name "*.[0-9]" | grep -Ev '[.](tar[.]gz|zip)$' | head -n1)
122+
info "Detected tool binary: ${TOOL_PATH}"
105123
[[ -z "${TOOL_PATH}" ]] && error "Tool binary '${TOOL_NAME}' not found in extracted path"
106124

107125
# Copy to cache directory

0 commit comments

Comments
 (0)