Update download counts #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update download counts | |
on: | |
schedule: | |
- cron: '0 0,8,16 * * *' # every 8 hours | |
workflow_dispatch: | |
jobs: | |
update-remote-gist: | |
runs-on: ubuntu-latest | |
env: | |
GIT_TOKEN: ${{ secrets.DOWNLOAD_COUNT_GITHUB_PAT }} | |
steps: | |
- name: Restore cached binary | |
id: cache | |
continue-on-error: true | |
uses: actions/cache/restore@v4 | |
with: | |
path: ./nexus-mods | |
key: nexus-badges-${{ runner.os }}-KEY_SHOULD_NOT_EXIST-binary-v1.0.0 | |
restore-keys: nexus-badges-${{ runner.os }}-binary-v | |
- name: Make cached binary file executable | |
if: steps.cache.outputs.cache-matched-key != null | |
run: | | |
chmod +x ./nexus-mods | |
- name: Check for update | |
id: check_ver | |
if: steps.cache.outputs.cache-matched-key != null | |
run: | | |
set +e | |
./nexus-mods --remote version | |
echo "exit_code=$?" >> $GITHUB_OUTPUT | |
- name: Download latest binary | |
id: download_latest | |
if: ${{ steps.cache.outputs.cache-matched-key == null || steps.check_ver.outputs.exit_code == '70' }} | |
continue-on-error: true | |
run: | | |
wget "https://github.com/WardLordRuby/nexus_badges/releases/latest/download/nexus_badges_linux_amd64.gz" -O ./nexus-mods.gz | |
- name: Decompress latest binary & generate cache key | |
id: decompress_and_cache_key | |
if: steps.download_latest.outcome == 'success' | |
run: | | |
gunzip -f ./nexus-mods.gz | |
chmod +x ./nexus-mods | |
VERSION_OUTPUT_RAW=$(./nexus-mods version) | |
VERSION_OUTPUT_SPLIT=($VERSION_OUTPUT_RAW) | |
echo "cache_key_new=nexus-badges-${{ runner.os }}-binary-${VERSION_OUTPUT_SPLIT[1]}" >> $GITHUB_OUTPUT | |
- name: Cache latest binary | |
id: cache_latest | |
if: steps.download_latest.outcome == 'success' | |
uses: actions/cache/save@v4 | |
with: | |
path: ./nexus-mods | |
key: ${{ steps.decompress_and_cache_key.outputs.cache_key_new }} | |
- name: Run binary | |
env: | |
NEXUS_KEY: ${{ secrets.NEXUS_API_KEY }} | |
GIST_ID: ${{ vars.DOWNLOAD_COUNT_GIST_ID }} | |
TRACKED_MODS: ${{ vars.DOWNLOAD_COUNT_MODS_TO_UPDATE }} | |
run: ./nexus-mods --remote |