diff --git a/.github/workflows/auto-merge-l10n.yml b/.github/workflows/auto-merge-l10n.yml index 03eceddfd..0eb321431 100644 --- a/.github/workflows/auto-merge-l10n.yml +++ b/.github/workflows/auto-merge-l10n.yml @@ -72,6 +72,17 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} REPO: ${{ github.repository }} run: | + APPROVED=$(gh pr view "$PR_NUMBER" \ + --repo "$REPO" \ + --json reviews \ + --jq '.reviews[] | select(.state == "APPROVED") | .id' \ + | wc -l) + + if [ "$APPROVED" -gt 0 ]; then + echo "PR already approved" + exit 0 + fi + gh pr review "$PR_NUMBER" \ --repo "$REPO" \ --approve \ diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 92a755781..2c9213f51 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -16,6 +16,7 @@ concurrency: jobs: pull-request-lint: name: "Lint PR" + if: github.event_name == 'pull_request' uses: ./.github/workflows/pull-request-lint.yml backend-tests: diff --git a/.github/workflows/scheduled-checks.yml b/.github/workflows/scheduled-checks.yml index 337907418..e9643e0e6 100644 --- a/.github/workflows/scheduled-checks.yml +++ b/.github/workflows/scheduled-checks.yml @@ -40,12 +40,18 @@ jobs: shell: bash run: pre-commit autoupdate --color=always - - name: Create Pull Request - uses: peter-evans/create-pull-request@v6 - # This doesn't currently work for us because it creates the PR but the workflows don't run. - # TODO: Provide a personal access token as a parameter here, that solves that problem. - # https://github.com/peter-evans/create-pull-request + - name: Generate GitHub App Token + id: app-token + uses: actions/create-github-app-token@v1 with: + app-id: ${{ secrets.COMMIT_BOT_APP_ID }} + private-key: ${{ secrets.COMMIT_BOT_APP_PRIVATE_KEY }} + + - name: Create Pull Request + id: create-pr + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ steps.app-token.outputs.token }} commit-message: "Update pre-commit hooks" branch: "fix/update-pre-commit-hooks" labels: | @@ -54,3 +60,38 @@ jobs: base: mealie-next title: "chore(auto): Update pre-commit hooks" body: "Auto-generated by `.github/workflows/scheduled-checks.yml`" + + - name: Approve PR + if: steps.create-pr.outputs.pull-request-number + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }} + REPO: ${{ github.repository }} + run: | + APPROVED=$(gh pr view "$PR_NUMBER" \ + --repo "$REPO" \ + --json reviews \ + --jq '.reviews[] | select(.state == "APPROVED") | .id' \ + | wc -l) + + if [ "$APPROVED" -gt 0 ]; then + echo "PR already approved" + exit 0 + fi + + gh pr review "$PR_NUMBER" \ + --repo "$REPO" \ + --approve \ + --body "Auto-approved: Pre-commit hook updates" + + - name: Enable auto-merge + if: steps.create-pr.outputs.pull-request-number + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }} + REPO: ${{ github.repository }} + run: | + gh pr merge "$PR_NUMBER" \ + --repo "$REPO" \ + --auto \ + --squash