Parcourir la source

#660 testing citation update

Rodja Trappe il y a 2 ans
Parent
commit
4baa55b36e

+ 0 - 4
.github/workflows/publish.yml

@@ -23,10 +23,6 @@ jobs:
       - name: get version
         id: get_version
         run: echo "VERSION=$(echo ${GITHUB_REF/refs\/tags\//})" >> $GITHUB_ENV
-      - name: Update Citation
-        run: |
-          pip install PyYAML
-          python .github/workflows/update_citation.py
       - name: set version
         run: poetry version ${{ env.VERSION }}
       - name: publish

+ 21 - 10
.github/workflows/update_citation.py

@@ -2,16 +2,27 @@ import yaml
 import os
 from datetime import datetime
 
-with open('CITATION.cff', 'r') as f:
-    citation = yaml.safe_load(f)
 
-citation['version'] = os.environ['GITHUB_REF'].split('/')[-1]
-citation['date-released'] = datetime.utcnow().strftime('%Y-%m-%d')
-# citation['doi'] = 'doi base (not ready yet)' + os.environ['GITHUB_REF'].split('/')[-1]
+import os
+import requests
+import yaml
+
+
+def get_infos() -> str:
+    headers = {'Accept': 'application/json'}
+    params = {
+        'access_token': os.environ['ZENODO_TOKEN'],
+        'q': 'nicegui', 'sort': 'mostrecent', 'status': 'published'
+    }
+    response = requests.get('https://zenodo.org/api/records', params=params, headers=headers)
+    response.raise_for_status()
+    data = response.json()[0]['metadata']
+    return data['doi'], data['version'], data['publication_date']
 
-with open('CITATION.cff', 'w') as f:
-    yaml.dump(citation, f, sort_keys=False, default_flow_style=False)
 
-os.system('git add CITATION.cff')
-os.system('git commit -m "Update CITATION.cff for release"')
-os.system('git push')
+if __name__ == '__main__':
+    with open('CITATION.cff', 'r') as file:
+        citation = yaml.safe_load(file)
+    citation['doi'], citation['version'],  citation['date-released'] = get_infos()
+    with open('citation.cff', 'w') as file:
+        yaml.dump(citation, file, sort_keys=False, default_flow_style=False)

+ 38 - 0
.github/workflows/update_citation.yml

@@ -0,0 +1,38 @@
+name: Update Citation
+
+on: [push]
+
+# on:
+#   release:
+#     types:
+#       - published
+
+jobs:
+  update_citation:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v2
+
+      - name: Set up Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: 3.11
+
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          pip install requests PyYAML
+
+      - name: Update Citation.cff
+        env:
+          ZENODO_TOKEN: ${{ secrets.ZENODO_TOKEN }}
+        run: python .github/update_citation.py
+
+      - name: Commit and push changes
+        run: |
+          git config --global user.name "github-actions[bot]"
+          git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
+          git add citation.cff
+          git commit -m "Update citation.cff"
+          git push