https://github.com/sof3/octodiff
GitHub action to send PR when git diff is dirty
https://github.com/sof3/octodiff
Last synced: 10 months ago
JSON representation
GitHub action to send PR when git diff is dirty
- Host: GitHub
- URL: https://github.com/sof3/octodiff
- Owner: SOF3
- License: gpl-3.0
- Created: 2020-11-19T04:44:42.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-25T03:49:00.000Z (about 5 years ago)
- Last Synced: 2025-01-25T10:41:16.754Z (12 months ago)
- Language: TypeScript
- Size: 5.67 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# octodiff
Create a pull request when git diff is dirty.
Let's say we have a tool that modifies our source code a bit,
e.g. a code formatter.
Since the workflow is automatic, we don't want to overwrite the branch.
Instead, the workflow creates a *pull request* if the working directory is dirty,
similar to the dependabot style.
octodiff **only** affects branches starting with `octodiff/`.
Furthermore, octodiff always force-pushes.
Do not name any other branches starting with `octodiff/`
unless you are merging.
## Usage
Put the following step in your action file
after you have performed steps that might modify files:
```yaml
- uses: SOF3/octodiff
with:
token: ${{secrets.GH_TOKEN}}
# commitMessage: "$GITHUB_WORKFLOW for $GITHUB_SHA"
# prTitle: "$GITHUB_WORKFLOW for $GITHUB_BRANCH"
```
Create a user access token at
with the `repo` (or `public_repo`) scope.
Setup the secret `GH_TOKEN` at your repo settings page
(`https://github.com///settings/secrets/actions`)
and pass it to the workflow.
The optional parameters `commitMessage` and `prTitle`
are the templates of commit and pull request titles.
All environment variables available in a workflow are available
(see ),
as well as `GITHUB_BRANCH` and `OCTODIFF_BRANCH`
for the current branch and the branch being used by octodiff.
Note that it does not make sense to use octodiff on tags.
## Note
octodiff uses `git diff HEAD` to check changes in *tracked* files.
To check changes with *new* files,
add `run: git add -A` before the octodiff step.
## Example
### `rustfmt`
```yaml
name: rustfmt
on:
push:
branches: "**"
jobs:
rustfmt:
runs-on: [ubuntu-20.04]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
components: rustfmt
- run: cargo fmt
- uses: SOF3/octodiff@v1
with:
token: ${{secrets.GH_TOKEN}}
```
### `black` (python)
```yaml
name: python reformat
on:
push:
branches: "**"
jobs:
black:
runs-on: [ubuntu-20.04]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.9"
- run: pip3 install black
- run: black src
- uses: SOF3/octodiff@v1
with:
token: ${{secrets.GH_TOKEN}}
```