Update download counts #7
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: ${{ vars.DOWNLOAD_COUNT_CACHED_BIN }} | |
- name: Make cached binary file executable | |
if: steps.cache.outputs.cache-hit | |
run: | | |
chmod +x ./nexus-mods | |
- name: Check for update | |
id: check_ver | |
if: steps.cache.outputs.cache-hit | |
run: | | |
set +e | |
./nexus-mods --remote version | |
echo "exit_code=$?" >> $GITHUB_OUTPUT | |
- name: Download latest binary | |
id: download_latest | |
if: ${{ !steps.cache.outputs.cache-hit || steps.check_ver.outputs.exit_code == '70' }} | |
continue-on-error: true | |
run: | | |
wget "https://drive.google.com/uc?export=download&id=1yHF8B0YynKglsOOsGAb5VXzOCAsCKW5o" -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: Set cache key | |
if: ${{ !steps.cache.outputs.cache-hit && steps.cache_latest.outcome == 'success' }} | |
continue-on-error: true | |
env: | |
REPO_FULL: ${{ github.repository }} | |
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: ./nexus-mods --remote update-cache-key --new ${{ steps.decompress_and_cache_key.outputs.cache_key_new }} | |
- name: Remove old cache & update cache key | |
if: ${{ steps.cache.outputs.cache-hit && steps.cache_latest.outcome == 'success' }} | |
continue-on-error: true | |
env: | |
REPO_FULL: ${{ github.repository }} | |
GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: ./nexus-mods --remote update-cache-key --old ${{ vars.DOWNLOAD_COUNT_CACHED_BIN }} --new ${{ 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 |