|
| 1 | +--- |
| 2 | +# GitHub Actions workflow for integrating Renovate Bot into your CI/CD pipeline. |
| 3 | +name: Renovate |
| 4 | +on: |
| 5 | + # Conservative rollout: manually trigger the workflow via the GitHub UI. |
| 6 | + workflow_dispatch: |
| 7 | +jobs: |
| 8 | + renovate: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + # STEP 1: Checkout the latest version of the repository. |
| 12 | + - name: Checkout Repository |
| 13 | + uses: actions/checkout@v2 |
| 14 | + |
| 15 | + # STEP 2: Generate the Renovate configuration file. |
| 16 | + # This step creates a 'renovate.json' file with the necessary configuration for Renovate. |
| 17 | + # The "enabledManagers" setting ensures that only GitHub Actions and workflow files are affected. |
| 18 | + - name: Generate Renovate Configuration |
| 19 | + run: | |
| 20 | + cat <<EOF > renovate.json |
| 21 | + { |
| 22 | + "extends": ["config:recommended"], |
| 23 | + "enabledManagers": ["github-actions"], |
| 24 | + "onboarding": false, |
| 25 | + "requireConfig": "optional", |
| 26 | + "autodiscover": false, |
| 27 | + "repositories": ["${GITHUB_REPOSITORY}"], |
| 28 | + "labels": ["renovate"], |
| 29 | + "schedule": ["before 5am on Monday"], |
| 30 | + "branchPrefix": "renovate/", |
| 31 | + "packageRules": [ |
| 32 | + { |
| 33 | + "matchUpdateTypes": ["minor", "patch"], |
| 34 | + "automerge": false, |
| 35 | + "groupName": "minor and patch updates" |
| 36 | + } |
| 37 | + ] |
| 38 | + } |
| 39 | + EOF |
| 40 | + env: |
| 41 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 42 | + |
| 43 | + # STEP 3: Verify that the provided RENOVATE_TOKEN has sufficient permissions. |
| 44 | + # This step validates that the Renovate token can access the repository. |
| 45 | + - name: Verify RENOVATE_TOKEN Permissions |
| 46 | + env: |
| 47 | + RENOVATE_TOKEN: ${{ secrets.RENOVATE_TOKEN }} |
| 48 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 49 | + run: | |
| 50 | + echo "Verifying RENOVATE_TOKEN permissions for repository ${GITHUB_REPOSITORY}..." |
| 51 | + response=$(curl -s -H "Authorization: token ${RENOVATE_TOKEN}" "https://api.github.com/repos/${GITHUB_REPOSITORY}") |
| 52 | + echo "$response" | jq . |
| 53 | + if echo "$response" | grep -q "Bad credentials"; then |
| 54 | + echo "Error: The provided RENOVATE_TOKEN is invalid or does not have sufficient permissions." |
| 55 | + exit 1 |
| 56 | + else |
| 57 | + echo "RENOVATE_TOKEN is valid and has sufficient permissions." |
| 58 | + fi |
| 59 | +
|
| 60 | + # STEP 4: Run the Renovate Bot using the official GitHub Action. |
| 61 | + # This step executes Renovate Bot to scan for dependency updates based on the configuration. |
| 62 | + - name: Run Renovate |
| 63 | + uses: renovatebot/[email protected] |
| 64 | + with: |
| 65 | + configurationFile: renovate.json # Use the configuration file generated in the previous step. |
| 66 | + token: ${{ secrets.RENOVATE_TOKEN }} |
| 67 | + renovate-version: 39 |
| 68 | + renovate-image: ghcr.io/renovatebot/renovate |
| 69 | + docker-socket-host-path: /var/run/docker.sock |
| 70 | + docker-volumes: /tmp:/tmp |
| 71 | + env: |
| 72 | + LOG_LEVEL: debug # Set log level to debug for detailed output (useful for troubleshooting). |
| 73 | + |
| 74 | + # STEP 5: Check for any Renovate update branches in the remote repository. |
| 75 | + # This step verifies whether Renovate has proposed any updates by creating new branches. |
| 76 | + - name: Check for Renovate Update Branches |
| 77 | + run: |- |
| 78 | + echo "Checking for Renovate update branches in the remote repository..." |
| 79 | + RENOVATE_BRANCHES=$(git ls-remote --heads origin | grep 'refs/heads/renovate/' || true) |
| 80 | + if [ -z "$RENOVATE_BRANCHES" ]; then |
| 81 | + echo "No update branches were created by Renovate." |
| 82 | + else |
| 83 | + echo "Renovate update branches found:" |
| 84 | + echo "$RENOVATE_BRANCHES" |
| 85 | + fi |
0 commit comments