Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not creates a push event #36

Open
mildred opened this issue Oct 4, 2021 · 3 comments
Open

Does not creates a push event #36

mildred opened this issue Oct 4, 2021 · 3 comments

Comments

@mildred
Copy link

mildred commented Oct 4, 2021

This action does not seem to create a GitHub push event, workflows registered on the target branch with a push event are not executed.

@oakkitten
Copy link

oakkitten commented May 20, 2022

This is probably due to workflows not being allowed to start other workflows in order to avoid loops. You can get around the above limitation by using a GitHub app. Here are some instructions to set one up.

In the end, since my use case was rather simple, and since I wasn't sure what staging_branch is supposed to be, I decided to do this by hand. The following works for me and runs all checks. LOKSMITH_ID and LOCKSMITH_PRIVATE_KEY are the id and private key of this repo-scoped GitHub app with repo write permissions. (I also needed the workflow permission since I'm modifying my workflow files as well.)

name: Fast-forward

on:
  issue_comment:
    types: [created, edited]

jobs:
  fast_forward:
    name: Fast-forward
    runs-on: ubuntu-latest
    if: |
      github.event.issue.pull_request &&
      github.event.comment.author_association == 'OWNER' && 
      contains(github.event.comment.body, '/fast-forward')

    steps:
      - name: Generate access token
        uses: tibdex/github-app-token@v1
        id: generate-token
        with:
          app_id: ${{ secrets.LOKSMITH_ID }}
          private_key: ${{ secrets.LOCKSMITH_PRIVATE_KEY }}

      - name: Fetch repository
        uses: actions/checkout@v3
        with:
          token: ${{ steps.generate-token.outputs.token }}
          fetch-depth: 0

      - name: Checkout pull request
        run: hub pr checkout ${{ github.event.issue.number }}
        env:
          GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

      - name: Fast-forward & push
        run: |
          export PR_COMMIT=$(git rev-parse HEAD)
          git checkout main
          git merge --ff-only $PR_COMMIT
          git push origin main

The same, but instead of reacting to a comment, this reacts to applying the label fast-forward:

name: Fast-forward

on:
  pull_request:
    types: [labeled]

jobs:
  fast_forward:
    name: Fast-forward
    runs-on: ubuntu-latest
    if: github.event.label.name == 'fast-forward'

    steps:
      - name: Generate access token
        uses: tibdex/github-app-token@v1
        id: generate-token
        with:
          app_id: ${{ secrets.LOKSMITH_ID }}
          private_key: ${{ secrets.LOCKSMITH_PRIVATE_KEY }}

      - name: Checkout pull request
        uses: actions/checkout@v3
        with:
          token: ${{ steps.generate-token.outputs.token }}
          fetch-depth: 0

      - name: Fast-forward & push
        env:
          PR_COMMIT: ${{ github.event.pull_request.head.sha }}
        run: |
          git checkout main
          git merge --ff-only "$PR_COMMIT"
          git push origin main

@mhostetter
Copy link

@mildred did you ever find a solution?

Unfortunately not being able to initiate my on: push workflows might force me to continue using GitHub's normal rebase & merge. 😞

@andreiborisov
Copy link

andreiborisov commented Apr 1, 2023

The solution is quite simple: instead of using automatically provided GITHUB_TOKEN which doesn't trigger events, create a personal access token, put it in GitHub secrets and use it as such:

- name: Fast-forward PR
  uses: endre-spotlab/[email protected]
  with:
    GITHUB_TOKEN: ${{ secrets.WORKFLOW_GITHUB_TOKEN }}

Where WORKFLOW_GITHUB_TOKEN is the name of the secret you've created.

@endre-spotlab probably makes sense to put it in README and close the issue, since it's a purposeful limitation of automatically provided GITHUB_TOKEN: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants