Skip to content

Commit

Permalink
github action: reusing the workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jan 11, 2024
1 parent 1106ee2 commit 0d60f73
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name: Update Catalogue
name: (reuse) update

on:
push:
branches:
- master
workflow_dispatch:
workflow_call:
inputs:
check:
type: boolean
required: true
description: If should do the check part
squash_history:
description: Select if you want the history to be squashed
type: boolean
required: false
default: false
description: SQUASH_HISTORY option for the branch push

jobs:
update:
Expand All @@ -23,7 +25,7 @@ jobs:
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
key: ${{ runner.os }}-pip-${{ hashFiles('scripts/**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-:
Expand All @@ -39,10 +41,14 @@ jobs:
cd ./scripts
pip install -r requirements.txt
- name: Check, fetch data and generate doc
- name: Do the update
run: |
cd ./scripts
python main.py all
if [ "${{ inputs.check }}" = "true" ]; then
python main.py all
else
python main.py all --no-check
fi
env:
github_api_token: ${{ secrets.TOKEN_FOR_GITHUB_API }}

Expand All @@ -53,7 +59,7 @@ jobs:
BRANCH: meta
FOLDER: meta
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SQUASH_HISTORY: ${{ github.event.inputs.squash_history }}
SQUASH_HISTORY: ${{ inputs.squash_history }}
SKIP_EMPTY_COMMITS: true

- name: Deploy doc
Expand All @@ -63,5 +69,5 @@ jobs:
BRANCH: catalogue
FOLDER: catalogue
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SQUASH_HISTORY: ${{ github.event.inputs.squash_history }}
SQUASH_HISTORY: ${{ inputs.squash_history }}
SKIP_EMPTY_COMMITS: true
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Catalogue CI

on:
push:
branches:
- master
workflow_dispatch:
inputs:
squash_history:
description: Select if you want the history to be squashed
type: boolean
default: false

jobs:
update:
uses: ./.github/workflows/_update.yml
secrets: inherit
with:
check: true
squash_history: ${{ input.squash_history }}
64 changes: 5 additions & 59 deletions .github/workflows/scheduled_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,8 @@ on:

jobs:
update:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-:
- name: Pull previous meta
uses: actions/checkout@v3
with:
ref: meta
path: meta

- name: Prepare runtime
run: |
rm -rf ./meta/.git
cd ./scripts
pip install -r requirements.txt
- name: Fetch data
run: |
cd ./scripts
python main.py data
env:
github_api_token: ${{ secrets.TOKEN_FOR_GITHUB_API }}

- name: Generate doc
run: |
cd ./scripts
python main.py doc
env:
github_api_token: ${{ secrets.TOKEN_FOR_GITHUB_API }}

- name: Deploy meta
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: meta
FOLDER: meta
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SQUASH_HISTORY: true
SKIP_EMPTY_COMMITS: true

- name: Deploy doc
uses: s0/git-publish-subdir-action@develop
env:
REPO: self
BRANCH: catalogue
FOLDER: catalogue
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SQUASH_HISTORY: true
SKIP_EMPTY_COMMITS: true
uses: ./.github/workflows/_update.yml
secrets: inherit
with:
check: false
squash_history: false
7 changes: 5 additions & 2 deletions scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async def async_main(parser: argparse.ArgumentParser, args: argparse.Namespace):
elif args.subparser_name == 'doc':
await generate_doc(target_ids)
elif args.subparser_name == 'all':
await check(target_ids)
if not args.no_check:
await check(target_ids)
await fetch_and_store_data(target_ids)
await generate_doc(target_ids)
else:
Expand All @@ -56,7 +57,9 @@ def main():
subparsers.add_parser('check', help='Check the correctness of files in "plugins/"')
subparsers.add_parser('data', help='Fetch all needed data of plugins from github, and save to "meta/"')
subparsers.add_parser('doc', help='Generate user friendly plugin catalogue doc to "catalogue/"')
subparsers.add_parser('all', help='Run everything above: check, fetch, doc')

all_parser = subparsers.add_parser('all', help='Run everything above: check, fetch, doc')
all_parser.add_argument('--no-check', action='store_true', help='Skip the check')

args = parser.parse_args()
asyncio.run(async_main(parser, args))
Expand Down

0 comments on commit 0d60f73

Please sign in to comment.