Update create-dependabot.yml #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Dependabot Config | |
on: | |
push: | |
paths: | |
- '.github/workflows/create-dependabot.yml' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
create-dependabot: | |
runs-on: [ubuntu-latest] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Calculate expected hash | |
id: hash | |
run: | | |
EXPECTED_CONTENT='# Please see the documentation for all configuration options: | |
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | |
version: 2 | |
updates: | |
# NuGet dependencies | |
- package-ecosystem: "nuget" | |
directory: "**/*" | |
schedule: | |
interval: "weekly" | |
day: "monday" | |
time: "09:00" | |
timezone: "Europe/London" | |
open-pull-requests-limit: 1 | |
groups: | |
patch-and-minor: | |
patterns: | |
- "*" | |
update-types: | |
- "minor" | |
- "patch" | |
labels: | |
- "dependencies" | |
- "nuget" | |
ignore: | |
- dependency-name: "*" | |
update-types: ["version-update:semver-major"] | |
# npm dependencies | |
- package-ecosystem: "npm" | |
directory: "**/*" | |
schedule: | |
interval: "weekly" | |
day: "monday" | |
time: "09:00" | |
timezone: "Europe/London" | |
open-pull-requests-limit: 1 | |
groups: | |
patch-and-minor: | |
patterns: | |
- "*" | |
update-types: | |
- "minor" | |
- "patch" | |
labels: | |
- "dependencies" | |
- "npm" | |
ignore: | |
- dependency-name: "*" | |
update-types: ["version-update:semver-major"] | |
# Docker dependencies | |
- package-ecosystem: "docker" | |
directory: "**/*" | |
schedule: | |
interval: "weekly" | |
day: "monday" | |
time: "09:00" | |
timezone: "Europe/London" | |
open-pull-requests-limit: 1 | |
groups: | |
patch-and-minor: | |
patterns: | |
- "*" | |
update-types: | |
- "minor" | |
- "patch" | |
labels: | |
- "dependencies" | |
- "docker" | |
ignore: | |
- dependency-name: "*" | |
update-types: ["version-update:semver-major"] | |
# GitHub Actions | |
- package-ecosystem: "github-actions" | |
directory: "**/*" | |
schedule: | |
interval: "weekly" | |
day: "monday" | |
time: "09:00" | |
timezone: "Europe/London" | |
open-pull-requests-limit: 1 | |
groups: | |
patch-and-minor: | |
patterns: | |
- "*" | |
update-types: | |
- "minor" | |
- "patch" | |
labels: | |
- "dependencies" | |
- "github-actions" | |
ignore: | |
- dependency-name: "*" | |
update-types: ["version-update:semver-major"] | |
# Python (pip) dependencies | |
- package-ecosystem: "pip" | |
directory: "**/*" | |
schedule: | |
interval: "weekly" | |
day: "monday" | |
time: "09:00" | |
timezone: "Europe/London" | |
open-pull-requests-limit: 1 | |
groups: | |
patch-and-minor: | |
patterns: | |
- "*" | |
update-types: | |
- "minor" | |
- "patch" | |
labels: | |
- "dependencies" | |
- "pip" | |
ignore: | |
- dependency-name: "*" | |
update-types: ["version-update:semver-major"] | |
# Terraform dependencies | |
- package-ecosystem: "terraform" | |
directory: "**/*" | |
schedule: | |
interval: "weekly" | |
day: "monday" | |
time: "09:00" | |
timezone: "Europe/London" | |
open-pull-requests-limit: 1 | |
groups: | |
patch-and-minor: | |
patterns: | |
- "*" | |
update-types: | |
- "minor" | |
- "patch" | |
labels: | |
- "dependencies" | |
- "terraform" | |
ignore: | |
- dependency-name: "*" | |
update-types: ["version-update:semver-major"]' | |
echo "EXPECTED_CONTENT<<EOF" >> $GITHUB_ENV | |
echo "$EXPECTED_CONTENT" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
EXPECTED_HASH=$(echo "$EXPECTED_CONTENT" | sha256sum | cut -d' ' -f1) | |
echo "expected=$EXPECTED_HASH" >> $GITHUB_OUTPUT | |
if [ -f ".github/dependabot.yml" ]; then | |
CURRENT_HASH=$(cat .github/dependabot.yml | sha256sum | cut -d' ' -f1) | |
echo "current=$CURRENT_HASH" >> $GITHUB_OUTPUT | |
else | |
echo "current=none" >> $GITHUB_OUTPUT | |
fi | |
- name: Create or update dependabot.yml | |
id: create-dependabot | |
if: steps.hash.outputs.current != steps.hash.outputs.expected | |
run: | | |
# Create a new branch | |
BRANCH_NAME="feature/update-dependabot-config-$(date +%s)" | |
git checkout -b $BRANCH_NAME | |
mkdir -p .github | |
echo "$EXPECTED_CONTENT" > .github/dependabot.yml | |
git config --global user.email "[email protected]" | |
git config --global user.name "Joe" | |
# Stage and commit the changes | |
git add .github/dependabot.yml | |
git commit -m "Add or update dependabot.yml configuration" | |
# Push the branch | |
git push origin $BRANCH_NAME | |
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT | |