From dc71fdb1161eb8f4ccc08284ebefc9d4c60c0379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rasmus=20Skytte=20Randl=C3=B8v?= Date: Mon, 19 Feb 2024 11:31:49 +0100 Subject: [PATCH] feat(update-renv): Add wf to update renv.lock --- .github/workflows/update-renv.yaml | 40 ++++++++++++++++++++++ .github/workflows/workflow-dispatcher.yaml | 15 ++++++++ workflows/README.md | 17 +++++++-- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/update-renv.yaml diff --git a/.github/workflows/update-renv.yaml b/.github/workflows/update-renv.yaml new file mode 100644 index 00000000..d05a73ba --- /dev/null +++ b/.github/workflows/update-renv.yaml @@ -0,0 +1,40 @@ +on: + workflow_call: + inputs: + run: + type: boolean + default: true + +jobs: + lint: + name: 🛠️ Store dependency versions + if: ${{ inputs.run }} + runs-on: ubuntu-latest + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + cache: false + extra-packages: any::renv + + - name: Update the renv.lock file + run: renv::snapshot(prompt = FALSE) + shell: Rscript {0} + + - name: Commit and push changes + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git switch ${{ inputs.branch_name }} + git add man/\* NAMESPACE DESCRIPTION + git commit -m "chore: update renv.lock" || echo "No changes to commit" + git push diff --git a/.github/workflows/workflow-dispatcher.yaml b/.github/workflows/workflow-dispatcher.yaml index 3ce59381..65bf1702 100644 --- a/.github/workflows/workflow-dispatcher.yaml +++ b/.github/workflows/workflow-dispatcher.yaml @@ -220,3 +220,18 @@ jobs: concurrency: group: pkgdown-${{ needs.trigger.outputs.branch_name }} cancel-in-progress: true + + update-renv: + needs: trigger + uses: ./.github/workflows/update-renv.yaml + with: + run: ${{ !contains(inputs.skip, 'update-renv') && ( + inputs.event_name == 'workflow_dispatch' || ( + needs.trigger.outputs.main_branch_affected == 'true' && ( + needs.trigger.outputs.R_files_changed == 'true' || + needs.trigger.outputs.test_files_changed == 'true' || + needs.trigger.outputs.description_changed == 'true'))) }} + branch_name: ${{ needs.trigger.outputs.branch_name }} + secrets: inherit + concurrency: + group: push-${{ needs.trigger.outputs.branch_name }} diff --git a/workflows/README.md b/workflows/README.md index 8a8f9f06..c624c969 100644 --- a/workflows/README.md +++ b/workflows/README.md @@ -64,7 +64,8 @@ If any issues are found, the workflow will give an error. ## code-coverage.yaml #### Trigger -Pushes or pull requests to the main branch if there are changes to any file in the `R/` or `tests/` folders. +Pushes or pull requests to the main branch if there are changes to the `DESCRIPTION`, or any file in the `R/` or +`tests/` folders. #### Function Determine the degree of [code coverage](https://en.wikipedia.org/wiki/Code_coverage) in your code base. @@ -121,7 +122,7 @@ Changes to `README.Rmd`. Knits `README.md` from `README.Rmd`. #### Outcome -If this generates changes to `README.md`, it it will commit the updated README to the repository. +If this generates changes to `README.md`, it will commit the updated README to the repository. ## spell-checker.yaml @@ -138,3 +139,15 @@ Click on the workflow and look for the "Run Spelling Check test" tab to see the #### Exit status If any spelling mistakes are found, the workflow will give an error. + + +## update-renv.yaml +#### Trigger +Pushes or pull requests to the main branch if there are changes to the `DESCRIPTION`, or any file in the `R/` or +`tests/` folders. + +#### Function +Runs `renv::snapshot()` on the code base and commits results. + +#### Outcome +The function will update the `renv.lock` file of the repository match the testing environment.