Compare commits

...

14 Commits

Author SHA1 Message Date
7beba58e42 Merge pull request #45 from peter-evans/git-lfs
Update Docker Image to include support for git-lfs
2019-09-26 13:27:02 +09:00
062968931c Update Docker Image to include support for git-lfs 2019-09-26 12:34:25 +09:00
76116b7f39 Update README 2019-09-25 23:58:47 +09:00
e635c55400 Update README 2019-09-25 09:42:45 +09:00
9e25487be4 Update workflows 2019-09-25 09:25:52 +09:00
39529236f7 Update README 2019-09-24 20:35:00 +09:00
f0728e6543 Update README 2019-09-24 20:27:25 +09:00
188c998f8f Update README 2019-09-24 20:23:49 +09:00
1fc2947eb6 Merge pull request #42 from peter-evans/new-params
New parameters
2019-09-24 20:13:43 +09:00
4e47f5e151 Add branch suffix parameter 2019-09-24 20:00:49 +09:00
e543bbd98a Merge pull request #41 from ScriptAutomate/master
Add skip_ignore arg to ignore_event function
2019-09-24 19:21:12 +09:00
4fb3c76ad7 Introduced SKIP_IGNORE env variable option
If the SKIP_IGNORE env var is present, the ignore_event function will not run
2019-09-24 01:08:16 -07:00
fcc56736a6 Add skip_ignore arg to ignore_event function
During testing, I found it useful to have this function skipped so I added a simple check for SKIP_IGNORE env variable
2019-09-24 00:56:53 -07:00
014d447f0c Update README 2019-09-20 10:23:15 +09:00
6 changed files with 79 additions and 25 deletions

View File

