Compare commits

..

13 Commits

Author SHA1 Message Date
Stefan Zweifel
268ec0c240 Release v4.9.0 2021-02-20 20:34:30 +01:00
Stefan Zweifel
9abc4c41e5 Merge pull request #140 from stefanzweifel/feature/create-new-branch-during-checkout
Feature: Create a new branch, if the given branch name doesn't exist yet
2021-02-20 20:29:23 +01:00
Stefan Zweifel
1aee6e6b46 Make Linter Happy 2021-02-07 16:14:11 +01:00
Stefan Zweifel
94941cff88 Cleanup Code 2021-02-07 16:09:59 +01:00
Stefan Zweifel
7507738fca Use git branch --list 2021-02-07 16:07:43 +01:00
Stefan Zweifel
53438d58ce Create new branch if NAME is given 2021-02-07 15:44:48 +01:00
Stefan Zweifel
8056699617 Add Testcase 2021-02-07 15:44:12 +01:00
Stefan Zweifel
520c63c171 Add Link to Article 2021-02-06 19:11:12 +01:00
Stefan Zweifel
a6006229e0 Merge pull request #138 from stefanzweifel/test-rm-is-tracked
Add Test to verify that removed files are picked up by the Action
2021-01-18 20:34:44 +01:00
Stefan Zweifel
40b55695d1 Add Test 2021-01-18 20:31:50 +01:00
Stefan Zweifel
8f33b6cc31 Merge pull request #136 from palmerabollo/patch-1
docs: minor typo
2021-01-15 15:21:34 +01:00
Guido García
c4ab3ecb7e docs: minor typo 2021-01-15 15:19:06 +01:00
Stefan Zweifel
350754fe3a Update LICENSE 2021-01-08 17:31:07 +01:00
5 changed files with 75 additions and 6 deletions

View File

@@ -4,11 +4,17 @@ 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/v4.8.0...HEAD) ## [Unreleased](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.9.0...HEAD)
> TBD > TBD
## [v4.9.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.8.0...v4.9.0) - 2021-02-20
### Changed
- Automatically create btanch if a branch with the given name does not exist [#140](https://github.com/stefanzweifel/git-auto-commit-action/pull/140)
## [v4.8.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.2...v4.8.0) - 2020-12-15 ## [v4.8.0](https://github.com/stefanzweifel/git-auto-commit-action/compare/v4.7.2...v4.8.0) - 2020-12-15
### Added ### Added

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2019 Stefan Zweifel Copyright (c) 2021 Stefan Zweifel
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -13,6 +13,8 @@ By default, the commit is made in the name of "GitHub Actions" and co-authored b
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 this [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.
If you want to learn more how this Action works under the hood, check out [this article](https://michaelheap.com/git-auto-commit/) by Michael Heap.
## Usage ## Usage
Add the following step at the end of your job, after other steps that might add or change files. Add the following step at the end of your job, after other steps that might add or change files.
@@ -143,7 +145,7 @@ You have to do this to avoid that the `checkout`-Action clones your repository i
### Commits of this Action do not trigger new Workflow runs ### Commits of this Action do not trigger new Workflow runs
The resulting commit **will not trigger** another GitHub Actions Workflow run. The resulting commit **will not trigger** another GitHub Actions Workflow run.
This is due to [limititations set by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token). This is due to [limitations set by GitHub](https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token).
> When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. > When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

View File

@@ -48,9 +48,28 @@ _switch_to_branch() {
git fetch --depth=1; git fetch --depth=1;
fi fi
# Switch to branch from current Workflow run
# If INPUT_BRANCH is empty, just run `git checkout`
if [ -z "$INPUT_BRANCH" ]
then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
git checkout $INPUT_BRANCH; git checkout $INPUT_BRANCH;
else
# If the branch which we should checkout already exists, just
# run `git checkout $INPUT_BRANCH`
# Otherwhise create a new branch by adding the `-b` option to
# `git-checkout`
# shellcheck disable=SC2086
if [ -n "$(git branch --list $INPUT_BRANCH)" ]
then
# shellcheck disable=SC2086
git checkout $INPUT_BRANCH;
else
# shellcheck disable=SC2086
git checkout -b $INPUT_BRANCH;
fi
fi
} }
_add_files() { _add_files() {

View File

@@ -94,6 +94,26 @@ git_auto_commit() {
assert_line "::debug::Push commit to remote branch master" assert_line "::debug::Push commit to remote branch master"
} }
@test "It detects when files have been deleted, commits changes and pushes them to the remote repository" {
rm -rf "${FAKE_LOCAL_REPOSITORY}"/remote-files1.txt
run git_auto_commit
assert_success
assert_line "INPUT_REPOSITORY value: ${INPUT_REPOSITORY}"
assert_line "::set-output name=changes_detected::true"
assert_line "INPUT_BRANCH value: master"
assert_line "INPUT_FILE_PATTERN: ."
assert_line "INPUT_COMMIT_OPTIONS: "
assert_line "::debug::Apply commit options "
assert_line "INPUT_TAGGING_MESSAGE: "
assert_line "No tagging message supplied. No tag will be added."
assert_line "INPUT_PUSH_OPTIONS: "
assert_line "::debug::Apply push options "
assert_line "::debug::Push commit to remote branch master"
}
@test "It prints a 'Nothing to commit' message in a clean repository" { @test "It prints a 'Nothing to commit' message in a clean repository" {
run git_auto_commit run git_auto_commit
@@ -311,3 +331,25 @@ git_auto_commit() {
assert_line "::debug::git-fetch has not been executed" assert_line "::debug::git-fetch has not been executed"
} }
@test "If INPUT_BRANCH is set and the branch does not exist it creates one" {
INPUT_BRANCH="new-branch"
run git branch
refute_line "new-branch"
touch "${FAKE_LOCAL_REPOSITORY}"/new-file-{1,2,3}.txt
run git_auto_commit
assert_success
assert_line "INPUT_BRANCH value: new-branch"
assert_line --partial "::debug::Push commit to remote branch new-branch"
# Assert that branch "new-branch" was updated on remote
current_sha="$(git rev-parse --verify --short new-branch)"
remote_sha="$(git rev-parse --verify --short origin/new-branch)"
assert_equal $current_sha $remote_sha
}