Compare commits

...

34 Commits

Author SHA1 Message Date
Federico Grandi
d926d1c554 [auto] Update compiled version 2020-05-17 16:26:50 +00:00
Federico Grandi
8b797ba126 Fix tag clobbering 2020-05-17 18:26:13 +02:00
Federico Grandi
1b11953688 Bump version: 4.2.0 2020-05-17 18:18:56 +02:00
Federico Grandi
36bc3f778b Improve tagging docs 2020-05-17 18:17:30 +02:00
Federico Grandi
c61b317dea Merge pull request #30 from ToMe25/master
Add tagging support
2020-05-17 18:12:19 +02:00
ToMe25
22cdfa345a [auto] Update compiled version 2020-05-16 17:54:55 +00:00
ToMe25
d4aeb9335d Hopefully this time fix which commit gets tagged 2020-05-16 19:54:18 +02:00
ToMe25
46569f991f [auto] Update compiled version 2020-05-16 17:45:45 +00:00
ToMe25
83761c7e8e Hopefully fix wrong commit getting tagged 2020-05-16 19:44:48 +02:00
ToMe25
f0a1d2598a [auto] Update compiled version 2020-05-16 17:17:36 +00:00
ToMe25
c902408157 Add missing push arg 2020-05-16 19:16:43 +02:00
ToMe25
6b705fa3a4 Add tagging support 2020-05-16 18:30:49 +02:00
Federico Grandi
0e98be578d Version bump: 4.1.0 2020-05-01 15:36:30 +02:00
Federico Grandi
c07603c1c4 [auto] Update compiled version 2020-05-01 13:28:50 +00:00
Federico Grandi
9cd6e9c0ea Add ref option 2020-05-01 15:27:44 +02:00
Federico Grandi
5bf921b386 Version bump: 4.0.3 2020-05-01 11:52:28 +02:00
Federico Grandi
beedcea439 Version bump: 4.0.2 2020-05-01 11:48:19 +02:00
Federico Grandi
6cb111a771 [auto] Update compiled version 2020-05-01 09:47:36 +00:00
Federico Grandi
6a4387c9c9 Minor log improvement 2020-05-01 11:46:57 +02:00
Federico Grandi
132aa0f637 [auto] Update compiled version 2020-05-01 09:42:54 +00:00
Federico Grandi
7dbb54bce3 Add groups 2020-05-01 11:42:13 +02:00
Federico Grandi
7f1289bf4a Pipe stderr too 2020-05-01 11:39:32 +02:00
Federico Grandi
88d475f304 [auto] Update compiled version 2020-05-01 09:35:49 +00:00
Federico Grandi
98f4b8018b Try with .pipe 2020-05-01 11:35:06 +02:00
Federico Grandi
2f6a78549b [auto] Update compiled version 2020-05-01 09:26:43 +00:00
Federico Grandi
9cd727829f Try using execFile 2020-05-01 11:26:05 +02:00
Federico Grandi
f0fcdb07a3 [auto] Update compiled version 2020-05-01 09:17:33 +00:00
Federico Grandi
5ead79aef9 Try to fix logs 2020-05-01 11:16:32 +02:00
Federico Grandi
72da43cf1b Merge pull request #28 from RobinWijnant/master
Add --quiet flag to git diff
2020-05-01 11:08:07 +02:00
Robin Wijnant
9eb0d21b0d add --quiet flag git diff
This fixes ENOBUFS error which is thrown when the stdout buffer exceeds 1MB
2020-04-30 10:31:44 +02:00
Federico Grandi
2db75722ce Merge pull request #26 from jsoref/grammar
Improve grammar and formatting in README
2020-04-27 16:07:53 +02:00
Josh Soref
68d0f64f6f Grammar 2020-04-26 18:23:22 -04:00
Federico Grandi
d1cfc165c7 [auto] Update compiled version 2020-04-19 17:48:30 +00:00
Federico Grandi
5f12f937cb Fix error hadling
Ref #25
2020-04-19 19:47:38 +02:00
8 changed files with 85 additions and 28 deletions

View File

