Skip to content

Update download counts #34

Update download counts

Update download counts #34

Workflow file for this run

name: Update download counts
on:
schedule:
- cron: '0 0 * * *' # Runs at 00:00 UTC every day
workflow_dispatch: # Allows manual triggering
jobs:
run-binary:
runs-on: ubuntu-latest
steps:
- name: Restore cached binary
id: cache
continue-on-error: true
uses: actions/cache/restore@v4
with:
path: ./nexus-mods.gz
key: ${{ vars.CACHED_BIN }}
- name: Decompress binary
if: steps.cache.outputs.cache-hit
run: gunzip -f ./nexus-mods.gz
- name: Check for update
id: check_ver
if: steps.cache.outputs.cache-hit
run: |
set +e
chmod +x ./nexus-mods
./nexus-mods --remote version
exit_code=$?
echo "exit_code=$exit_code" >> $GITHUB_OUTPUT
if [ "$exit_code" -eq 0 ]; then
echo "Nexus Badges up to date"
elif [ "$exit_code" -eq 70 ]; then
echo "New Nexus Badges version available"
fi
- name: Download latest binary
id: download_latest
if: ${{ !steps.cache.outputs.cache-hit || steps.check_ver.outputs.exit_code == '70' }}
run: wget "https://drive.google.com/uc?export=download&id=1yHF8B0YynKglsOOsGAb5VXzOCAsCKW5o" -O ./nexus-mods.gz
- name: Cache up-to-date binary
if: steps.download_latest.outcome != 'skipped'
uses: actions/cache/save@v4
with:
path: ./nexus-mods.gz
key: ${{ runner.os }}-nexus-badges-${{ github.run_id }}-${{ github.run_attempt }}-binary
- name: Update Repository Variable
id: update_cache_key
if: steps.download_latest.outcome != 'skipped'
run: |
set +e
response=$(curl -s -w "%{http_code}" -X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GIT_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/actions/variables/CACHED_BIN \
-d '{"name": "CACHED_BIN", "value": "${{ runner.os }}-nexus-badges-${{ github.run_id }}-${{ github.run_attempt }}-binary"}')
status=$(echo "$response" | tail -n 1)
if [ "$status" -eq 204 ]; then
echo "Updated Repository variable: 'CACHED_BIN'"
else
echo "HTTP response: $(echo "$response" | head -n -1 | jq -r '.message')"
fi
echo "status=$status" >> $GITHUB_OUTPUT
- name: Create Repository Variable
if: ${{ steps.update_cache_key.outcome != 'skipped' && steps.update_cache_key.outputs.status != '204' }}
continue-on-error: true
run: |
response=$(curl -s -w "%{http_code}" -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GIT_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/actions/variables \
-d '{"name": "CACHED_BIN", "value": "${{ runner.os }}-nexus-badges-${{ github.run_id }}-${{ github.run_attempt }}-binary"}')
if [ $(echo "$response" | tail -n 1) -eq 204 ]; then
echo "Created Repository variable: 'CACHED_BIN'"
else
echo "HTTP response: $(echo "$response" | head -n -1 | jq -r '.message')"
fi
- name: Decompress binary
if: ${{ !steps.cache.outputs.cache-hit || steps.check_ver.outputs.exit_code == '70' }}
run: gunzip -f ./nexus-mods.gz
- name: Run binary
env:
NEXUS_KEY: ${{ secrets.NEXUS_KEY }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
GIST_ID: ${{ vars.GIST_ID }}
TRACKED_MODS: ${{ vars.TRACKED_MODS }}
run: |
chmod +x ./nexus-mods
./nexus-mods --remote