Skip to content

Commit

Permalink
Use GitHub Token to get higher rate limit
Browse files Browse the repository at this point in the history
  • Loading branch information
plengauer authored Apr 19, 2024
1 parent f156644 commit e698e74
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ jobs:
working-directory: ./package
steps:
- uses: actions/checkout@v4
- run: sudo apt-get update
- run: sudo apt-get -y dist-upgrade
- run: sudo apt-get install devscripts debhelper
- run: sed -i "s/__VERSION__/$(cat ../VERSION)/g" DEBIAN/control
- run: dpkg-deb --root-owner-group --build . ../package.deb
Expand Down
34 changes: 21 additions & 13 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,28 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- run: sudo apt-get update
- run: sudo apt-get -y dist-upgrade
- uses: actions/download-artifact@v4
with:
name: package.deb
- run: sudo apt-get -y install --allow-unauthenticated ./package.deb
- run: sudo apt-get -y install ./package.deb
- run: echo "deb [arch=all] http://127.0.0.1:8000/ stable main" | sudo tee /etc/apt/sources.list.d/example.list
- run: sudo apt-get update --allow-insecure-repositories
- run: sudo apt-get -y install --allow-unauthenticated auto-management
- run: sudo apt-get -y remove gitaptly

test-token:
needs: build
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y debconf-utils
- run: echo gitaptly gitaptly/GITHUB_API_TOKEN string $GITHUB_API_TOKEN | sudo debconf-set-selections
env:
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v4
with:
name: package.deb
- run: sudo apt-get -y install ./package.deb
- run: echo "deb [arch=all] http://127.0.0.1:8000/ stable main" | sudo tee /etc/apt/sources.list.d/example.list
- run: sleep 10
- run: sudo apt-get update --allow-insecure-repositories
- run: sudo apt-get -y install --allow-unauthenticated auto-management
- run: sudo apt-get -y remove gitaptly
Expand All @@ -27,15 +41,12 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- run: sudo apt-get update
- run: sudo apt-get -y dist-upgrade
- run: wget -O - https://raw.githubusercontent.com/plengauer/opentelemetry-bash/main/INSTALL.sh | sh -E
- uses: actions/download-artifact@v4
with:
name: package.deb
- run: sudo apt-get -y install --allow-unauthenticated ./package.deb
- run: sudo apt-get -y install ./package.deb
- run: echo "deb [arch=all] http://127.0.0.1:8000/ stable main" | sudo tee /etc/apt/sources.list.d/example.list
- run: sleep 10
- run: sudo apt-get update --allow-insecure-repositories
- run: sudo apt-get -y install --allow-unauthenticated auto-management
- run: sudo apt-get -y remove gitaptly
Expand All @@ -44,16 +55,13 @@ jobs:
needs: build
runs-on: ubuntu-latest
steps:
- run: sudo apt-get update
- run: sudo apt-get -y dist-upgrade
- run: wget https://github.com/plengauer/GitAptly/releases/download/v2.0.0/gitaptly_2.0.0.deb
- run: sudo apt-get -y install --allow-unauthenticated ./gitaptly_2.0.0.deb
- run: sudo apt-get -y install ./gitaptly_2.0.0.deb
- uses: actions/download-artifact@v4
with:
name: package.deb
- run: sudo apt-get -y install --allow-unauthenticated ./package.deb
- run: sudo apt-get -y install ./package.deb
- run: echo "deb [arch=all] http://127.0.0.1:8000/ stable main" | sudo tee /etc/apt/sources.list.d/example.list
- run: sleep 10
- run: sudo apt-get update --allow-insecure-repositories
- run: sudo apt-get -y install --allow-unauthenticated auto-management
- run: sudo apt-get -y remove gitaptly
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.1
3.10.0
4 changes: 4 additions & 0 deletions package/DEBIAN/config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ db_beginblock
db_input high gitaptly/MODE || true
db_endblock

db_beginblock
db_input high gitaptly/GITHUB_API_TOKEN || true
db_endblock

db_beginblock
db_input high gitaptly/OTLP_TRACES_ENDPOINT || true
db_endblock
Expand Down
2 changes: 2 additions & 0 deletions package/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ db_get gitaptly/PORT
echo "PORT=$RET" >> /opt/gitaptly/env
db_get gitaptly/MODE
echo "MODE=$RET" >> /opt/gitaptly/env
db_get gitaptly/GITHUB_API_TOKEN
echo "GITHUB_API_TOKEN=\"$RET\"" >> /opt/gitaptly/env
db_get gitaptly/OTLP_TRACES_ENDPOINT
echo "OTLP_TRACES_ENDPOINT=\"$RET\"" >> /opt/gitaptly/env
db_get gitaptly/OTLP_TRACES_HEADER
Expand Down
6 changes: 6 additions & 0 deletions package/DEBIAN/templates
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Default: proxy
Description: Mode:
Select whether the repository should cache deb files on disk or act as a pure proxy.

Template: gitaptly/GITHUB_API_TOKEN
Type: string
Default:
Description: GitHub API Token:
A valid GitHub API Token. GitAptly only accesses publicly available information, making the token optional. However, providing a token drastically increases the rate limit GitHub imposes.

Template: gitaptly/OTLP_TRACES_ENDPOINT
Type: string
Default:
Expand Down
10 changes: 8 additions & 2 deletions package/usr/bin/gitaptly_scan
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/bash -e
source /opt/gitaptly/env
if [ -n "$GITHUB_API_TOKEN" ]; then
auth_header="Authorization: Bearer $GITHUB_API_TOKEN"
else
auth_header='foo: bar'
fi
per_page=100
url="https://api.github.com/repos/$1/releases?per_page=$per_page"
curl --no-progress-meter --fail --head "$url" \
curl --no-progress-meter --fail --head -H "$auth_header" "$url" \
| grep '^link: ' | cut -d ' ' -f 2- | tr -d ' <>' | tr ',' '\n' \
| grep 'rel="last"' | cut -d ';' -f1 | cut -d '?' -f 2- | tr '&' '\n' \
| grep '^page=' | cut -d = -f 2 \
| xargs seq 1 | xargs parallel -q curl --no-progress-meter --fail "$url"\&page={} ::: \
| xargs seq 1 | xargs parallel -q curl --no-progress-meter --fail -H "$auth_header" "$url"\&page={} ::: \
| jq '.[] | .assets[] | .browser_download_url' -r | (grep '.deb$' || true)

0 comments on commit e698e74

Please sign in to comment.