-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (126 loc) · 5.14 KB
/
update.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Nix Flake and Submodule Update
on:
schedule:
- cron: "0 0 * * *" # Run daily at midnight UTC
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: 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: update flake.lock" && echo "Flake.lock changes committed")
echo "Flake.lock update complete"
# - name: Push changes
# if: (github.event.inputs.update_submodule == 'true' || github.event.inputs.update_flake == 'true' || github.event_name == 'schedule')
# run: |
# echo "Pushing changes"
# git push --set-upstream origin ${{ env.PR_BRANCH }} --force
# echo "Changes pushed"
- name: Debug Git Status
run: |
echo "Current branch:"
git branch --show-current
echo "Git status:"
git status
echo "Diff with main:"
git diff main
echo "Log of last few commits:"
git log -n 5 --oneline
- 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: update flake.lock and astro nvim submodule"
title: "chore: 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 }}
# delete-branch: true
base: "main" # Change this if your default branch has a different name
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"