Giter Club home page Giter Club logo

Comments (2)

Bombarding avatar Bombarding commented on July 18, 2024

Hello @Nek-12, so I was having this problem as well, and i managed to get this working based off of #170
This was my original CI in a single workflow file.

graph LR;
A[create pr]-->B[approve pr];
B-->C[merge pr]

So, when doing it this way (something I was unable to solve) I got the same undefined state that you are seeing. Despite PR status checks passing.. it was unable to verify that it was in a merge ready state and was merging before PR checks completed, which I did not want

Automerge action was removed from ci.yml and put it its own automerge.yml

---
name: Auto Merge Pull Request With Approved Label
on:
  repository_dispatch:
    types: [ ready-to-merge ] # This was the main fix
jobs:
  auto-merge:
    name: Auto Merge The Created Pull Request
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - id: automerge
        name: automerge
        uses: pascalgn/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.SECRET_TOKEN }} # PAT
          MERGE_LABELS: "automerge,autogenerated"
          MERGE_METHOD: "merge"

Then, I have a pull-request-checks.yml which is loosely Trivy Scan, and Spin up the container from GHCR. Adding in the following code, allowed me to solve this:

  repo-event:
    name: Set Repository Event
    permissions:
      contents: write
    runs-on: ubuntu-latest
    needs: [trivy-scan, compose-container]
    steps:
      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          event-type: ready-to-merge
          client-payload: '{"github": ${{ toJson(github) }}}'
        if: github.event_name == 'pull_request'

So... Repository Dispatch by peter evens, will create an event called ready-to-merge using ${{ secrets.GITHUB_TOKEN }} with contents: write permissions. Because that has a needs: [job1, job2] it will not create the event until those PR checks pass. Once that event is created, using

on:
  repository_dispatch:
    types: [ ready-to-merge ]

Will force the automerge action to kick off. Because the action does not natively wait for any PR checks to pass, approval, or statuses at this point (since those requirements are already done), it recognizes that and merges. You can use MERGE_READY_STATE: 'clean' if you want, but setting up the action in this manor basically says that the creation of the repository_dispatch == MERGE_READY_STATE: 'clean'. Force setting the MERGE_READY_STATE is redundant, as using the repository_dispatch event nets the following output when pascalgn's action is run.
image

from automerge-action.

Nek-12 avatar Nek-12 commented on July 18, 2024

Thanks @Bombarding for such a detailed workaround. Yes, a custom trigger action will definitely work. I'll copy your config :)

from automerge-action.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.