-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (125 loc) · 4.93 KB
/
update-cache.yaml
File metadata and controls
142 lines (125 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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 "::set-output name=ok::true"
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 "::set-output name=ok::true"
echo "Running on schedule"
else
echo "::set-output name=ok::false"
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@v2
- id: renv
run: |
if [[ -d renv ]]; then
echo "::set-output name=exists::true"
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 }}
bad_token:
name: "Invalid/Missing Token"
runs-on: ubuntu-latest
needs: check_token
if: ${{ needs.check_token.outputs.workflow != 'true' }}
steps:
- name: "Instructions to create a new token"
run: |
printf "::warning::The SANDPAPER_WORKFLOW secret is missing, invalid, "\
"or does not have the right scope to update the package cache.\n"\
"If you want to have automated pull request updates to your package cache, "\
"you will need to generate a new token by visiting "\
"https://github.com/settings/tokens/new?scopes=repo,workflow&description=Sandpaper%%20Token%%20%%28${{ github.repository }}%%29\n"\
"Once you have created the token, copy it to your clipboard and go to "\
"https://github.com/${{ github.repository }}/settings/secrets/actions/new "\
"and enter SANDPAPER_WORKFLOW for the 'Name' and paste your key for the 'Value'."
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@v2
- 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: peter-evans/create-pull-request@v3.10.0
with:
token: ${{ secrets.SANDPAPER_WORKFLOW }}
delete-branch: true
branch: "update-${{ steps.update.outputs.n }}-packages-${{ steps.update.outputs.date }}"
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 the following package versions in your lesson:
```
${{ 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-${{ steps.update.outputs.n }}-packages-${{ steps.update.outputs.date }}
git checkout update-${{ steps.update.outputs.n }}-packages-${{ steps.update.outputs.date }}
```
- Auto-generated by [create-pull-request][1] via ${{ github.event.inputs.name }}
[1]: https://github.com/peter-evans/create-pull-request
labels: "type:package cache"
draft: false