@ -0,0 +1,28 @@
on:
repository_dispatch:
types: [create-pull-request-multi]
name: create-pull-request action testing workflow
jobs:
createPullRequest:
name: Testing on ${{ matrix.platform }}
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@master
- name: Create report file
if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest'
run: touch report.txt
- name: Create report file (windows)
if: matrix.platform == 'windows-latest'
run: type NUL > report.txt
- name: Create Pull Request
uses: peter-evans/create-pull-request@multi-platform-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: Add report file
PULL_REQUEST_BODY: This PR is auto-generated by [create-pull-request](https://github.com/peter-evans/create-pull-request).
PULL_REQUEST_BRANCH: test-patches
PULL_REQUEST_TITLE: '[Test] Add report file'
BRANCH_SUFFIX: 'timestamp'

View File

@ -1,6 +1,6 @@
on:
repository_dispatch:
types: [test]
types: [create-pull-request]
name: create-pull-request action testing workflow
jobs:
createPullRequest:
@ -8,10 +8,7 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Create report file
uses: finnp/create-file-action@1.0.0
env:
FILE_DATA: This is created to test create-pull-request action.
FILE_NAME: report.txt
run: touch report.txt
- name: Create Pull Request
uses: ./
env:

View File

@ -1,4 +1,4 @@
FROM python:3.7.3
FROM alpine:3.10.2
LABEL maintainer="Peter Evans <mail@peterevans.dev>"
LABEL repository="https://github.com/peter-evans/create-pull-request"
@ -11,8 +11,10 @@ LABEL com.github.actions.color="gray-dark"
COPY LICENSE README.md /
RUN apk add python3-dev git git-lfs
COPY requirements.txt /tmp/
RUN pip install --requirement /tmp/requirements.txt
RUN pip3 install --requirement /tmp/requirements.txt
COPY create-pull-request.py /create-pull-request.py
ENTRYPOINT [ "/create-pull-request.py" ]
ENTRYPOINT [ "/create-pull-request.py" ]

View File

@ -3,31 +3,36 @@
A GitHub action to create a pull request for changes to your repository in the actions workspace.
Changes to a repository in the actions workspace persist between actions in a workflow.
This action is designed to be used in conjunction with other actions that modify or add files to your repository.
Changes to a repository in the Actions workspace persist between steps in a workflow.
This action is designed to be used in conjunction with other steps that modify or add files to your repository.
The changes will be automatically committed to a new branch and a pull request created.
Create Pull Request action will:
1. Check for repository changes in the actions workspace. This includes untracked (new) files as well as modified files.
1. Check for repository changes in the Actions workspace. This includes untracked (new) files as well as modified files.
2. Commit all changes to a new branch. The commit will be made using the name and email of the `HEAD` commit author.
3. Create a pull request to merge the new branch into the currently active branch executing the workflow.
Note: Modifying a repository during workflows is not good practice in general.
However, this action opens up some interesting possibilities when used carefully.
This action is experimental and may not work well for repositories that have a very high frequency of commits.
This action is experimental and may not work well for some use cases.
## Usage
In addition to the default `GITHUB_TOKEN`, the action requires a `repo` scoped token in order to commit.
Create one [here](https://github.com/settings/tokens) and pass that as a secret to the `REPO_ACCESS_TOKEN` environment variable.
Linux
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.1.4
uses: peter-evans/create-pull-request@v1.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Multi platform - Linux, MacOS, Windows (beta)
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.2.1-multi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
```
#### Environment variables
@ -35,10 +40,16 @@ Create one [here](https://github.com/settings/tokens) and pass that as a secret
These variables are all optional. If not set, a default value will be used.
- `PULL_REQUEST_BRANCH` - The branch name. See **Branch naming** below for details.
- `BRANCH_SUFFIX` - The branch suffix type. Valid values are `short-commit-hash` (default) and `timestamp`. See **Branch naming** below for details.
- `COMMIT_MESSAGE` - The message to use when committing changes.
- `PULL_REQUEST_TITLE` - The title of the pull request.
- `PULL_REQUEST_BODY` - The body of the pull request.
The following parameters are available for debugging and troubleshooting.
- `DEBUG_EVENT` - If present, outputs the event data that triggered the workflow.
- `SKIP_IGNORE` - If present, the `ignore_event` function will be skipped.
#### Branch naming
The variable `PULL_REQUEST_BRANCH` defaults to `create-pull-request/patch`.
@ -50,21 +61,29 @@ create-pull-request/patch-fcdfb59
create-pull-request/patch-394710b
```
Alternatively, branches can be suffixed with a timestamp by setting the environment variable `BRANCH_SUFFIX` to the value `timestamp`. This option must be used if multiple pull requests will be created during the execution of a workflow.
e.g.
```
create-pull-request/patch-1569322532
create-pull-request/patch-1569322552
```
#### Ignoring files
If there are files or directories you want to ignore you can simply add them to a `.gitignore` file at the root of your repository. The action will respect this file.
## Example
Here is an example that sets all the environment variables.
Here is an example that sets all the main environment variables.
```yml
- name: Create Pull Request
uses: peter-evans/create-pull-request@v1.1.4
uses: peter-evans/create-pull-request@v1.2.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
PULL_REQUEST_BRANCH: my-patches
BRANCH_SUFFIX: short-commit-hash
COMMIT_MESSAGE: Auto-modify files by my-file-modifier-action
PULL_REQUEST_TITLE: Changes from my-file-modifier-action
PULL_REQUEST_BODY: This is an auto-generated PR with changes from my-file-modifier-action

View File

@ -2,6 +2,7 @@
''' Create Pull Request '''
import json
import os
import time
from git import Repo
from github import Github
@ -9,7 +10,7 @@ from github import Github
def get_github_event(github_event_path):
with open(github_event_path) as f:
github_event = json.load(f)
if os.environ.get('DEBUG_EVENT') is not None:
if bool(os.environ.get('DEBUG_EVENT')):
print(os.environ['GITHUB_EVENT_NAME'])
print(json.dumps(github_event, sort_keys=True, indent=2))
return github_event
@ -122,7 +123,8 @@ def process_event(event_name, event_data, repo, branch, base):
event_name = os.environ['GITHUB_EVENT_NAME']
event_data = get_github_event(os.environ['GITHUB_EVENT_PATH'])
# Check if this event should be ignored
if not ignore_event(event_name, event_data):
skip_ignore_event = bool(os.environ.get('SKIP_IGNORE'))
if skip_ignore_event or not ignore_event(event_name, event_data):
# Set the repo to the working directory
repo = Repo(os.getcwd())
@ -133,8 +135,14 @@ if not ignore_event(event_name, event_data):
# Skip if the current branch is a PR branch created by this action
if not base.startswith(branch):
# Suffix with the short SHA1 hash
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
# Fetch an optional environment variable to determine the branch suffix
branch_suffix = os.getenv('BRANCH_SUFFIX', 'short-commit-hash')
if branch_suffix == "timestamp":
# Suffix with the current timestamp
branch = "%s-%s" % (branch, int(time.time()))
else:
# Suffix with the short SHA1 hash
branch = "%s-%s" % (branch, get_head_short_sha1(repo))
# Check if a PR branch already exists for this HEAD commit
if not pr_branch_exists(repo, branch):

View File

@ -1,2 +1,2 @@
GitPython==3.0.2
PyGithub==1.43.8
PyGithub==1.43.8