Coder Social home page Coder Social logo

fast-forward-js-action's Introduction

Fast Forward PR action

Merge pull request using fast forward only, if possible, moving base branch (target branch) to head branch (source branch). Comment success or failure messages on the pull request issue. The goal is to keep branches equal at the end of the merge.

git checkout target_base && git merge source_head --ff-only

As a more advanced use case, this action can also update status API (with success or failure), which can be used to block pr when status checks are required to pass before merging. You can also have different failure messages commented on the pr issue, based on the state of a staging and a production branch.

Example usage

  • Comment /fast-forward in a pull request.
  • Wait for the action to execute (~10 seconds)

To set-up this GitHub action in your repository, check out the example workflow description file in .github/workflows/. You can see one set up for the basic use case, and one for the advanced use case.

Inputs

  • GITHUB_TOKEN:
    • Automatically provided token, that can be used to authenticate on behalf of the GitHub action, with permissions limited to the repository that contains your workflow
  • success_message:
    • Generic success message, will be commented on the pull request, if pull-request fast forward succeeds
  • failure_message:
    • Generic failure message, Will be commented on the pull request, if pull-request fast forward fails
  • update_status:
    • Optional, if true, the status API is used to set failure or success as a state for the commit, which can be used to gate merging. Default value is false.
  • failure_message_same_stage_and_prod:
    • Optional, failure message, when pull-request fast forward fails, and staging branch equals production branch.
  • failure_message_diff_stage_and_prod:
    • Optional, failure message, when pull-request fast forward fails, and staging branch and production branch are at different commits
  • production_branch:
    • Optional, production branch name. Default value is master.
  • staging_branch:
    • Optional, staging or preproduction branch name. Default value is staging.

How to modify action

  • Change source code in src/
  • Compile ts to js tsc --build tsconfig.json
  • Commit changes

fast-forward-js-action's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fast-forward-js-action's Issues

Action fails when then branch is updated in PR by rebasing

Thanks for making this action.

I recently noticed, for some of triggering PRs, if the user updated any out-of-date branch by clicking the update branch button and with rebase option selected. Then running this action would cause a failure.

From the log it looks the action is trying to checking staging branch which doesn't exist in the repo.

Failed log
Run endre-spotlab/[email protected]
RequestError [HttpError]: Update is not a fast forward
    at /home/runner/work/_actions/endre-spotlab/fast-forward-js-action/2.1/node_modules/@octokit/request/dist-node/index.js:66:23
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  status: 422,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
    connection: 'close',
    'content-length': '126',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Thu, 20 Oct 2022 20:42:02 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    vary: 'Accept-Encoding, Accept, X-Requested-With',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': '0703:0DFF:1FAD39A:40EF280:6351B29A',
    'x-ratelimit-limit': '1000',
    'x-ratelimit-remaining': '998',
    'x-ratelimit-reset': '1666302122',
    'x-ratelimit-resource': 'core',
    'x-ratelimit-used': '2',
    'x-xss-protection': '0'
  },
  request: {
    method: 'PATCH',
    url: 'https://api.github.com/repos/NYK-Business-Systems-Americas/roro-uber/git/refs/heads/next',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit.js/16.41.0 Node.js/12.22.7 (Linux 5.15; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"sha":"db95c1f5048d641549d2d0ce63af99afd212a078","force":false}',
    request: { hook: [Function: bound bound register], validate: [Object] }
  },
  documentation_url: 'https://docs.github.com/rest/reference/git#update-a-reference'
}
RequestError [HttpError]: Branch not found
    at /home/runner/work/_actions/endre-spotlab/fast-forward-js-action/2.1/node_modules/@octokit/request/dist-node/index.js:66:23
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  status: 404,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset',
    connection: 'close',
    'content-encoding': 'gzip',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Thu, 20 Oct 2022 20:42:03 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    'transfer-encoding': 'chunked',
    vary: 'Accept-Encoding, Accept, X-Requested-With',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': '0707:50EF:218BF3A:44A71A8:6351B29B',
    'x-ratelimit-limit': '1000',
    'x-ratelimit-remaining': '994',
    'x-ratelimit-reset': '1666302122',
    'x-ratelimit-resource': 'core',
    'x-ratelimit-used': '6',
    'x-xss-protection': '0'
  },
  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/NYK-Business-Systems-Americas/roro-uber/branches/staging',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit.js/16.41.0 Node.js/12.22.7 (Linux 5.15; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound register], validate: [Object] }
  },
  documentation_url: 'https://docs.github.com/rest/reference/repos#get-a-branch'
}
Workflow File
name: Fast-Forward PR

on:
  issue_comment:
    types: [created]

jobs:
  fast_forward_job:
    name: Fast Forward
    if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/fast-forward')
    runs-on: ubuntu-latest
    steps:
      # To use this repository's private action, you must check out the repository
      - name: Checkout code into workspace directory
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      # Basic use case example
      - name: Fast Forward PR
        uses: endre-spotlab/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          success_message: 'Success! Fast forwarded ***target_base*** to ***source_head***! ```git checkout target_base && git merge source_head --ff-only``` '
          failure_message: 'Failed! Cannot do fast forward!'
          # staging_branch: 'main'
          # production_branch: 'prod'

In our use case, we typically merges pu/module/* branches into origin/next branch.

Does not creates a push event

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

how do i actually use this?

i copied your existing workflow word for word

but nothing happened

on:
  issue_comment:
    types: [created]

jobs:
  fast_forward_job:
    name: Fast Forward
    if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/fast-forward')
    runs-on: ubuntu-latest
    steps:
      # To use this repository's private action, you must check out the repository
      - name: Checkout
        uses: actions/checkout@v2
      # Basic use case example
      - name: Fast Forward PR
        id: ff-action
        uses:  ./
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          success_message: 'Success! Fast forwarded ***target_base*** to ***source_head***! ```git checkout target_base && git merge source_head --ff-only``` '
          failure_message: 'Failed! Cannot do fast forward!'

as fast-forward.yml then i type /fast-forward in a pull request as comment. nothing happened

Does anyone have an updated working example of how to use this action?

I've followed a few examples provided from users in a few different issues and haven't had any luck. I've created a repository secret in lieu of the automatically applied GITHUB_SECRET mentioned in the docs.

Here's what I have in my repo, stored in a ff-merge.yml file under the following directory structure: [REPO]/.github/workflows/ff-merge.yml

With this installed in my repo, I'm still unable to get FF merges working via Github UI when commenting /fast-forward. Going to utilize CLI merges as a workaround for now....

name: Fast-Forward PR

on: 
  issue_comment:
    types: [created]

jobs:
  fast_forward_job:
    name: Fast Forward
    if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/fast-forward')   
    runs-on: ubuntu-latest
    steps:
      # To use this repository's private action, you must check out the repository
      - name: Checkout code into workspace directory
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      # Basic use case example
      - name: Fast Forward PR
        id: ff-action
        uses: endre-spotlab/fast-forward-js-action@master
        with:
          GITHUB_TOKEN: ${{ secrets.ACTION_SECRET }}
          success_message: 'Success! Fast forwarded ***target_base*** to ***source_head***! ```git checkout target_base && git merge source_head --ff-only``` '
          failure_message: 'Failed! Cannot do fast forward!'
          staging_branch: 'stage'
          production_branch: 'main'

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.