@@ -1,9 +1,9 @@
# Add & Commit
You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds and so on...
You can use this GitHub Action to commit changes made in your workflow run directly to your repo: for example, you use it to lint your code, update documentation, commit updated builds, etc....
This is **heavily** inspired by [git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) (by [Stefan Zweifel](https://github.com/stefanzweifel)): that action automatically detects changed files and commits them. While this is useful for most situations, this doesn't commit untracked files and can sometimes commit unintended changes (such as `package-lock.json` or similar, that may have happened during previous steps).
This action lets you choose the path that you want to use when adding & committing changes, so that it works as you would normally do using `git` on your machine.
This action lets you choose the path that you want to use when adding & committing changes so that it works as you would normally do using `git` on your machine.
## Usage
@@ -12,7 +12,7 @@ Add a step like this to your workflow:
```yaml
- uses: EndBug/add-and-commit@v4 # You can change this to use a specific version
with:
# The arguments for the git add command (see the paragraph below for more info)
# The arguments for the `git add` command (see the paragraph below for more info)
# Default: '.'
add: 'src'
@@ -20,7 +20,7 @@ Add a step like this to your workflow:
# Default: author of the commit that triggered the run
author_name: Your Name
# The The email of the user that will be displayed as the author of the commit
# The email of the user that will be displayed as the author of the commit
# Default: author of the commit that triggered the run
author_email: mail@example.com
@@ -28,7 +28,7 @@ Add a step like this to your workflow:
# Default: '.'
cwd: './path/to/the/repo'
# Whether to use the --force option on git add, in order to bypass eventual gitignores
# Whether to use the --force option on `git add`, in order to bypass eventual gitignores
# Default: false
force: true
@@ -36,10 +36,18 @@ Add a step like this to your workflow:
# Default: 'Commit from GitHub Actions'
message: 'Your commit message'
# The arguments for the git rm command (see the paragraph below for more info)
# Name of the branch to use, if different from the one that triggered the workflow
# Default: the branch that triggered the workflow (from GITHUB_REF)
ref: 'someOtherBranch'
# The arguments for the `git rm` command (see the paragraph below for more info)
# Default: ''
remove: "./dir/old_file.js"
# Name of the tag to add to the new commit (see the paragraph below for more info)
# Default: ''
tag: "v1.0.0"
env:
# This is necessary in order to push a commit to the repo
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
@@ -48,17 +56,22 @@ Add a step like this to your workflow:
### Environment variables:
The only `env` variable required is the token for the action to run: GitHub generates one automatically, but you need to pass it through `env` to make it available to actions. You can find more about `GITHUB_TOKEN` [here](https://help.github.com/en/articles/virtual-environments-for-github-actions#github_token-secret).
With that said, you can just copy the example line and don't worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
That said, you can just copy the example line and not worry about it. If you do want to use a different token you can pass that in, but I wouldn't see any possible advantage in doing so.
### Adding files:
The action adds files using a regular `git add` command, so you can put every kind of argument in the `add` option. For example, if you don't want it to use a recursive behavior: `$(find . -maxdepth 1 -name *.js)`.
The script will not stop if one the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
The script will not stop if one of the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
### Deleting files:
You can delete files with the `remove` option: that runs a `git rm` command that will stage the files in the given path for removal.
The script will not stop if one the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
The script will not stop if one of the git commands fails. E.g.: if your command shows a "fatal: pathspec 'yourFile' did not match any files" error the action will go on.
### Tagging:
You can tag commits with the `tag` option: when used, it will create a lightweight tag for the commit with the name you set as input. If not entered (or if an empty string is passed) teh action won't create any tag.
If there is already a tag with the name you entered it will be overwritten, and so the tag will be "updated".
### Examples:
@@ -110,7 +123,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# If you need to, you can checkout your repo to a different location
# If you need to, you can check out your repo to a different location
- uses: actions/checkout@v2
with:
path: "./pathToRepo/"

View File

@@ -24,10 +24,17 @@ inputs:
description: The message for the commit
required: false
default: Commit from GitHub Actions
ref:
description: Name of the branch to use, if different from the one that triggered the workflow
required: false
remove:
description: Arguments for the git rm command
required: false
default: ""
tag:
description: The name of the tag to add to the new commit
required: false
default: ""
runs:
using: node12

View File

@@ -1,6 +1,8 @@
#!/bin/bash
set -u
echo "::group::Internal logs"
cd $INPUT_CWD
echo "Running in $PWD."
@@ -29,6 +31,10 @@ remove() {
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
}
tag() {
if [ -n "$INPUT_TAG" ]; then git tag $INPUT_TAG; fi
}
# This is needed to make the check work for untracked files
echo "Staging files..."
add
@@ -36,20 +42,20 @@ remove
echo "Checking for uncommitted changes in the git working tree..."
# This section only runs if there have been file changes
if ! git diff --cached --exit-code; then
if ! git diff --cached --quiet --exit-code; then
git_setup
git fetch
# Verify if the branch needs to be created
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"; then
if ! git rev-parse --verify --quiet "$INPUT_REF"; then
echo "Creating branch..."
git branch "${GITHUB_REF:11}"
git branch "$INPUT_REF"
fi
# Switch to branch from current workflow run
echo "Switching branch..."
git checkout "${GITHUB_REF:11}"
git checkout "$INPUT_REF"
echo "Pulling from remote..."
git fetch && git pull
@@ -66,8 +72,18 @@ if ! git diff --cached --exit-code; then
echo "Creating commit..."
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
echo "Pushing to repo..."
git push --set-upstream origin "${GITHUB_REF:11}"
echo "Tagging commit..."
tag
echo "Pushing commits to repo..."
git push --set-upstream origin "$INPUT_REF"
echo "Pushing tags to repo..."
git push --set-upstream origin "$INPUT_REF" --force --tags
echo "::endgroup::"
echo "Task completed."
else
echo "::endgroup::"
echo "Working tree clean. Nothing to commit."
fi

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "add-and-commit",
"version": "4.0.0",
"version": "4.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "add-and-commit",
"version": "4.0.1",
"version": "4.2.0",
"description": "Add & commit files from a path directly from GitHub Actions",
"main": "lib/index.js",
"scripts": {

View File

@@ -1,6 +1,8 @@
#!/bin/bash
set -u
echo "::group::Internal logs"
cd $INPUT_CWD
echo "Running in $PWD."
@@ -29,6 +31,10 @@ remove() {
if [ -n "$INPUT_REMOVE" ]; then git rm $INPUT_REMOVE; fi
}
tag() {
if [ -n "$INPUT_TAG" ]; then git tag $INPUT_TAG; fi
}
# This is needed to make the check work for untracked files
echo "Staging files..."
add
@@ -36,20 +42,20 @@ remove
echo "Checking for uncommitted changes in the git working tree..."
# This section only runs if there have been file changes
if ! git diff --cached --exit-code; then
if ! git diff --cached --quiet --exit-code; then
git_setup
git fetch
# Verify if the branch needs to be created
if ! git rev-parse --verify --quiet "${GITHUB_REF:11}"; then
if ! git rev-parse --verify --quiet "$INPUT_REF"; then
echo "Creating branch..."
git branch "${GITHUB_REF:11}"
git branch "$INPUT_REF"
fi
# Switch to branch from current workflow run
echo "Switching branch..."
git checkout "${GITHUB_REF:11}"
git checkout "$INPUT_REF"
echo "Pulling from remote..."
git fetch && git pull
@@ -66,8 +72,18 @@ if ! git diff --cached --exit-code; then
echo "Creating commit..."
git commit -m "$INPUT_MESSAGE" --author="$INPUT_AUTHOR_NAME <$INPUT_AUTHOR_EMAIL>"
echo "Pushing to repo..."
git push --set-upstream origin "${GITHUB_REF:11}"
echo "Tagging commit..."
tag
echo "Pushing commits to repo..."
git push --set-upstream origin "$INPUT_REF"
echo "Pushing tags to repo..."
git push --set-upstream origin "$INPUT_REF" --force --tags
echo "::endgroup::"
echo "Task completed."
else
echo "::endgroup::"
echo "Working tree clean. Nothing to commit."
fi

View File

@@ -1,12 +1,15 @@
import { info, setFailed, getInput, warning } from '@actions/core'
import { join as path } from 'path'
import { execFileSync } from 'child_process'
import { execFile } from 'child_process'
try {
checkInputs()
execFileSync(path(__dirname, 'entrypoint.sh'))
const child = execFile(path(__dirname, 'entrypoint.sh'))
child.stdout?.pipe(process.stdout)
child.stderr?.pipe(process.stderr)
} catch (err) {
setFailed(err)
console.error(err)
setFailed(err instanceof Error ? err.message : err)
}
function checkInputs() {
@@ -22,6 +25,8 @@ function checkInputs() {
setDefault('author_email', 'actions@github.com')
}
setDefault('ref', process.env.GITHUB_REF?.substring(11) || '')
info(`Using '${getInput('author_name')} <${getInput('author_email')}>' as author.`)
}