Skip to content

Commit

Permalink
feat: use gh in composite action (#938)
Browse files Browse the repository at this point in the history
* feat: use gh in composite action

* add shell

* syntax

* token name

* input name

* don't build just test

* remove needs build

* remove typescript code

* update approve step

* use artifact to test pr branch

* fix workflow

* sha to branch name

* update readme

* update readme

* remove unnecessary files

* test matrix os

* multi-os lowercase

* missing output name

* update readme

* bump major
  • Loading branch information
peter-evans authored Mar 23, 2023
1 parent c2125c1 commit a660677
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 24,458 deletions.
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

18 changes: 0 additions & 18 deletions .eslintrc.json

This file was deleted.

1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

12 changes: 0 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "thursday"
labels:
- "dependencies"

- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
day: "thursday"
open-pull-requests-limit: 1
ignore:
- dependency-name: "*"
update-types: ["version-update:semver-major"]
labels:
- "dependencies"

87 changes: 19 additions & 68 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
- run: npm ci
- run: npm run build
- run: npm run format-check
- run: npm run lint
- run: npm run test
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
- uses: actions/upload-artifact@v3
with:
name: action.yml
Expand All @@ -40,21 +28,15 @@ jobs:
testWithRequiredStatusChecks:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
target: [built, committed]
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
ref: ci-test/status-check-base-${{ matrix.target }}
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v3
ref: ci-test/status-check-base-${{ matrix.os }}
- uses: actions/download-artifact@v3
with:
name: action.yml
path: .
Expand All @@ -67,17 +49,17 @@ jobs:
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
commit-message: '[CI] test ${{ matrix.target }}'
commit-message: '[CI] test ${{ matrix.os }}'
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: '[CI] test ${{ matrix.target }}'
title: '[CI] test ${{ matrix.os }}'
body: |
- CI test case for target '${{ matrix.target }}'
- CI test case for target '${{ matrix.os }}'
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: ci-test/status-check-branch-${{ matrix.target }}
branch: ci-test/status-check-branch-${{ matrix.os }}-${{ github.sha }}

- name: Enable Pull Request Automerge
uses: ./
Expand All @@ -89,21 +71,15 @@ jobs:
testWithRequiredReviews:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
needs: [build]
runs-on: ubuntu-latest
strategy:
matrix:
target: [built, committed]
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
ref: ci-test/reviews-base-${{ matrix.target }}
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v3
with:
name: dist
path: dist
- if: matrix.target == 'built' || github.event_name == 'pull_request'
uses: actions/download-artifact@v3
ref: ci-test/reviews-base-${{ matrix.os }}
- uses: actions/download-artifact@v3
with:
name: action.yml
path: .
Expand All @@ -116,17 +92,17 @@ jobs:
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
commit-message: '[CI] test ${{ matrix.target }}'
commit-message: '[CI] test ${{ matrix.os }}'
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
title: '[CI] test ${{ matrix.target }}'
title: '[CI] test ${{ matrix.os }}'
body: |
- CI test case for target '${{ matrix.target }}'
- CI test case for target '${{ matrix.os }}'
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: ci-test/reviews-branch-${{ matrix.target }}-${{ github.sha }}
branch: ci-test/reviews-branch-${{ matrix.os }}-${{ github.sha }}

- name: Enable Pull Request Automerge
uses: ./
Expand All @@ -137,31 +113,6 @@ jobs:

- name: Auto approve
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/approve-pull-request-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.cpr.outputs.pull-request-number }}

package:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [testWithRequiredStatusChecks, testWithRequiredReviews]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.ACTIONS_BOT_TOKEN }}
commit-message: Update distribution
title: Update distribution
body: |
- Updates the distribution for changes on `main`
Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
branch: update-distribution
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 0 additions & 21 deletions .github/workflows/rebase-command.yml

This file was deleted.

15 changes: 0 additions & 15 deletions .github/workflows/slash-command-dispatch.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/update-major-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
description: The major version tag to update
options:
- v2
- v3

jobs:
tag:
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
lib/
node_modules/

.DS_Store
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

11 changes: 0 additions & 11 deletions .prettierrc.json

This file was deleted.

31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

A GitHub action to [enable auto-merge](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/automatically-merging-a-pull-request) on a pull request.

:warning: There are very specific conditions under which this action will work. See [Conditions](#conditions) for details.
:warning: There are very specific conditions under which this action will work as expected. See [Conditions](#conditions) for details.

## Usage

| :exclamation: Using this action is no longer necessary |
|-----------------------------------------------------------|

The same functionality exists in the GitHub CLI. See the documentation [here](https://cli.github.com/manual/gh_pr_merge).
```yml
- uses: peter-evans/enable-pull-request-automerge@v2
- name: Enable Pull Request Automerge
run: gh pr merge --merge --auto "1"
env:
GH_TOKEN: ${{ secrets.PAT }}
```
If you prefer to use this action:
```yml
- uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.PAT }}
pull-request-number: 1
Expand All @@ -26,11 +38,11 @@ A GitHub action to [enable auto-merge](https://docs.github.com/en/github/collabo

### Conditions

This action uses a GitHub API that only works under specific conditions. All of the following conditions must be true for this action to succeed.
The following conditions must be true for auto-merge to be enabled on a pull request.

1. The target repository must have [Allow auto-merge](https://docs.github.com/en/github/administering-a-repository/managing-auto-merge-for-pull-requests-in-your-repository) enabled in settings.
2. The pull request `base` must have a branch protection rule with at least one requirement enabled.
3. The pull request must be in a state where requirements have not yet been satisfied. If the pull request can already be merged, attempting to enable auto-merge will fail.
3. The pull request must be in a state where requirements have not yet been satisfied. If the pull request is in a state where it can already be merged, the action will merge it immediately without enabling auto-merge.

### Dependabot example

Expand All @@ -51,7 +63,7 @@ jobs:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: peter-evans/enable-pull-request-automerge@v2
- uses: peter-evans/enable-pull-request-automerge@v3
with:
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: squash
Expand All @@ -74,7 +86,7 @@ In the following example [create-pull-request](https://github.com/peter-evans/cr
- name: Enable Pull Request Automerge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v2
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
Expand All @@ -87,10 +99,9 @@ The `if` condition makes sure we don't approve multiple times if the workflow ex
```yml
- name: Auto approve
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: juliangruber/approve-pull-request-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.cpr.outputs.pull-request-number }}
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

## License
Expand Down
17 changes: 14 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@ inputs:
required: true
merge-method:
description: 'The merge method to use. `merge`, `rebase` or `squash`.'
default: MERGE
default: merge
runs:
using: 'node16'
main: 'dist/index.js'
using: composite
steps:
- name: Lowercase
id: lowercase
shell: bash
run: |
echo merge-method=$(echo "${{ inputs.merge-method }}" | tr '[:upper:]' '[:lower:]') >> $GITHUB_OUTPUT
- name: Enable automerge
shell: bash
run: gh pr merge -R "${{ inputs.repository }}" --${{ steps.lowercase.outputs.merge-method }} --auto "${{ inputs.pull-request-number }}"
env:
GH_TOKEN: ${{ inputs.token }}
branding:
icon: 'git-pull-request'
color: 'gray-dark'
Loading

0 comments on commit a660677

Please sign in to comment.