Skip to content

Commit

Permalink
Switch to a GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex committed Nov 17, 2019
1 parent 668468c commit ce3759c
Show file tree
Hide file tree
Showing 24 changed files with 1,424 additions and 4,768 deletions.
44 changes: 0 additions & 44 deletions .circleci/config.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!.eslintrc.js
/dist/
55 changes: 55 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"use strict";

module.exports = {
env: {
es6: true,
},
extends: [
"plugin:unicorn/recommended",
"xo",
"xo-typescript",
"prettier",
"prettier/@typescript-eslint",
],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 2018,
project: "tsconfig.json",
sourceType: "module",
},
plugins: ["sort-destructure-keys", "typescript-sort-keys", "unicorn"],
root: true,
rules: {
// @actions/github uses a lot of snake_case keys.
"@typescript-eslint/camelcase": "off",
// TypeScript is good at type inference and already requires types where they matter: exported symbols.
"@typescript-eslint/explicit-function-return-type": "off",
// We use sort-keys instead.
"@typescript-eslint/member-ordering": "off",
"arrow-body-style": "error",
// Forbid function declarations
"func-style": ["error", "expression", { allowArrowFunctions: true }],
// It's fine to use await in for loops instead of Promise.all to execute promises sequentially.
"no-await-in-loop": "off",
"no-console": "error",
// TypeScript already takes care of that. See https://github.com/bradzacher/eslint-plugin-typescript/issues/110.
"no-undef": "off",
"object-shorthand": [
"error",
"always",
{ avoidExplicitReturnArrows: true },
],
"sort-destructure-keys/sort-destructure-keys": [
"error",
{ caseSensitive: false },
],
"sort-keys": [
"error",
"asc",
{ caseSensitive: false, minKeys: 2, natural: true },
],
"typescript-sort-keys/interface": "error",
"typescript-sort-keys/string-enum": "error",
"unicorn/prevent-abbreviations": ["error", { whitelist: { args: true } }],
},
};
22 changes: 22 additions & 0 deletions .github/workflows/autosquash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Autosquash
on:
check_run:
types:
- completed
pull_request:
types:
- closed
- labeled
pull_request_review:
types:
- submitted
status: {}

jobs:
autosquash:
name: Autosquash
runs-on: ubuntu-18.04
steps:
- uses: tibdex/autosquash@v2
with:
github_token: ${{ secrets.AUTOSQUASH_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Backport
on:
pull_request:
types:
- closed
- labeled

jobs:
backport:
runs-on: ubuntu-18.04
name: Backport
steps:
- name: Backport
uses: tibdex/backport@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Publish
on:
push:
branches:
- master

jobs:
publish:
name: Publish
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- uses: dylanvann/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Test
on:
push:
branches-ignore:
- master

jobs:
test:
name: Test
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Install
run: yarn install --frozen-lockfile
- name: Build
run: yarn run build
- name: ESLint
run: yarn run eslint
- name: Prettier
run: yarn run check-prettier
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/.env
/coverage/
/node_modules/
/reports/
/dist
/node_modules
46 changes: 0 additions & 46 deletions CODE_OF_CONDUCT.md

This file was deleted.

8 changes: 0 additions & 8 deletions LICENSE

This file was deleted.

32 changes: 3 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
[![build status](https://img.shields.io/circleci/project/github/tibdex/backport.svg)](https://circleci.com/gh/tibdex/backport)
Backport is a [JavaScript GitHub Action](https://help.github.com/en/articles/about-actions#javascript-actions) to backport a pull request by simply adding a label to it.

# Goal

Backport is a GitHub App, based on [Probot](https://probot.github.io/), to backport a pull request by simply adding a label to it. [Try it!](https://github.com/apps/backporting)
It can backport [rebased and merged](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#rebase-and-merge-your-pull-request-commits) pull requests with a single commit and [squashed and merged](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-request-merges#squash-and-merge-your-pull-request-commits) pull requests. It thus integrates well with [Autosquash](https://github.com/marketplace/actions/autosquash).

# Usage

1. :electric_plug: Install the publicly hosted [Backport GitHub App](https://github.com/apps/backporting) on your repository.
1. :electric_plug: Add this [.github/workflows/backport.yml](.github/workflows/backport.yml) to your repository.
2. :speech_balloon: Let's say you want to backport a pull request on a branch named `production`. Then label it with `backport production`. (See [how to create labels](https://help.github.com/articles/creating-a-label/).)
3. :sparkles: That's it! When the pull request gets merged, it will be backported to the `production` branch. If the pull request cannot be backported, a comment explaining why will automatically be posted.

_Note:_ multiple backport labels can be added. For example, if a pull request has the labels `backport staging` and `backport production` it will be backported to both branches: `staging` and `production`.

## Demo

![Backport demo](./assets/demo.gif)

This pull request has two commits and targets the `development` branch. After labeling it with `backport production` and merging it, Backport automatically creates a pull request on the `production` branch by cherry-picking these two commits.

# How it Works

Backport relies on [`github-backport`](https://www.npmjs.com/package/github-backport) to perform all the required Git operations directly through the GitHub REST API instead of having to clone repositories on a server and executing Git CLI commands.

`github-backport` is the :old_key: to being able to run Backport as a stateless, easy to maintain, and cheap to operate, GitHub App!

## Which Permissions & Webhooks Is Backport Using?

### Permissions

- **Repository contents** _[read & write]_: because the backporting process requires creating commits and manipulating branches.
- **Issues** _[read & write]_: to post comments when the backport process fails.
- **Pull requests** _[read & write]_: to create new pull requests.

### Webhooks

- **Pull requests**: to detect when pull requests are merged or labeled.
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Backporting
author: Thibault Derousseaux <[email protected]>
description: Automatically backport PRs to other branches by simply labeling them.
inputs:
github_token:
description: Token for the GitHub API.
required: true
runs:
using: node12
main: dist/index.js
branding:
icon: arrow-left-circle
color: purple
Binary file removed assets/demo.gif
Binary file not shown.
16 changes: 0 additions & 16 deletions jest.config.js

This file was deleted.

14 changes: 0 additions & 14 deletions now.json

This file was deleted.

Loading

0 comments on commit ce3759c

Please sign in to comment.