Skip to content

Commit

Permalink
Merge pull request #48 from devops-infra/feature/branches-commits
Browse files Browse the repository at this point in the history
Allow both commit messages and prefixes
  • Loading branch information
ChristophShyper authored Mar 23, 2022
2 parents 28247c7 + 9211c93 commit 5107351
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
phony: help

# Release tag for the action
VERSION := v0.8.4
VERSION := v0.9.0

# GitHub Actions bogus variables
GITHUB_REF ?= refs/heads/null
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
Dockerized as [devopsinfra/action-commit-push](https://hub.docker.com/repository/docker/devopsinfra/action-commit-push).

Features:
* Can add a custom prefix to commit message by setting `commit_prefix`.
* Can create a new branch when `target_branch` is set.
* Can add a timestamp to a branch name, when `target_branch` is set and `add_timestamp` is `true`. Will create a branch named `${branch_name}/${add_timestamp}`. Great for cron-based updates.
* As a commit message will use `commit_message` if set, or `commit_prefix` and add changed files or just list changed files.
* Can add a custom prefix to commit message title by setting `commit_prefix`.
* As a commit message title will use `commit_message` if set, or `commit_prefix` and add changed files or just list of changed files.
* Can create a new branch when `target_branch` is set.
* Can add a timestamp to a branch name (great for cron-based updates):
* When `target_branch` is set and `add_timestamp` is `true` will create a branch named `${branch_name}/${add_timestamp}`.
* When `target_branch` is not set and `add_timestamp` is `true` will create a branch named `${add_timestamp}`.
* Good to combine with my other action [devops-infra/action-pull-request](https://github.com/devops-infra/action-pull-request).
* Can use `git push --force` for fast-forward changes.
* Can use `git push --force` for fast-forward changes with `force` input.


## Badge swag
Expand Down Expand Up @@ -50,10 +52,10 @@ Features:
| Input Variable | Required | Default | Description |
| ------------------- | -------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| github_token | Yes | `""` | Personal Access Token for GitHub for pushing the code. |
| add_timestamp | No | `false` | Whether to add the timestamp to a new branch name. Used when `target_branch` is set. Uses format `%Y-%m-%dT%H-%M-%SZ`. |
| add_timestamp | No | `false` | Whether to add the timestamp to a new branch name. Uses format `%Y-%m-%dT%H-%M-%SZ`. |
| amend | No | `false` | Whether to make amendment to the previous commit (`--amend`). Cannot be used together with `commit_message` or `commit_prefix`. |
| commit_prefix | No | `""` | Prefix added to commit message. If `commit_message` is not used. |
| commit_message | No | `""` | Full commit message to set. Cannot be used together with `amend`. |
| commit_prefix | No | `""` | Prefix added to commit message. Combines with `commit_message`. |
| commit_message | No | `""` | Commit message to set. Combines with `commit_prefix`. Cannot be used together with `amend`. |
| force | No | `false` | Whether to use force push for fast-forward changes (`--force`). Use only if necessary, e.g. when using `--amend`. And set `fetch-depth: 0` for `actions/checkout`. |
| no_edit | No | `false` | Whether to not edit commit message when using amend (`--no-edit`). |
| organization_domain | No | `github.com` | Github Enterprise domain name. |
Expand Down Expand Up @@ -82,7 +84,7 @@ jobs:
run: |
find . -type f -name "*" -print0 | xargs -0 sed -i "s/foo/bar/g"
- name: Commit and push changes
uses: devops-infra/action-commit-push@v0.8.4
uses: devops-infra/action-commit-push@v0.9.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: Replaced foo with bar
Expand All @@ -103,7 +105,7 @@ jobs:
run: |
find . -type f -name "*" -print0 | xargs -0 sed -i "s/foo/bar/g"
- name: Commit and push changes
uses: devops-infra/action-commit-push@v0.8.4
uses: devops-infra/action-commit-push@v0.9.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_prefix: "[AUTO-COMMIT] foo/bar replace"
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
required: false
default: ""
commit_message:
description: Full commit message to set
description: Commit message to set
required: false
default: ""
force:
Expand All @@ -45,7 +45,7 @@ outputs:
description: Name of the branch code was pushed into
runs:
using: docker
image: docker://devopsinfra/action-commit-push:v0.8.4
image: docker://devopsinfra/action-commit-push:v0.9.0
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
branding:
Expand Down
14 changes: 7 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ fi

# Setting branch name
BRANCH="${INPUT_TARGET_BRANCH:-$(git symbolic-ref --short -q HEAD)}"

# Add timestamp to branch name
if [[ "${INPUT_ADD_TIMESTAMP}" == "true" && -n ${FILES_CHANGED} ]]; then
TIMESTAMP=$(date -u +"%Y-%m-%dT%H-%M-%SZ")
BRANCH="${BRANCH}-${TIMESTAMP}"
if [[ -n ${BRANCH} ]]; then
BRANCH="${BRANCH}-${TIMESTAMP}"
else
BRANCH="${TIMESTAMP}"
fi
fi

echo -e "\n[INFO] Target branch: ${BRANCH}"

# Create a new branch
Expand All @@ -64,10 +66,8 @@ if [[ -n ${FILES_CHANGED} ]]; then
if [[ "${INPUT_NO_EDIT}" == "true" ]]; then
COMMIT_PARAMS+=("--no-edit")
git commit "${COMMIT_PARAMS[@]}"
elif [[ -n "${INPUT_COMMIT_MESSAGE}" ]]; then
git commit "${COMMIT_PARAMS[@]}" -am "${INPUT_COMMIT_MESSAGE}"
elif [[ -n "${INPUT_COMMIT_PREFIX}" ]]; then
git commit "${COMMIT_PARAMS[@]}" -am "${INPUT_COMMIT_PREFIX} Files changed:" -m "${FILES_CHANGED}"
elif [[ -n "${INPUT_COMMIT_MESSAGE}" || -n "${INPUT_COMMIT_PREFIX}" ]]; then
git commit "${COMMIT_PARAMS[@]}" -am "${INPUT_COMMIT_PREFIX}${INPUT_COMMIT_MESSAGE}" -m "Files changed:\n${FILES_CHANGED}"
else
git commit "${COMMIT_PARAMS[@]}" -am "Files changed:" -m "${FILES_CHANGED}"
fi
Expand Down

0 comments on commit 5107351

Please sign in to comment.