Skip to content

03 Maintain: Update Package Cache #97

03 Maintain: Update Package Cache

03 Maintain: Update Package Cache #97

Workflow file for this run

name: "03 Maintain: Update Package Cache"
on:
workflow_dispatch:
inputs:
name:
description: 'Who triggered this build (enter github username to tag yourself)?'
required: true
default: 'monthly run'
schedule:
# Run every tuesday
- cron: '0 0 * * 2'
jobs:
preflight:
name: "Preflight Check"
runs-on: ubuntu-latest
outputs:
ok: ${{ steps.check.outputs.ok }}
steps:
- id: check
run: |
if [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
echo "ok=true" >> $GITHUB_OUTPUT
echo "Running on request"
# using single brackets here to avoid 08 being interpreted as octal
# https://github.com/carpentries/sandpaper/issues/250
elif [ `date +%d` -le 7 ]; then
# If the Tuesday lands in the first week of the month, run it
echo "ok=true" >> $GITHUB_OUTPUT
echo "Running on schedule"
else
echo "ok=false" >> $GITHUB_OUTPUT
echo "Not Running Today"
fi
check_renv:
name: "Check if We Need {renv}"
runs-on: ubuntu-latest
needs: preflight
if: ${{ needs.preflight.outputs.ok == 'true'}}
outputs:
needed: ${{ steps.renv.outputs.exists }}
steps:
- name: "Checkout Lesson"
uses: actions/checkout@v3
- id: renv
run: |
if [[ -d renv ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
fi
check_token:
name: "Check SANDPAPER_WORKFLOW token"
runs-on: ubuntu-latest
needs: check_renv
if: ${{ needs.check_renv.outputs.needed == 'true' }}
outputs:
workflow: ${{ steps.validate.outputs.wf }}
repo: ${{ steps.validate.outputs.repo }}
steps:
- name: "validate token"
id: validate
uses: carpentries/actions/check-valid-credentials@main
with:
token: ${{ secrets.SANDPAPER_WORKFLOW }}
update_cache:
name: "Update Package Cache"
needs: check_token
if: ${{ needs.check_token.outputs.repo== 'true' }}
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
RENV_PATHS_ROOT: ~/.local/share/renv/
steps:
- name: "Checkout Lesson"
uses: actions/checkout@v3
- name: "Set up R"
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
install-r: false
- name: "Update {renv} deps and determine if a PR is needed"
id: update
uses: carpentries/actions/update-lockfile@main
with:
cache-version: ${{ secrets.CACHE_VERSION }}
- name: Create Pull Request
id: cpr
if: ${{ steps.update.outputs.n > 0 }}
uses: carpentries/create-pull-request@main
with:
token: ${{ secrets.SANDPAPER_WORKFLOW }}
delete-branch: true
branch: "update/packages"
commit-message: "[actions] update ${{ steps.update.outputs.n }} packages"
title: "Update ${{ steps.update.outputs.n }} packages"
body: |
:robot: This is an automated build
This will update ${{ steps.update.outputs.n }} packages in your lesson with the following versions:
```
${{ steps.update.outputs.report }}
```
:stopwatch: In a few minutes, a comment will appear that will show you how the output has changed based on these updates.
If you want to inspect these changes locally, you can use the following code to check out a new branch:
```bash
git fetch origin update/packages
git checkout update/packages
```
- Auto-generated by [create-pull-request][1] on ${{ steps.update.outputs.date }}
[1]: https://github.com/carpentries/create-pull-request/tree/main
labels: "type: package cache"
draft: false