mirror of
https://github.com/stefanzweifel/git-auto-commit-action.git
synced 2025-08-01 07:56:08 +08:00
Compare commits
95 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a7342eab13 | ||
|
256f31683d | ||
|
8040ba33d6 | ||
|
80c7ed953f | ||
|
dd055f6225 | ||
|
55734408b7 | ||
|
d317154f77 | ||
|
36489f4cb5 | ||
|
2530046e72 | ||
|
172c2a2fc3 | ||
|
480e111bf8 | ||
|
7659782c71 | ||
|
026f88c27c | ||
|
f73d11d461 | ||
|
2b6b90e8f1 | ||
|
e1770ec52b | ||
|
0453bb1c25 | ||
|
da55e4a0cf | ||
|
b1833bd054 | ||
|
6dfda22dd6 | ||
|
94c72aa7c5 | ||
|
87526a8aa1 | ||
|
844c808726 | ||
|
ce08dda6b3 | ||
|
0ad4c8ce73 | ||
|
3387b2f267 | ||
|
d4a53f1779 | ||
|
956a47433b | ||
|
f866b2a854 | ||
|
8744cc88ef | ||
|
57bbd38e56 | ||
|
eef5f33ea3 | ||
|
25e6f0b17d | ||
|
ae885f5d8c | ||
|
33e8fd937f | ||
|
404d2015f4 | ||
|
cd0530ad7a | ||
|
2a957f5c41 | ||
|
7e64e614a1 | ||
|
c887fa4a07 | ||
|
09d175379e | ||
|
cdb861eda0 | ||
|
6a853b60cc | ||
|
76f50fc3ad | ||
|
9b4acb8f10 | ||
|
d11ccd183d | ||
|
a156a1072e | ||
|
d69e5f0850 | ||
|
86f0c11c06 | ||
|
eda98fb9e5 | ||
|
844e852dde | ||
|
cca75e0840 | ||
|
ef107e1d4b | ||
|
e97d20ce65 | ||
|
3c9d7dd29d | ||
|
4ff392a586 | ||
|
69c53bd75e | ||
|
8563bc2c47 | ||
|
657dcb0873 | ||
|
1d39bb676c | ||
|
864c975b87 | ||
|
33592697c4 | ||
|
13e281008a | ||
|
42e5be9ebb | ||
|
f0354eba45 | ||
|
af7b14b2cf | ||
|
5a4e81ccd7 | ||
|
0884c39e7e | ||
|
5ab45a4eef | ||
|
e20b39e8ed | ||
|
5df30c89b8 | ||
|
b197c5ff8c | ||
|
098f1a8051 | ||
|
a06032e34f | ||
|
3185f2bd2a | ||
|
5432544bdb | ||
|
0a5fd7e510 | ||
|
81fa501ea5 | ||
|
3c60dc19b2 | ||
|
0822a9b930 | ||
|
d47024e59c | ||
|
ae384f95d0 | ||
|
959e7d4eab | ||
|
b21b1abc6d | ||
|
35440b9386 | ||
|
99f6ce74b4 | ||
|
4ab94c0ec4 | ||
|
1a9ba81dae | ||
|
2043118160 | ||
|
9879efa581 | ||
|
3525430c70 | ||
|
db25cb8fde | ||
|
5dd90bb58c | ||
|
36610a4da0 | ||
|
26a56d2023 |
31
.github/workflows/continuous-deployment.yml
vendored
Normal file
31
.github/workflows/continuous-deployment.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
|
||||||
|
|
||||||
|
name: "Continuous Deployment"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
name: "Release"
|
||||||
|
|
||||||
|
runs-on: "ubuntu-latest"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Determine tag"
|
||||||
|
id: "determine-tag"
|
||||||
|
run: "echo \"::set-output name=tag::${GITHUB_REF#refs/tags/}\""
|
||||||
|
|
||||||
|
- name: "Create release"
|
||||||
|
uses: "actions/create-release@v1.0.0"
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
with:
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
body: |
|
||||||
|
See [Changelog](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/CHANGELOG.md) for details.
|
||||||
|
release_name: "${{ steps.determine-tag.outputs.tag }}"
|
||||||
|
tag_name: "${{ steps.determine-tag.outputs.tag }}"
|
22
.github/workflows/git-auto-commit.yml
vendored
Normal file
22
.github/workflows/git-auto-commit.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
name: git-auto-commit
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
git-auto-commit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use git-auto-commit-action
|
||||||
|
id: "auto-commit-action"
|
||||||
|
uses: ./
|
||||||
|
|
||||||
|
- name: "no changes detected"
|
||||||
|
if: steps.auto-commit-action.outputs.changes_detected == false
|
||||||
|
run: "echo \"No changes detected\""
|
||||||
|
|
||||||
|
- name: "changes detected"
|
||||||
|
if: steps.auto-commit-action.outputs.changes_detected == true
|
||||||
|
run: "echo \"Changes detected\""
|
42
CHANGELOG.md
42
CHANGELOG.md
@@ -4,9 +4,47 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.5.0...HEAD)
|
## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.3...HEAD)
|
||||||
|
|
||||||
|
## [v4.1.3](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.2...v4.1.3) - 2020-04-18
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Place Git user configuration inline [#59](https://github.com/stefanzweifel/git-auto-commit-action/pull/59)
|
||||||
|
|
||||||
|
## [v4.1.2](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.1...v4.1.2) - 2020-04-03
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix Issue with `changes_detected`-output [#57](https://github.com/stefanzweifel/git-auto-commit-action/pull/57)
|
||||||
|
|
||||||
|
## [v4.1.1](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.1.0...v4.1.1) - 2020-03-14
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- Fix issue where commit has not been pushed to remote repository, when no `branch`-option has been given [#54](https://github.com/stefanzweifel/git-auto-commit-action/pull/54)
|
||||||
|
|
||||||
|
|
||||||
|
## [v4.1.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.0.0...v4.1.0) - 2020-03-05
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add `changes_detected` output [#49](https://github.com/stefanzweifel/git-auto-commit-action/pull/49), [#46](https://github.com/stefanzweifel/git-auto-commit-action/issues/46)
|
||||||
|
- Add `tagging_message` input option to create and push tags [#50](https://github.com/stefanzweifel/git-auto-commit-action/pull/50), [#47](https://github.com/stefanzweifel/git-auto-commit-action/issues/47)
|
||||||
|
|
||||||
|
|
||||||
|
## [v4.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v3.0.0...v4.0.0) - 2020-02-24
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Switch Action to use `node12`-environment instead of `docker`. [#45](https://github.com/stefanzweifel/git-auto-commit-action/pull/45)
|
||||||
|
|
||||||
|
## [v3.0.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.5.0...v3.0.0) - 2020-02-06
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add `commit_user_name`, `commit_user_email` and `commit_author` input options for full customzation on how the commit is being created [#39](https://github.com/stefanzweifel/git-auto-commit-action/pull/39)
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Make the `branch` input option optional [#41](https://github.com/stefanzweifel/git-auto-commit-action/pull/41)
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- Remove the need of a GITHUB_TOKEN. Users now have to use `actions/checkout@v2` or higher [#36](https://github.com/stefanzweifel/git-auto-commit-action/pull/36)
|
||||||
|
|
||||||
> TBD
|
|
||||||
|
|
||||||
## [v2.5.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.4.0...v2.5.0) - 2019-12-18
|
## [v2.5.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v2.4.0...v2.5.0) - 2019-12-18
|
||||||
|
|
||||||
|
17
Dockerfile
17
Dockerfile
@@ -1,17 +0,0 @@
|
|||||||
FROM alpine/git:1.0.7
|
|
||||||
|
|
||||||
LABEL "com.github.actions.name"="Auto Commit changed files"
|
|
||||||
LABEL "com.github.actions.description"="Automatically commits files which have been changed during the workflow run and push changes back to remote repository."
|
|
||||||
LABEL "com.github.actions.icon"="git-commit"
|
|
||||||
LABEL "com.github.actions.color"="orange"
|
|
||||||
|
|
||||||
LABEL "repository"="http://github.com/stefanzweifel/git-auto-commit-action"
|
|
||||||
LABEL "homepage"="http://github.com/stefanzweifel/git-auto-commit-action"
|
|
||||||
LABEL "maintainer"="Stefan Zweifel <hello@stefanzweifel.io>"
|
|
||||||
|
|
||||||
RUN apk add git-lfs
|
|
||||||
|
|
||||||
COPY lib.sh /lib.sh
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
|
||||||
|
|
||||||
ENTRYPOINT ["sh", "/entrypoint.sh"]
|
|
120
README.md
120
README.md
@@ -1,21 +1,28 @@
|
|||||||
# git-auto-commit-action
|
# git-auto-commit-action
|
||||||
|
|
||||||
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the Commit back to GitHub.
|
This GitHub Action automatically commits files which have been changed during a Workflow run and pushes the commit back to GitHub.
|
||||||
The Committer is "GitHub Actions <actions@github.com>" and the Author of the Commit is "Your GitHub Username <github_username@users.noreply.github.com>.
|
The default committer is "GitHub Actions <actions@github.com>" and the default author of the commit is "Your GitHub Username <github_username@users.noreply.github.com>".
|
||||||
|
|
||||||
If no changes are available, the Actions does nothing.
|
If no changes are detected, the Action does nothing.
|
||||||
|
|
||||||
This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
|
This Action has been inspired and adapted from the [auto-commit](https://github.com/cds-snc/github-actions/tree/master/auto-commit
|
||||||
)-Action of the Canadian Digital Service and the [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
|
)-Action of the Canadian Digital Service and this [commit](https://github.com/elstudio/actions-js-build/blob/41d604d6e73d632e22eac40df8cc69b5added04b/commit/entrypoint.sh)-Action by Eric Johnson.
|
||||||
|
|
||||||
|
*This Action currently can't be used in conjunction with pull requests of forks. See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.*
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
**Note:** This Action requires that you use `action/checkout@v2` or above to checkout your repository.
|
||||||
|
|
||||||
Add the following step at the end of your job.
|
Add the following step at the end of your job.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v2.5.0
|
- uses: stefanzweifel/git-auto-commit-action@v4.1.2
|
||||||
with:
|
with:
|
||||||
commit_message: Apply automatic changes
|
commit_message: Apply automatic changes
|
||||||
|
|
||||||
|
# Optional name of the branch the commit should be pushed to
|
||||||
|
# Required if Action is used in Workflow listening to the `pull_request` event
|
||||||
branch: ${{ github.head_ref }}
|
branch: ${{ github.head_ref }}
|
||||||
|
|
||||||
# Optional git params
|
# Optional git params
|
||||||
@@ -24,62 +31,129 @@ Add the following step at the end of your job.
|
|||||||
# Optional glob pattern of files which should be added to the commit
|
# Optional glob pattern of files which should be added to the commit
|
||||||
file_pattern: src/\*.js
|
file_pattern: src/\*.js
|
||||||
|
|
||||||
# Optional repository path
|
# Optional local file path to the repository
|
||||||
repository: .
|
repository: .
|
||||||
|
|
||||||
env:
|
# Optional commit user and author settings
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
commit_user_name: My GitHub Actions Bot
|
||||||
```
|
commit_user_email: my-github-actions-bot@example.org
|
||||||
|
commit_author: Author <actions@github.com>
|
||||||
|
|
||||||
You **do not** have to create a new secret called `GITHUB_TOKEN` in your repository. `GITHUB_TOKEN` is a special token GitHub creates automatically during an Action run. (See [the documentation](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) for details)
|
# Optional tag message. Will create and push a new tag to the remote repository
|
||||||
|
tagging_message: 'v1.0.0'
|
||||||
|
```
|
||||||
|
|
||||||
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
|
The Action will only commit files back, if changes are available. The resulting commit **will not trigger** another GitHub Actions Workflow run!
|
||||||
|
|
||||||
It is recommended to use this Action in Workflows which listen to the `pull_request` event. If you want to use the Action on other events, you have to hardcode the value for `branch` as `github.head_ref` is only available in Pull Requests.
|
We recommend to use this Action in Workflows, which listen to the `pull_request` event. You can then use the option `branch: ${{ github.head_ref }}` to set up the branch name correctly.
|
||||||
|
If you don't pass a branch name, the Action will try to push the commit to a branch with the same name, as with which the repo has been checked out.
|
||||||
|
|
||||||
## Example Usage
|
## Example Usage
|
||||||
|
|
||||||
This Action will only work, if the job in your workflow changes project files.
|
This Action will only work, if the job in your Workflow changes files.
|
||||||
The most common use case for this, is when you're running a Linter or Code-Style fixer on GitHub Actions.
|
The most common use case for this, is when you're running a Linter or Code-Style fixer on GitHub Actions.
|
||||||
|
|
||||||
In this example I'm running `php-cs-fixer` in a PHP project.
|
In this example I'm running `php-cs-fixer` in a PHP project.
|
||||||
|
|
||||||
|
### Example on `pull_request` event
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: php-cs-fixer
|
name: php-cs-fixer
|
||||||
|
|
||||||
on:
|
on: pull_request
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- '**.php'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
php-cs-fixer:
|
php-cs-fixer:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 1
|
ref: ${{ github.head_ref }}
|
||||||
|
|
||||||
- name: Run php-cs-fixer
|
- name: Run php-cs-fixer
|
||||||
uses: docker://oskarstark/php-cs-fixer-ga
|
uses: docker://oskarstark/php-cs-fixer-ga
|
||||||
|
|
||||||
- name: Commit changed files
|
- uses: stefanzweifel/git-auto-commit-action@v4.1.2
|
||||||
uses: stefanzweifel/git-auto-commit-action@v2.5.0
|
|
||||||
with:
|
with:
|
||||||
commit_message: Apply php-cs-fixer changes
|
commit_message: Apply php-cs-fixer changes
|
||||||
branch: ${{ github.head_ref }}
|
branch: ${{ github.head_ref }}
|
||||||
file_pattern: src/\*.php
|
```
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|
||||||
|
### Example on `push` event
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: php-cs-fixer
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
php-cs-fixer:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Run php-cs-fixer
|
||||||
|
uses: docker://oskarstark/php-cs-fixer-ga
|
||||||
|
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4.1.2
|
||||||
|
with:
|
||||||
|
commit_message: Apply php-cs-fixer changes
|
||||||
```
|
```
|
||||||
|
|
||||||
### Inputs
|
### Inputs
|
||||||
|
|
||||||
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
|
Checkout [`action.yml`](https://github.com/stefanzweifel/git-auto-commit-action/blob/master/action.yml) for a full list of supported inputs.
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
You can use these outputs to trigger other Actions in your Workflow run based on the result of `git-auto-commit-action`.
|
||||||
|
|
||||||
|
- `changes_detected`: Returns either "true" or "false" if the repository was dirty and files have changed.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Can't push commit to repository
|
||||||
|
If your Workflow can't push the commit to the repository because of authentication issues, please update your Workflow configuration and usage of [`actions/checkout`](https://github.com/actions/checkout#usage). (Updating the `token` value with a Personal Access Token should fix your issues)
|
||||||
|
|
||||||
|
### Commit of this Action does not trigger a new Workflow run
|
||||||
|
As mentioned in the [Usage](#Usage) section, the commit created by this Action **will not trigger** a new Workflow run automatically.
|
||||||
|
|
||||||
|
This is due to limitations set up by GitHub:
|
||||||
|
|
||||||
|
> An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.
|
||||||
|
[Source](https://help.github.com/en/actions/reference/events-that-trigger-workflows)
|
||||||
|
|
||||||
|
You can change this by creating a new [Personal Access Token (PAT)](https://github.com/settings/tokens/new), storing the token as a secret in your repository and then passing the new token to the [`actions/checkout`](https://github.com/actions/checkout#usage) Action.
|
||||||
|
|
||||||
|
#### Example Workflow
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: php-cs-fixer
|
||||||
|
|
||||||
|
on: push
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
php-cs-fixer:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.PAT_TOKEN }}
|
||||||
|
|
||||||
|
- name: Run php-cs-fixer
|
||||||
|
uses: docker://oskarstark/php-cs-fixer-ga
|
||||||
|
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4.1.2
|
||||||
|
with:
|
||||||
|
commit_message: Apply php-cs-fixer changes
|
||||||
|
```
|
||||||
|
|
||||||
|
## Known Issues
|
||||||
|
|
||||||
|
- GitHub currently prohibits Actions like this to push changes from a fork to the upstream repository. See [issue #25](https://github.com/stefanzweifel/git-auto-commit-action/issues/25) for more information.
|
||||||
|
|
||||||
## Versioning
|
## Versioning
|
||||||
|
|
||||||
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).
|
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/stefanzweifel/git-auto-commit-action/tags).
|
||||||
|
41
action.yml
41
action.yml
@@ -7,30 +7,45 @@ inputs:
|
|||||||
commit_message:
|
commit_message:
|
||||||
description: Commit message
|
description: Commit message
|
||||||
required: true
|
required: true
|
||||||
|
branch:
|
||||||
|
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
commit_options:
|
commit_options:
|
||||||
description: Commit options (eg. --no-verify)
|
description: Commit options (eg. --no-verify)
|
||||||
required: false
|
required: false
|
||||||
branch:
|
|
||||||
description: Branch name where changes should be pushed too
|
|
||||||
required: true
|
|
||||||
file_pattern:
|
file_pattern:
|
||||||
description: File pattern used for "git add"
|
description: File pattern used for `git add`. For example `src/\*.js`
|
||||||
required: false
|
required: false
|
||||||
default: '.'
|
default: '.'
|
||||||
repository:
|
repository:
|
||||||
description: Path to git repository
|
description: Local file path to the git repository. Defaults to the current directory (`.`)
|
||||||
required: false
|
required: false
|
||||||
default: '.'
|
default: '.'
|
||||||
|
commit_user_name:
|
||||||
|
description: Name used for the commit user
|
||||||
|
required: false
|
||||||
|
default: GitHub Actions
|
||||||
|
commit_user_email:
|
||||||
|
description: Email address used for the commit user
|
||||||
|
required: false
|
||||||
|
default: actions@github.com
|
||||||
|
commit_author:
|
||||||
|
description: Value used for the commit author. Defaults to the username of whoever triggered this workflow run.
|
||||||
|
required: false
|
||||||
|
default: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
|
||||||
|
tagging_message:
|
||||||
|
description: Message used to create a new git tag with the commit. Keep this empty, if no tag should be created.
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
changes_detected:
|
||||||
|
description: Value is "true", if the repository was dirty and file changes have been detected. Value is "false", if no changes have been detected.
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'node12'
|
||||||
image: 'Dockerfile'
|
main: 'index.js'
|
||||||
args:
|
|
||||||
- ${{ inputs.commit_message }}
|
|
||||||
- ${{ inputs.commit_options }}
|
|
||||||
- ${{ inputs.branch }}
|
|
||||||
- ${{ inputs.file_pattern }}
|
|
||||||
- ${{ inputs.repository }}
|
|
||||||
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'git-commit'
|
icon: 'git-commit'
|
||||||
|
@@ -2,21 +2,86 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
source /lib.sh
|
_main() {
|
||||||
|
_switch_to_repository
|
||||||
|
|
||||||
_switch_to_repository
|
if _git_is_dirty; then
|
||||||
|
|
||||||
if _git_is_dirty; then
|
echo "::set-output name=changes_detected::true"
|
||||||
|
|
||||||
_setup_git
|
_switch_to_branch
|
||||||
|
|
||||||
_switch_to_branch
|
_add_files
|
||||||
|
|
||||||
_add_files
|
_local_commit
|
||||||
|
|
||||||
_local_commit
|
_tag_commit
|
||||||
|
|
||||||
_push_to_github
|
_push_to_github
|
||||||
else
|
else
|
||||||
echo "Working tree clean. Nothing to commit."
|
|
||||||
fi
|
echo "::set-output name=changes_detected::false"
|
||||||
|
|
||||||
|
echo "Working tree clean. Nothing to commit."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_switch_to_repository() {
|
||||||
|
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
|
||||||
|
cd $INPUT_REPOSITORY
|
||||||
|
}
|
||||||
|
|
||||||
|
_git_is_dirty() {
|
||||||
|
[ -n "$(git status -s)" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
_switch_to_branch() {
|
||||||
|
echo "INPUT_BRANCH value: $INPUT_BRANCH";
|
||||||
|
|
||||||
|
# Switch to branch from current Workflow run
|
||||||
|
git checkout $INPUT_BRANCH
|
||||||
|
}
|
||||||
|
|
||||||
|
_add_files() {
|
||||||
|
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
|
||||||
|
git add "${INPUT_FILE_PATTERN}"
|
||||||
|
}
|
||||||
|
|
||||||
|
_local_commit() {
|
||||||
|
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
|
||||||
|
git -c user.name="$INPUT_COMMIT_USER_NAME" -c user.email="$INPUT_COMMIT_USER_EMAIL" commit -m "$INPUT_COMMIT_MESSAGE" --author="$INPUT_COMMIT_AUTHOR" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
|
||||||
|
}
|
||||||
|
|
||||||
|
_tag_commit() {
|
||||||
|
echo "INPUT_TAGGING_MESSAGE: ${INPUT_TAGGING_MESSAGE}"
|
||||||
|
|
||||||
|
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||||
|
then
|
||||||
|
echo "::debug::Create tag $INPUT_TAGGING_MESSAGE"
|
||||||
|
git tag -a "$INPUT_TAGGING_MESSAGE" -m "$INPUT_TAGGING_MESSAGE"
|
||||||
|
else
|
||||||
|
echo " No tagging message supplied. No tag will be added."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_push_to_github() {
|
||||||
|
if [ -z "$INPUT_BRANCH" ]
|
||||||
|
then
|
||||||
|
# Only add `--tags` option, if `$INPUT_TAGGING_MESSAGE` is set
|
||||||
|
if [ -n "$INPUT_TAGGING_MESSAGE" ]
|
||||||
|
then
|
||||||
|
echo "::debug::git push origin --tags"
|
||||||
|
git push origin --tags
|
||||||
|
else
|
||||||
|
echo "::debug::git push origin"
|
||||||
|
git push origin
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "::debug::Push commit to remote branch $INPUT_BRANCH"
|
||||||
|
git push --set-upstream origin "HEAD:$INPUT_BRANCH" --tags
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_main
|
||||||
|
34
index.js
Normal file
34
index.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Most of this code has been copied from the following GitHub Action
|
||||||
|
* to make it simpler or not necessary to install a lot of
|
||||||
|
* JavaScript packages to execute a shell script.
|
||||||
|
*
|
||||||
|
* https://github.com/ad-m/github-push-action/blob/fe38f0a751bf9149f0270cc1fe20bf9156854365/start.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
const spawn = require('child_process').spawn;
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const exec = (cmd, args=[]) => new Promise((resolve, reject) => {
|
||||||
|
console.log(`Started: ${cmd} ${args.join(" ")}`)
|
||||||
|
const app = spawn(cmd, args, { stdio: 'inherit' });
|
||||||
|
app.on('close', code => {
|
||||||
|
if(code !== 0){
|
||||||
|
err = new Error(`Invalid status code: ${code}`);
|
||||||
|
err.code = code;
|
||||||
|
return reject(err);
|
||||||
|
};
|
||||||
|
return resolve(code);
|
||||||
|
});
|
||||||
|
app.on('error', reject);
|
||||||
|
});
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
await exec('bash', [path.join(__dirname, './entrypoint.sh')]);
|
||||||
|
};
|
||||||
|
|
||||||
|
main().catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
console.error(err.stack);
|
||||||
|
process.exit(err.code || -1);
|
||||||
|
})
|
48
lib.sh
48
lib.sh
@@ -1,48 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
_switch_to_repository() {
|
|
||||||
echo "INPUT_REPOSITORY value: $INPUT_REPOSITORY";
|
|
||||||
cd $INPUT_REPOSITORY
|
|
||||||
}
|
|
||||||
|
|
||||||
_git_is_dirty() {
|
|
||||||
[[ -n "$(git status -s)" ]]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set up .netrc file with GitHub credentials
|
|
||||||
_setup_git ( ) {
|
|
||||||
cat <<- EOF > $HOME/.netrc
|
|
||||||
machine github.com
|
|
||||||
login $GITHUB_ACTOR
|
|
||||||
password $GITHUB_TOKEN
|
|
||||||
|
|
||||||
machine api.github.com
|
|
||||||
login $GITHUB_ACTOR
|
|
||||||
password $GITHUB_TOKEN
|
|
||||||
EOF
|
|
||||||
chmod 600 $HOME/.netrc
|
|
||||||
|
|
||||||
git config --global user.email "actions@github.com"
|
|
||||||
git config --global user.name "GitHub Actions"
|
|
||||||
}
|
|
||||||
|
|
||||||
_switch_to_branch() {
|
|
||||||
echo "INPUT_BRANCH value: $INPUT_BRANCH";
|
|
||||||
|
|
||||||
# Switch to branch from current Workflow run
|
|
||||||
git checkout $INPUT_BRANCH
|
|
||||||
}
|
|
||||||
|
|
||||||
_add_files() {
|
|
||||||
echo "INPUT_FILE_PATTERN: ${INPUT_FILE_PATTERN}"
|
|
||||||
git add "${INPUT_FILE_PATTERN}"
|
|
||||||
}
|
|
||||||
|
|
||||||
_local_commit() {
|
|
||||||
echo "INPUT_COMMIT_OPTIONS: ${INPUT_COMMIT_OPTIONS}"
|
|
||||||
git commit -m "$INPUT_COMMIT_MESSAGE" --author="$GITHUB_ACTOR <$GITHUB_ACTOR@users.noreply.github.com>" ${INPUT_COMMIT_OPTIONS:+"$INPUT_COMMIT_OPTIONS"}
|
|
||||||
}
|
|
||||||
|
|
||||||
_push_to_github() {
|
|
||||||
git push --set-upstream origin "HEAD:$INPUT_BRANCH"
|
|
||||||
}
|
|
Reference in New Issue
Block a user