Skip to content

Commit

Permalink
replaced wrong content
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-jettka committed Nov 29, 2024
1 parent 6260414 commit 5c10f24
Showing 1 changed file with 36 additions and 51 deletions.
87 changes: 36 additions & 51 deletions .github/workflows/update-citation.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,36 @@
import os
import requests
import yaml

# Repository details
repo_owner = os.getenv("GITHUB_REPOSITORY").split('/')[0]
repo_name = os.getenv("GITHUB_REPOSITORY").split('/')[1]
token = os.getenv("GITHUB_TOKEN")

# GitHub API URL
api_url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/contributors"

# Fetch contributors
response = requests.get(api_url, headers={"Authorization": f"token {token}"})
if response.status_code != 200:
raise Exception(f"Failed to fetch contributors: {response.json()}")

contributors = response.json()

# Extract contributor details
new_authors = []
for contributor in contributors:
new_authors.append({
"name": contributor.get("login"),
"orcid": None # ORCID integration can be added here
})

# Load existing CITATION.cff
citation_file = "CITATION.cff"
if os.path.exists(citation_file):
with open(citation_file, "r") as file:
citation_data = yaml.safe_load(file)
else:
citation_data = {
"cff-version": "1.2.0",
"message": "If you use this software, please cite it using this metadata.",
}

# Update authors
citation_data["authors"] = new_authors

# Optionally update other fields
citation_data["title"] = citation_data.get("title", repo_name)
citation_data["version"] = "1.0.0" # Update dynamically if needed
citation_data["date-released"] = "2024-11-29" # Update dynamically

# Write back to CITATION.cff
with open(citation_file, "w") as file:
yaml.dump(citation_data, file, sort_keys=False)

print("CITATION.cff updated successfully.")
name: Update CITATION.cff

on:
workflow_dispatch: # Allows manual trigger
push:
branches:
- main # Run on pushes to main branch
schedule:
- cron: "0 0 * * *" # Run daily

jobs:
update-citation:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install Dependencies
run: pip install requests pyyaml

- name: Update CITATION.cff
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: python .github/scripts/update_citation.py

- name: Commit and Push Changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update CITATION.cff with latest contributors"
file_pattern: "CITATION.cff"

0 comments on commit 5c10f24

Please sign in to comment.