Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions using actions/cache to README #827

Open
mering opened this issue Feb 13, 2024 · 4 comments
Open

Add instructions using actions/cache to README #827

mering opened this issue Feb 13, 2024 · 4 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed

Comments

@mering
Copy link

mering commented Feb 13, 2024

Newer versions of actions/cache have resolved previous issues. Prefer this over third party actions.

@viceice
Copy link
Member

viceice commented Feb 13, 2024

@viceice viceice added documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed labels Feb 13, 2024
@mering
Copy link
Author

mering commented Feb 13, 2024

@viceice Thanks. In the current version of the README using a third party action there is also an explicit chown call necessary.

@viceice
Copy link
Member

viceice commented Feb 13, 2024

feel free to open a PR to update the readme 🤗

@AB-xdev
Copy link
Contributor

AB-xdev commented Feb 11, 2025

Hey,

we had the same problem and created a working version.

renovate.yml
name: Renovate

on:
  # This lets you dispatch a renovate job with different cache options if you want to reset or disable the cache manually.
  workflow_dispatch:
    inputs:
      repoCache:
        description: 'Reset or disable the cache?'
        type: choice
        default: enabled
        options:
          - enabled
          - disabled
          - reset
  schedule:
    - cron: '0 0 * * *'

permissions: 
  actions: write # Required to delete existing cache
  contents: read 

# Adding these as env variables makes it easy to re-use them in different steps and in bash.
env:
  # This is the dir renovate provides -- if we set our own directory via cacheDir, we can run into permissions issues.
  # It is also possible to cache a higher level of the directory, but it has minimal benefit. While renovate execution
  # time gets faster, it also takes longer to upload the cache as it grows bigger.
  cache_dir: /tmp/renovate/cache/renovate/repository
  # This can be manually changed to bust the cache if necessary.
  cache_key: renovate-cache

jobs:
  renovate:
    name: Renovate
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Restore cache
        if: github.event.inputs.repoCache != 'disabled'
        id: cache-restore
        uses: actions/cache/restore@v4
        with:
          path: ${{ env.cache_dir }}
          key: ${{ env.cache_key }}

      - name: Try fix cache permissions
        if: ${{ steps.cache-restore.outputs.cache-hit }}
        continue-on-error: true
        run: |
          set -x
          
          # Unfortunately, the permissions expected within renovate's docker container
          # are different than the ones given after the cache is restored. We have to
          # change ownership to solve this. We also need to have correct permissions in
          # the entire /tmp/renovate tree, not just the section with the repo cache.
          sudo chown -R 12021:0 /tmp/renovate/
          ls -R $cache_dir

      - uses: renovatebot/github-action@v41.0.13
        with:
          configurationFile: self-hosted.json5
          token: ${{ secrets.RENOVATE_TOKEN }}
        env:
          # This enables the cache -- if this is set, it's not necessary to add it to renovate.json.
          RENOVATE_REPOSITORY_CACHE: ${{ github.event.inputs.repoCache || 'enabled' }}

      - name: Delete previous cache
        if: ${{ github.event.inputs.repoCache != 'disabled' && steps.cache-restore.outputs.cache-hit }}
        continue-on-error: true
        # GitHub CLI is already preinstalled on the runner
        run: gh cache delete "${{ env.cache_key }}"
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Save cache
        uses: actions/cache/save@v4
        if: github.event.inputs.repoCache != 'disabled'
        with:
          path: ${{ env.cache_dir }}
          key: ${{ env.cache_key }}

in use at: https://github.com/xdev-software/renovate-selfhosted

Should I create a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants
@viceice @AB-xdev @mering and others