Skip to content

Commit

Permalink
fix: authenticate curl GET requests to GitHub with token
Browse files Browse the repository at this point in the history
  • Loading branch information
mtardy committed Oct 31, 2023
1 parent 6e3505b commit bdc8d9b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ on:
- '.github/workflows/test.yaml'

jobs:
build:
runs-on: ubuntu-20.04
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install bpftool
uses: ./

test-authenticated:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install bpftool
uses: ./
with:
token: ${{ secrets.GITHUB_TOKEN }}
16 changes: 14 additions & 2 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ inputs:
description: 'Installation path'
required: false
default: '/usr/local/bin'
token:
description: 'A GitHub token (e.g. secrets.GITHUB_TOKEN)'
required: false

runs:
using: "composite"
steps:
Expand All @@ -25,6 +29,14 @@ runs:
*) echo "Unsupported architecture: $(uname -m)"; exit 1;;
esac
- name: set authentication header
shell: bash
run: |
if [ -n "${{ inputs.token }}" ]; then
echo "AUTH_HEADER_OPTION=\"--header 'authorization: Bearer ${{ inputs.token }}'\"" >> $GITHUB_ENV
fi
- name: retrieve version
id: version
shell: bash {0}
Expand All @@ -35,7 +47,7 @@ runs:
retry_delay=1
while [ -z "$version" ] && [ "$attempt" -le "$max_attempts" ]; do
echo "Attempt $attempt: Fetching latest version from GitHub..."
response=$(curl -s https://api.github.com/repos/libbpf/bpftool/releases/latest)
response=$(curl -s $AUTH_HEADER_OPTION https://api.github.com/repos/libbpf/bpftool/releases/latest)
version=$(echo $response | jq -r '.tag_name | select (.!=null)')
if [ -z "$version" ]; then
delay=$((2 ** (attempt - 1) * retry_delay))
Expand Down Expand Up @@ -67,7 +79,7 @@ runs:
if: steps.cache-download.outputs.cache-hit != 'true'
shell: bash
run: |
curl -s -L https://github.com/libbpf/bpftool/releases/download/${{ steps.version.outputs.version }}/bpftool-${{ steps.version.outputs.version }}-${{ steps.arch.outputs.arch }}.tar.gz | tar xz
curl -s -L $AUTH_HEADER_OPTION https://github.com/libbpf/bpftool/releases/download/${{ steps.version.outputs.version }}/bpftool-${{ steps.version.outputs.version }}-${{ steps.arch.outputs.arch }}.tar.gz | tar xz
sudo install bpftool ${{ inputs.path }}
- name: check installation
Expand Down

0 comments on commit bdc8d9b

Please sign in to comment.