|
| 1 | +name: "03 Maintain: Apply Package Cache" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + name: |
| 7 | + description: 'Who triggered this build?' |
| 8 | + required: true |
| 9 | + default: 'Maintainer (via GitHub)' |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - closed |
| 13 | + |
| 14 | +jobs: |
| 15 | + preflight: |
| 16 | + name: "Preflight: PR or Manual Trigger?" |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + do-apply: ${{ steps.check.outputs.merged_or_manual }} |
| 20 | + steps: |
| 21 | + - name: "Should we run cache application?" |
| 22 | + id: check |
| 23 | + run: | |
| 24 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" || |
| 25 | + ("${{ github.event.action }}" == "closed" && "${{ github.event.pull_request.merged }}" == "true") ]]; then |
| 26 | + echo "merged_or_manual=true" >> $GITHUB_OUTPUT |
| 27 | + else |
| 28 | + echo "This was not a manual trigger and no PR was merged. No action taken." |
| 29 | + echo "merged_or_manual=false" >> $GITHUB_OUTPUT |
| 30 | + fi |
| 31 | +
|
| 32 | + check-renv: |
| 33 | + name: "Check If We Need {renv}" |
| 34 | + runs-on: ubuntu-latest |
| 35 | + needs: preflight |
| 36 | + if: ${{ needs.preflight.outputs.do-apply == 'true' }} |
| 37 | + outputs: |
| 38 | + renv-needed: ${{ steps.check-for-renv.outputs.exists }} |
| 39 | + steps: |
| 40 | + - name: "Checkout Lesson" |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: "Check for renv" |
| 44 | + id: check-for-renv |
| 45 | + run: | |
| 46 | + if [[ -d renv ]]; then |
| 47 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | +
|
| 50 | + prepare: |
| 51 | + name: "Grab renv.lock hash" |
| 52 | + runs-on: ubuntu-latest |
| 53 | + needs: check-renv |
| 54 | + if: ${{ needs.check-renv.outputs.renv-needed == 'true' }} |
| 55 | + outputs: |
| 56 | + renv-cache-hashsum: ${{ steps.set-hash.outputs.renv-cache-hashsum }} |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Calculate renv hash |
| 61 | + id: set-hash |
| 62 | + run: | |
| 63 | + echo "renv-cache-hashsum=${{ hashFiles('renv/profiles/lesson-requirements/renv.lock') }}" >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | + update-renv-cache: |
| 66 | + name: "Update renv Cache" |
| 67 | + if: | |
| 68 | + github.event_name == 'workflow_dispatch' || |
| 69 | + ( |
| 70 | + github.event.pull_request.merged == true && |
| 71 | + contains( |
| 72 | + join(github.event.pull_request.labels.*.name, ','), |
| 73 | + 'type: package cache' |
| 74 | + ) |
| 75 | + ) |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: prepare |
| 78 | + permissions: |
| 79 | + checks: write |
| 80 | + contents: write |
| 81 | + pages: write |
| 82 | + container: |
| 83 | + image: carpentries/workbench-docker:${{ vars.WORKBENCH_TAG || 'latest' }} |
| 84 | + env: |
| 85 | + WORKBENCH_PROFILE: "ci" |
| 86 | + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + RENV_PATHS_ROOT: /home/rstudio/lesson/renv |
| 88 | + RENV_PROFILE: "lesson-requirements" |
| 89 | + RENV_VERSION: ${{ needs.prepare.outputs.renv-cache-hashsum }} |
| 90 | + RENV_CONFIG_EXTERNAL_LIBRARIES: "/usr/local/lib/R/site-library" |
| 91 | + volumes: |
| 92 | + - ${{ github.workspace }}:/home/rstudio/lesson |
| 93 | + options: --cpus 2 |
| 94 | + steps: |
| 95 | + - name: "Checkout Lesson" |
| 96 | + uses: actions/checkout@v4 |
| 97 | + |
| 98 | + - name: Current env |
| 99 | + run: env | sort |
| 100 | + |
| 101 | + - name: Debugging Info |
| 102 | + run: | |
| 103 | + echo "Current Directory: $(pwd)" |
| 104 | + ls -lah /home/rstudio/.workbench |
| 105 | + ls -lah $(pwd) |
| 106 | + Rscript -e 'sessionInfo()' |
| 107 | +
|
| 108 | + - name: Mark Repository as Safe |
| 109 | + run: | |
| 110 | + git config --global --add safe.directory $(pwd) |
| 111 | +
|
| 112 | + - name: "Ensure sandpaper is loadable" |
| 113 | + run: | |
| 114 | + .libPaths() |
| 115 | + library(sandpaper) |
| 116 | + shell: Rscript {0} |
| 117 | + |
| 118 | + - name: Setup Lesson Dependencies |
| 119 | + run: | |
| 120 | + Rscript /home/rstudio/.workbench/setup_lesson_deps.R |
| 121 | +
|
| 122 | + - name: Fortify renv Cache |
| 123 | + run: | |
| 124 | + Rscript /home/rstudio/.workbench/fortify_renv_cache.R |
| 125 | +
|
| 126 | + - name: Cache renv Directory |
| 127 | + uses: actions/cache@v4 |
| 128 | + with: |
| 129 | + path: /home/rstudio/lesson/renv |
| 130 | + key: ${{ runner.os }}-${{ inputs.cache-version }}-renv-${{ needs.prepare.outputs.renv-cache-hashsum }} |
| 131 | + restore-keys: |
| 132 | + ${{ runner.os }}-${{ inputs.cache-version }}-renv- |
0 commit comments