Skip to content

Commit

Permalink
add changes to workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
alchem0x2A committed Jan 16, 2024
1 parent c0767fa commit 670ab8b
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/api_version_probe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys

from packaging import version

from sparc.api import SparcAPI # Replace with your actual module import


def compare_versions():
default_version = SparcAPI().sparc_version
new_version = SparcAPI(json_api="parameters.json").sparc_version
print(f"Default api version: {default_version}, upstream version {new_version}")

if version.parse(default_version) < version.parse(new_version):
print(f"Version changed from {default_version} to {new_version}")
sys.exit(1) # Exit with a non-zero status to indicate change
else:
print("No version change")
sys.exit(0) # Exit with zero status to indicate no change


if __name__ == "__main__":
compare_versions()
69 changes: 69 additions & 0 deletions .github/workflows/update_api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Update JSON API (recurring job)

on:
push:
branches:
- master
pull_request:
branches:
- master
schedule:
- cron: '0 0 * * *' # Runs every day at midnight
workflow_dispatch:

jobs:
build-linux:
defaults:
run:
shell: bash -l {0}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: "3.10"
mamba-version: "*"
channels: conda-forge,alchem0x2a,defaults
channel-priority: true
activate-environment: sparc-api-test
- name: Install package
run: |
pip install -e ".[test]"
- name: Generate json api from github master
run: |
python -m sparc.docparser --git --include-subdirs
- name: Test if json api is newer than current
id: probe
run: |
python .github/workflows/api_version_probe.py || echo "::set-output name=update_needed::true"
continue-on-error: true
- name: Create Pull Request
if: steps.compare_versions.outputs.update_needed == 'true'
run: |
mv parameters.json sparc/sparc_json_api/
gh pr create --title "[PR Bot] New JSON API version" -R alchem0x2a/SPARC-X-API
- name: Create badges
run: |
mkdir -p badges/
# A coverage test badge
anybadge --value=$COVPERCENT --file=badges/coverage.svg coverage
# A version badge
PIPVER=`pip show sparc-x-api | grep Version | cut -d ' ' -f2`
anybadge --value=$PIPVER --file=badges/package.svg -l sparc-x-api
- name: Manually add git badges
run: |
# Assuming a badges branch already exists!
rm -rf /tmp/*.svg && cp badges/*.svg /tmp/
git fetch
git switch badges || { echo "Could not check out badges branch. Have you created it on remote?"; exit 1; }
git pull
cp /tmp/*.svg badges/ && git add -f badges/*.svg && rm -rf /tmp/*.svg
git config --global user.email "[email protected]"
git config --global user.name "Github Action Bot (badges only)"
git commit -m "Update badges from run ${RID}" || true
git push -u origin badges || true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RID: ${{ github.run_id }}

0 comments on commit 670ab8b

Please sign in to comment.