trevstack/.gitea/workflows/update.yaml
trev 174d15de5b
All checks were successful
Check / check (push) Successful in 51s
fix: merge when checks succeed
2025-05-14 10:02:08 -04:00

61 lines
2.0 KiB
YAML

name: Update
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Use Cachix
uses: cachix/cachix-action@v16
with:
name: trevstack
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
# https://github.com/actions/checkout/issues/13
- name: Set Git Config
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B create-pull-request/patch
- name: Update
run: nix run .#update
- name: Create Gitea PR
env:
URL: ${{ vars.URL }}
PAT: ${{ secrets.PAT }}
run: |
REPO_OWNER_SLASH_NAME="${{ gitea.repository }}"
git push origin create-pull-request/patch --force
CURRENT_PR=$(curl -s -X GET -H "Authorization: token $PAT" "https://$URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/main/create-pull-request/patch")
if [ "$( jq 'has("errors")' <<< $CURRENT_PR )" == "true" ]; then
PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $PAT" \
-H "Content-Type: application/json" \
-d '{"title":"update","body":"automatic update pr","head":"create-pull-request/patch","base":"main"}' \
"https://$URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls")
PR_NUMBER=$(echo "$PR_RESPONSE" | jq -r '.number')
curl -s -X POST -H "Authorization: token $PAT" \
-H "Content-Type: application/json" \
-d '{"Do":"merge","merge_when_checks_succeed":true}' \
"https://$URL/api/v1/repos/$REPO_OWNER_SLASH_NAME/pulls/$PR_NUMBER/merge"
fi