diff --git a/.gitea/workflows/create-pr.sh b/.gitea/workflows/create-pr.sh new file mode 100755 index 000000000..796f1348d --- /dev/null +++ b/.gitea/workflows/create-pr.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# Shared script for creating pull requests in Gitea workflows +set -euo pipefail + +# Required environment variables: +# - CI_BOT_TOKEN: Gitea bot token for authentication +# - PR_BRANCH: Branch name for the pull request +# - PR_TITLE: Title of the pull request +# - PR_BODY: Body/description of the pull request + +if [[ -z "${CI_BOT_TOKEN:-}" ]]; then + echo "Error: CI_BOT_TOKEN is not set" >&2 + exit 1 +fi + +if [[ -z "${PR_BRANCH:-}" ]]; then + echo "Error: PR_BRANCH is not set" >&2 + exit 1 +fi + +if [[ -z "${PR_TITLE:-}" ]]; then + echo "Error: PR_TITLE is not set" >&2 + exit 1 +fi + +if [[ -z "${PR_BODY:-}" ]]; then + echo "Error: PR_BODY is not set" >&2 + exit 1 +fi + +# Push the branch +git push origin "+HEAD:${PR_BRANCH}" + +# Create pull request +resp=$(nix run --inputs-from . nixpkgs#curl -- -X POST \ + -H "Authorization: token $CI_BOT_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{ + \"head\": \"${PR_BRANCH}\", + \"base\": \"main\", + \"title\": \"${PR_TITLE}\", + \"body\": \"${PR_BODY}\" + }" \ + "https://git.clan.lol/api/v1/repos/clan/clan-core/pulls") + +pr_number=$(echo "$resp" | jq -r '.number') + +if [[ "$pr_number" == "null" ]]; then + echo "Error creating pull request:" >&2 + echo "$resp" | jq . >&2 + exit 1 +fi + +echo "Created pull request #$pr_number" + +# Merge when checks succeed +while true; do + resp=$(nix run --inputs-from . nixpkgs#curl -- -X POST \ + -H "Authorization: token $CI_BOT_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "Do": "merge", + "merge_when_checks_succeed": true, + "delete_branch_after_merge": true + }' \ + "https://git.clan.lol/api/v1/repos/clan/clan-core/pulls/$pr_number/merge") + msg=$(echo "$resp" | jq -r '.message') + if [[ "$msg" != "Please try again later" ]]; then + break + fi + echo "Retrying in 2 seconds..." + sleep 2 +done + +echo "Pull request #$pr_number merge initiated" \ No newline at end of file diff --git a/.gitea/workflows/update-clan-core-for-checks.yml b/.gitea/workflows/update-clan-core-for-checks.yml index 94e372391..ed37eedff 100644 --- a/.gitea/workflows/update-clan-core-for-checks.yml +++ b/.gitea/workflows/update-clan-core-for-checks.yml @@ -19,35 +19,10 @@ jobs: run: | export GIT_AUTHOR_NAME=clan-bot GIT_AUTHOR_EMAIL=clan-bot@clan.lol GIT_COMMITTER_NAME=clan-bot GIT_COMMITTER_EMAIL=clan-bot@clan.lol git commit -am "Update pinned clan-core for checks" - git push origin +HEAD:update-clan-core-for-checks - set -x - resp=$(nix run --inputs-from . nixpkgs#curl -- -X POST \ - -H "Authorization: token $CI_BOT_TOKEN" \ - -H "Content-Type: application/json" \ - -d '{ - "head": "update-clan-core-for-checks", - "base": "main", - "title": "Update Clan Core for Checks", - "body": "This PR updates the pinned clan-core flake input that is used for checks." - }' \ - "https://git.clan.lol/api/v1/repos/clan/clan-core/pulls") - pr_number=$(echo "$resp" | jq -r '.number') - # Merge when succeed - while true; do - resp=$(nix run --inputs-from . nixpkgs#curl -- -X POST \ - -H "Authorization: token $CI_BOT_TOKEN" \ - -H "Content-Type: application/json" \ - -d '{ - "Do": "merge", - "merge_when_checks_succeed": true, - "delete_branch_after_merge": true - }' \ - "https://git.clan.lol/api/v1/repos/clan/clan-core/pulls/$pr_number/merge") - msg=$(echo $resp | jq -r '.message') - if [[ "$msg" != "Please try again later" ]]; then - break - fi - echo "Retrying in 2 seconds..." - sleep 2 - done + # Use shared PR creation script + export PR_BRANCH="update-clan-core-for-checks" + export PR_TITLE="Update Clan Core for Checks" + export PR_BODY="This PR updates the pinned clan-core flake input that is used for checks." + + ./.gitea/workflows/create-pr.sh diff --git a/.gitea/workflows/update-private-flake-inputs.yml b/.gitea/workflows/update-private-flake-inputs.yml new file mode 100644 index 000000000..21622b238 --- /dev/null +++ b/.gitea/workflows/update-private-flake-inputs.yml @@ -0,0 +1,40 @@ +name: "Update private flake inputs" +on: + repository_dispatch: + workflow_dispatch: + schedule: + - cron: "0 3 * * *" # Run daily at 3 AM +jobs: + update-private-flake: + runs-on: nix + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - name: Update private flake inputs + run: | + # Update the private flake lock file + cd devFlake/private + nix flake update + cd ../.. + + # Update the narHash + ./devFlake/update-private-narhash + - name: Create pull request + env: + CI_BOT_TOKEN: ${{ secrets.CI_BOT_TOKEN }} + run: | + export GIT_AUTHOR_NAME=clan-bot GIT_AUTHOR_EMAIL=clan-bot@clan.lol GIT_COMMITTER_NAME=clan-bot GIT_COMMITTER_EMAIL=clan-bot@clan.lol + + # Check if there are any changes + if ! git diff --quiet; then + git add devFlake/private/flake.lock devFlake/private.narHash + git commit -m "Update dev flake" + + # Use shared PR creation script + export PR_BRANCH="update-dev-flake" + export PR_TITLE="Update dev flake" + export PR_BODY="This PR updates the dev flake inputs and corresponding narHash." + else + echo "No changes detected in dev flake inputs" + fi