From c7790a4aafcf5c28c19dab2a86b7a008b625c605 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 4 Aug 2022 19:04:58 +0200 Subject: [PATCH 1/3] remove preview --- .github/workflows/preview.yml | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 .github/workflows/preview.yml diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index 9ed56d9b..00000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Deploy PR previews -concurrency: preview-${{ github.ref }} -on: - pull_request: - types: - - opened - - reopened - - synchronize - - closed -jobs: - deploy-preview: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - bundler-cache: true - - name: Setup Node - uses: actions/setup-node@v2 - with: - node-version: '14' - - run: npm install - - name: Build site - uses: limjh16/jekyll-action-ts@v2 - with: - enable_cache: true - - uses: rossjrw/pr-preview-action@v1 - with: - source-dir: . - preview-branch: gh-pages - umbrella-dir: _site/pr-preview - action: auto From 5583d8b3a59c903867e7fa434ccacdd88d159ea4 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 4 Aug 2022 19:51:17 +0200 Subject: [PATCH 2/3] use python script for updates --- .github/get_stats.py | 47 +++++++++++++++++++++++++++++++++ .github/workflows/get_stats.yml | 33 ++++------------------- 2 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 .github/get_stats.py diff --git a/.github/get_stats.py b/.github/get_stats.py new file mode 100644 index 00000000..8d33aad7 --- /dev/null +++ b/.github/get_stats.py @@ -0,0 +1,47 @@ +from enum import Enum +import json +from pathlib import Path +from urllib.request import urlopen, Request + +file_name = Path('_data/general/stats.yml') + +class ReturnMode(Enum): + data = 0 + header = 1 + +def get_data(url, key=None, default=0, mode: ReturnMode=ReturnMode.data): + """Fetches data from remote endpoint""" + httprequest = Request(url, headers={"Accept": "application/json"}) + + with urlopen(httprequest) as response: + if mode == ReturnMode.data: + data = response.read().decode() + data = json.loads(data) + + elif mode == ReturnMode.header: + data = dict(response.headers.items()) + + if key: + data = data.get(key, default) + + return data + +docker = get_data('https://hub.docker.com/v2/repositories/inventree/inventree', 'pull_count') +gh_data = get_data('https://api.github.com/repos/inventree/inventree') +stars = gh_data.get('stargazers_count', 0) +forks = gh_data.get('forks_count', 0) +# See https://stackoverflow.com/a/60458265/17860466 # to enabble anon add `&anon=true` +link = get_data('https://api.github.com/repos/inventree/inventree/contributors?per_page=1', mode=ReturnMode.header).get('Link') +contributors = link.split('page=')[-1].split('>')[0] + +# Write data +file_name.write_text( +f"""stats: + - name: Docker pulls + number: {docker} + - name: GitHub Stars + number: {stars} + - name: Forks + number: {forks} + - name: Contributors + number: {contributors}""") diff --git a/.github/workflows/get_stats.yml b/.github/workflows/get_stats.yml index 98f7b937..211b5ee5 100644 --- a/.github/workflows/get_stats.yml +++ b/.github/workflows/get_stats.yml @@ -2,28 +2,6 @@ name: Get stats on: workflow_dispatch: - inputs: - logLevel: - description: 'Log level' - required: true - default: 'warning' - type: choice - options: - - info - - warning - - debug - print_tags: - description: 'True to print to STDOUT' - required: true - type: boolean - tags: - description: 'Test scenario tags' - required: true - type: string - environment: - description: 'Environment to run tests against' - type: environment - required: true jobs: build: @@ -33,9 +11,8 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set selected color - run: echo '::set-output name=SELECTED_COLOR::green' - id: random-color-generator - - name: Docker stats - run: | - curl -s https://hub.docker.com/v2/repositories/inventree/inventree/ | jq -r ".pull_count" - id: docker-pulls + run: python .github/get_stats.py + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "[Bot] Updated the stats" + branch: main From a96fedd5e64f3f2049834baf5cb815bb1d4a6b8e Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 4 Aug 2022 21:25:25 +0200 Subject: [PATCH 3/3] run daily --- .github/workflows/get_stats.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/get_stats.yml b/.github/workflows/get_stats.yml index 211b5ee5..0f9eb4a1 100644 --- a/.github/workflows/get_stats.yml +++ b/.github/workflows/get_stats.yml @@ -2,6 +2,8 @@ name: Get stats on: workflow_dispatch: + schedule: + - cron: "0 0 * * *" jobs: build: