Skip to content

Nix Flake and Submodule Update #26

Nix Flake and Submodule Update

Nix Flake and Submodule Update #26

Workflow file for this run

name: Nix Flake and Submodule Update
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
update_submodule:
description: "Update submodule"
required: true
default: "true"
update_flake:
description: "Update flake"
required: true
default: "true"
create_pr:
description: "Create or update PR"
required: true
default: "true"
permissions:
contents: write
pull-requests: write
env:
PR_BRANCH: "automated-flake-and-submodule-update"
PR_LABEL: "automated-update"
jobs:
update-flake-and-submodule:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0
- name: Debug Info
run: |
echo "GitHub event name: ${{ github.event_name }}"
echo "Update submodule: ${{ github.event.inputs.update_submodule }}"
echo "Update flake: ${{ github.event.inputs.update_flake }}"
echo "Create PR: ${{ github.event.inputs.create_pr }}"
- name: Check for existing PR
if: github.event.inputs.create_pr == 'true' || github.event_name == 'schedule'
id: check_pr
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
console.log("Checking for existing PR");
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:${process.env.PR_BRANCH}`
});
console.log(`Found ${prs.data.length} potential PRs`);
for (const pr of prs.data) {
const labels = pr.labels.map(label => label.name);
console.log(`PR #${pr.number} labels: ${labels.join(', ')}`);
if (labels.includes(process.env.PR_LABEL)) {
console.log(`Existing automated PR found: #${pr.number}`);
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
state: 'closed'
});
console.log(`Closed PR #${pr.number}`);
break;
}
}
- name: Update submodule
if: github.event.inputs.update_submodule == 'true' || github.event_name == 'schedule'
run: |
echo "Updating submodule"
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b ${{ env.PR_BRANCH }}
git submodule update --remote config/nvim/astro
git add config/nvim/astro
git diff --cached --exit-code || (git commit -m "chore(deps): update astro nvim submodule" && echo "Submodule changes committed")
echo "Submodule update complete"
- name: Install Nix
if: github.event.inputs.update_flake == 'true' || github.event_name == 'schedule'
uses: cachix/install-nix-action@v27
- name: Update flake.lock
if: github.event.inputs.update_flake == 'true' || github.event_name == 'schedule'
run: |
echo "Updating flake.lock"
nix flake update --accept-flake-config
git add flake.lock
git diff --cached --exit-code || (git commit -m "chore(deps): update flake.lock" && echo "Flake.lock changes committed")
echo "Flake.lock update complete"
- name: Create Pull Request
if: github.event.inputs.create_pr == 'true' || github.event_name == 'schedule'
uses: peter-evans/create-pull-request@v6
with:
commit-message: "chore(deps): update flake.lock and astro nvim submodule"
title: "chore(deps): update flake.lock and astro nvim submodule"
body: |
This is an automated PR to update `flake.lock` to the latest versions and update the 'config/nvim/astro' submodule.
Please review the changes and merge if everything looks good.
branch: ${{ env.PR_BRANCH }}
base: "main"
labels: |
${{ env.PR_LABEL }}
- name: PR Creation Result
if: github.event.inputs.create_pr == 'true' || github.event_name == 'schedule'
run: |
echo "PR creation step completed"
echo "If no PR was created, check if there were any changes to commit"