diff --git a/.github/workflows/update-citation.yml b/.github/workflows/update-citation.yml new file mode 100644 index 0000000000..4e82d49f29 --- /dev/null +++ b/.github/workflows/update-citation.yml @@ -0,0 +1,61 @@ +name: Auto-update CITATION.cff + +on: + release: + types: [published] + +permissions: + contents: write # Required for creating branch and committing updates + pull-requests: write # Required for creating the pull request + +jobs: + update-citation: + runs-on: ubuntu-24.04 + + strategy: + max-parallel: 4 + matrix: + python-version: [3.13] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install doi2cff + run: + pip install + git+https://github.com/citation-file-format/doi2cff + + - name: Fetch latest Zenodo DOI + id: get-doi # Assign an ID to this step to reference its outputs + env: + ZENODO_TOKEN: ${{ secrets.ZENODO_TOKEN }} + run: | + ZENODO_DOI=$(python etc/scripts/fetch_latest_doi.py) + echo "ZENODO_DOI=${ZENODO_DOI}" >> "$GITHUB_OUTPUT" + + - name: Update CITATION.cff + # Use the output from the 'get-doi' step as the argument for doi2cff + run: doi2cff update ${{ steps.get-doi.outputs.ZENODO_DOI }} + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + base: develop + branch: update-citation-${{ github.event.release.tag_name }} + commit-message: + 'Automated: Update CITATION.cff with the latest Zenodo DOI' + title: 'Automated: Update CITATION.cff' + body: | + This is an automated pull request to update the `CITATION.cff` file + with the latest Zenodo DOI fetched from Zenodo repository. + # Set to true to automatically merge the PR if all checks pass (optional) + # automerge: true + # Set to true to delete the branch after merging (optional) + # delete-branch: true diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000000..6890fb8d42 --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,15 @@ +cff-version: 1.2.0 +message: If you use this software, please cite it using these metadata. +title: ScanCode-Toolkit +authors: + - family-names: Philippe + given-names: Ombredanne + orcid: 'https://orcid.org/0000-0001-5280-9256' + - family-names: Ayan + given-names: Sinha Mahapatra + orcid: 'https://orcid.org/0009-0006-0174-5727' + - family-names: Jono + given-names: Yang + - name: 'nexB Inc. and others.' +license: Apache-2.0 +url: 'https://github.com/aboutcode-org/scancode-toolkit' diff --git a/README.rst b/README.rst index 413567056e..e023e6cb5f 100644 --- a/README.rst +++ b/README.rst @@ -134,6 +134,9 @@ Other Important Documentation Pages: See also https://aboutcode.org for related companion projects and tools. +To cite this repository, visit the main page and click on the 'Cite this +repository' button for APA or BibTeX citation formats. + Installation ============ diff --git a/etc/scripts/fetch_latest_doi.py b/etc/scripts/fetch_latest_doi.py new file mode 100644 index 0000000000..caa7d94c45 --- /dev/null +++ b/etc/scripts/fetch_latest_doi.py @@ -0,0 +1,18 @@ +import requests +import os + +CONCEPT_DOI = "10.5281/zenodo.16361290" +ZENODO_API = "https://zenodo.org/api/records" +TOKEN = os.getenv("ZENODO_TOKEN") + +params = { + "q": f"conceptdoi:{CONCEPT_DOI}", + "sort": "version", + "size": 1, + "access_token": TOKEN +} + +r = requests.get(ZENODO_API, params=params) +r.raise_for_status() +latest_record = r.json()["hits"]["hits"][0] +print(latest_record["doi"])