From 6af0530c08b9c72e9fa7666c88ef006438fb2fcc Mon Sep 17 00:00:00 2001 From: Brantly Callaway Date: Fri, 31 Jan 2025 13:18:34 -0500 Subject: [PATCH] added workflow for updating citation --- .github/workflows/update-citation.yml | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/update-citation.yml diff --git a/.github/workflows/update-citation.yml b/.github/workflows/update-citation.yml new file mode 100644 index 0000000..724c0d0 --- /dev/null +++ b/.github/workflows/update-citation.yml @@ -0,0 +1,60 @@ +name: Update Citation Files + +on: + push: + paths: + - "DESCRIPTION" + workflow_dispatch: + +jobs: + update-citation: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + + - name: Install dependencies + run: | + Rscript -e 'install.packages(c("usethis", "cffr", "desc"))' + + - name: Update inst/CITATION + run: | + Rscript -e ' + library(desc); + # Read package metadata + package_title <- desc::desc_get("Title") + authors <- desc::desc_get("Authors@R") + version <- desc::desc_get("Version") + url <- desc::desc_get("URL") + year <- format(Sys.Date(), "%Y") # Get current year + + # Generate citation content dynamically + citation_text <- sprintf("citHeader(\"To cite this package, use:\")\n\n + bibentry(\n + bibtype = \"Manual\",\n + title = \"%s\",\n + author = %s,\n + year = \"%s\",\n + note = \"R package version %s\",\n + url = \"%s\" + )", package_title, authors, year, version, url) + + # Write the updated citation file + writeLines(citation_text, "inst/CITATION")' + + + - name: Update CITATION.cff + run: | + Rscript -e 'cffr::cff_write()' + + - name: Commit and Push if Changed + run: | + git config --global user.name "github-actions" + git config --global user.email "github-actions@github.com" + git add inst/CITATION CITATION.cff + git commit -m "Auto-update citation files" || echo "No changes to commit" + git push