nixos-config/.forgejo/workflows/update_nix_flakes.yml

62 lines
1.5 KiB
YAML
Raw Normal View History

2024-07-20 22:32:37 +02:00
name: Update Nix flakes and commit changes
on:
schedule:
2024-07-21 00:54:53 +02:00
- cron: "0 2/5 * * * *" # not to frequent, GitHub only allows a few pulls per hour
2024-07-20 22:32:37 +02:00
jobs:
update-and-commit:
runs-on: native
steps:
2024-07-21 00:08:51 +02:00
2024-07-20 23:19:11 +02:00
- name: checkout repository
2024-07-20 22:32:37 +02:00
uses: actions/checkout@v2
with:
ref: "update"
2024-07-21 00:55:13 +02:00
depth: 0
2024-07-20 22:32:37 +02:00
2024-07-20 23:19:11 +02:00
- name: setup git
2024-07-20 22:32:37 +02:00
run: |
git config --local user.email "action@git.ingolf-wagner.de"
git config --local user.name "Forgejo Action"
2024-07-21 00:08:51 +02:00
# fixme: not working for some reason
#- name: rebase with main branch
# run: |
# git fetch origin main
# git rebase origin/main
2024-07-20 22:32:37 +02:00
2024-07-20 23:19:11 +02:00
- name: setup ssh
run: |
cat <<EOF > .id_rsa
${{ secrets.SSH_KEY }}
EOF
chmod 600 .id_rsa
eval $(ssh-agent)
ssh-add .id_rsa
cat <<EOF > "$GITHUB_ENV"
SSH_AUTH_SOCK="$SSH_AUTH_SOCK"
SSH_AGENT_PID=$SSH_AGENT_PID
EOF
- name: update nix flakes
2024-07-20 22:32:37 +02:00
run: nix flake update
2024-07-21 00:08:51 +02:00
# we need the ssh-agent here, otherwise git push would use the GITHUB_TOKEN
# which prevents other workflows to be triggered
2024-07-20 23:19:11 +02:00
- name: commit and push changes
2024-07-20 22:32:37 +02:00
run: |
2024-07-20 23:25:07 +02:00
git diff --quiet && \
git diff --staged --quiet || \
(git commit -am "Update Nix flakes" && git push)
2024-07-20 23:19:11 +02:00
- name: teardown ssh
if: always()
run: |
echo $SSH_AGENT_PID
kill $SSH_AGENT_PID