feat: create action
This commit is contained in:
commit
043c18e89a
3 changed files with 289 additions and 0 deletions
86
action.yml
Normal file
86
action.yml
Normal file
|
@ -0,0 +1,86 @@
|
|||
---
|
||||
name: 'Flake Input Updater'
|
||||
inputs:
|
||||
base:
|
||||
default: 'main'
|
||||
required: false
|
||||
name:
|
||||
default: 'flake bump bot'
|
||||
required: false
|
||||
email:
|
||||
default: 'bot@nix.flake'
|
||||
required: false
|
||||
title:
|
||||
default: '[bot]: flake bump'
|
||||
required: false
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: "Configure git"
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Configuring git"
|
||||
git config user.name "${{ inputs.name }}" >> $GITHUB_OUTPUT
|
||||
git config user.email "${{ inputs.email }}" >> $GITHUB_OUTPUT
|
||||
- name: "Create branch"
|
||||
id: clone
|
||||
shell: bash
|
||||
run: |
|
||||
BRANCH="flake-update-$(date +%s)"
|
||||
echo "Creating branch $BRANCH"
|
||||
# git fetch --all
|
||||
git checkout -b "$BRANCH"
|
||||
echo branch=$BRANCH >> $GITHUB_OUTPUT
|
||||
- name: "Check for updates"
|
||||
id: changes
|
||||
shell: bash
|
||||
run: |
|
||||
echo "Checking for flake updates"
|
||||
cp flake.lock test.lock
|
||||
nix flake update --output-lock-file test.lock
|
||||
if ! (diff -q flake.lock test.lock); then
|
||||
echo change=true >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo change=false >> $GITHUB_OUTPUT
|
||||
fi
|
||||
- name: "Push + create PR"
|
||||
shell: bash
|
||||
id: push
|
||||
if: steps.changes.outputs.change == 'true'
|
||||
run: |
|
||||
echo "Creating PR for branch ${{ steps.clone.outputs.branch }}"
|
||||
mv test.lock flake.lock
|
||||
git add flake.lock
|
||||
git commit -m "${{ inputs.title }}"
|
||||
git push --force-with-lease origin "${{ steps.clone.outputs.branch }}"
|
||||
|
||||
RESPONSE=$(curl -X 'POST' \
|
||||
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/pulls" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H 'Content-type: application/json' \
|
||||
-d '{
|
||||
"base": "${{ inputs.base }}",
|
||||
"head": "${{ steps.clone.outputs.branch }}",
|
||||
"title": "automated flake update"
|
||||
}')
|
||||
|
||||
NUMBER=$(echo $RESPONSE | jq -r '.number')
|
||||
echo "Created PR $NUMBER."
|
||||
echo NUMBER=$NUMBER >> $GITHUB_OUTPUT
|
||||
- name: "Set automerge on PR"
|
||||
shell: bash
|
||||
if: steps.changes.outputs.change == 'true' && steps.push.outputs.number != 'null'
|
||||
run: |
|
||||
RESPONSE=$(curl -X 'POST' \
|
||||
"$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/pulls/${{ steps.push.outputs.number }}/merge" \
|
||||
-H 'accept: application/json' \
|
||||
-H "Authorization: token $GITHUB_TOKEN" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
"Do": "merge",
|
||||
"merge_when_checks_succeed": true,
|
||||
"delete_branch_after_merge": true
|
||||
}')
|
||||
echo $RESPONSE
|
Loading…
Add table
Add a link
Reference in a new issue